-
Notifications
You must be signed in to change notification settings - Fork 251
[Add] truncate properties to Data.Vec.Properties #2795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
@MatthewDaggitt are you happy to proceed with this PR, and its predecessor #2769 for v2.4, and only consider #2770 / #2787 downstream, or should we move to reconcile them all together? UPDATED: I'll review once the direction of travel is (a bit) clearer... |
Yes, I'm happy to add these now and then the breaking changes in v3.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of things to fix, hopefully all (most?) of which will simplify what's here.
CHANGELOG.md
Outdated
take-updateAt : (f : A → A) {m n : ℕ} (xs : Vec A (m + n)) (i : Fin m) → | ||
updateAt (take m xs) i f ≡ take m (updateAt xs (inject≤ i (m≤m+n m n)) f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several things (which will be recapitulated below):
- indentation/alignment so that
updateAt
in LHS aligns with beginning of type signature on line above - omit
{m n : ℕ}
from type signature:- they're inferrable, and/so should be captured by a
variable
declaration already - such arguments should, where possible, never be non-prenex (otherwise, turning them into
variable
s would be abreaking
change!)
- they're inferrable, and/so should be captured by a
- I'll double down on my comment on [Add] padRight properties to Data.Vec.Properties #2769 , and say that the argument order (in particular, the position of the
f
binding) should mirror that forupdateAt
itself, if only for consistency's sake
CHANGELOG.md
Outdated
truncate-zipWith : (f : A → B → C) (m≤n : m ≤ n) (xs : Vec A n) (ys : Vec B n) → | ||
truncate m≤n (zipWith f xs ys) ≡ zipWith f (truncate m≤n xs) (truncate m≤n ys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. re: alignment
CHANGELOG.md
Outdated
truncate-zipWith-truncate : truncate o≤m (zipWith f (truncate m≤n xs) ys) ≡ | ||
zipWith f (truncate o≤n xs) (truncate o≤m ys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides alignment, and the quantifier prefix!, here you need to inline the let
binding for o≤n
, as otherwise it's out of scope:
truncate-zipWith-truncate : truncate o≤m (zipWith f (truncate m≤n xs) ys) ≡ | |
zipWith f (truncate o≤n xs) (truncate o≤m ys) | |
truncate-zipWith-truncate : truncate o≤m (zipWith f (truncate m≤n xs) ys) ≡ | |
zipWith f (truncate (≤-trans o≤m m≤n) xs) (truncate o≤m ys) |
CHANGELOG.md
Outdated
zipWith-truncate : zipWith f (truncate p≤p+q xs) (truncate p≤p+q ys) ≡ | ||
truncate p≤p+q (zipWith f xs ys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why you've changed to p
and q
here, rather than m
and n
?
Also, we 'know' that p ≤ p + q
, so the (presumably) mnemonic name must be carrying other information? If not, simply use m≤n
?
CHANGELOG.md
Outdated
zipWith-truncate₁ : zipWith f (truncate o≤o+m+n xs) (truncate (o≤o+m) ys) ≡ | ||
truncate (o≤o+m) (zipWith f (truncate (o+m≤o+m+n) xs) ys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here, the names are getting very unwieldy... I'll look at the code to see what might be going on...
src/Data/Vec/Properties.agda
Outdated
truncate++drop≡id {m = m} {n} xs = begin | ||
truncate (m≤m+n m n) xs ++ drop m xs ≡⟨ cong (_++ drop m xs) (take≡truncate m xs) ⟨ | ||
take m xs ++ drop m xs ≡⟨ take++drop≡id m xs ⟩ | ||
xs ∎ where open ≡-Reasoning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
src/Data/Vec/Properties.agda
Outdated
@@ -472,6 +541,20 @@ toList-map : ∀ (f : A → B) (xs : Vec A n) → | |||
toList-map f [] = refl | |||
toList-map f (x ∷ xs) = cong (f x List.∷_) (toList-map f xs) | |||
|
|||
truncate-map : (f : A → B) (m : ℕ) (m≤n : m ≤ n) (xs : Vec A n) → |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
truncate-map : (f : A → B) (m : ℕ) (m≤n : m ≤ n) (xs : Vec A n) → | |
truncate-map : (f : A → B) (m≤n : m ≤ n) (xs : Vec A n) → |
src/Data/Vec/Properties.agda
Outdated
@@ -472,6 +541,20 @@ toList-map : ∀ (f : A → B) (xs : Vec A n) → | |||
toList-map f [] = refl | |||
toList-map f (x ∷ xs) = cong (f x List.∷_) (toList-map f xs) | |||
|
|||
truncate-map : (f : A → B) (m : ℕ) (m≤n : m ≤ n) (xs : Vec A n) → | |||
map f (truncate m≤n xs) ≡ truncate m≤n (map f xs) | |||
truncate-map {n = n} f m m≤n xs = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... with corresponding
truncate-map {n = n} f m m≤n xs = | |
truncate-map {m = m} {n = n} f m≤n xs = |
src/Data/Vec/Properties.agda
Outdated
take m (cast eq (map f xs)) ≡⟨ truncate≡take m≤n (map f xs) eq ⟨ | ||
truncate m≤n (map f xs) ∎ | ||
where | ||
.eq : n ≡ m + (n ∸ m) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to mark eq
as irrelevant; it's the proof which is ignored by cast
etc.
.eq : n ≡ m + (n ∸ m) | |
eq : n ≡ m + (n ∸ m) |
src/Data/Vec/Properties.agda
Outdated
truncate m≤n (map f xs) ∎ | ||
where | ||
.eq : n ≡ m + (n ∸ m) | ||
eq = sym (proj₂ (m≤n⇒∃[o]m+o≡n m≤n)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, Data.Nat.Properties.guarded-∸≗∸
is (more like) what you need here... and could then be inlined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See also padRight-drop′
and padRight-take′
that I've added to #2787 for comparison.
Thanks for the second contribution! |
…e `truncate-irrelevant`
Hi! |
As suggested by @jamesmckinna, this PR adds several equational properties for truncate to Data.Vec.Properties, extending the standard vector operations toolkit with useful lemmas for reasoning about truncate.
Added properties: