[Add] truncate properties to Data.Vec.Properties - #2795
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. |
jamesmckinna
left a comment
There was a problem hiding this comment.
Lots of things to fix, hopefully all (most?) of which will simplify what's here.
| 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) |
| 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.
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?
| 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.
Similarly here, the names are getting very unwieldy... I'll look at the code to see what might be going on...
| 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 |
| 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.
| 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) → |
|
|
||
| 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.
... with corresponding
| truncate-map {n = n} f m m≤n xs = | |
| truncate-map {m = m} {n = n} f m≤n xs = |
| 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.
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) |
| 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.
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.
See also padRight-drop′ and padRight-take′ that I've added to #2787 for comparison.
|
Thanks for the second contribution! |
…e `truncate-irrelevant`
|
Hi! |
jamesmckinna
left a comment
There was a problem hiding this comment.
All looks good!
Thanks very much for this final round of nitpicks.
…ht}` irrelevant (#2787) * refactor: make `truncate` and `padRight` take irrelevant argument * fix: proofs of properties following #2769 and #2795; deprecate `truncate-irrelevant` * fix: deprecation in `CHANGELOG` * fix: duplication after resolving merge conflict * fix: alignment * add: specialised versions of `padRight-drop` and `padRight-take` * fix: whitespace * reset: `CHANGELOG` * restore: new `CHANGELOG` entries * refactor: weaken types of `truncate` properties * fix:`CHANGELOG` to reflect weakened types * fix: whitespace * final tweak * final tweak
* adding truncate's properties * update changelog * cleaning whitespaces * Recleaning * corrections after reviews * correction of changelog * changes after review
…ht}` irrelevant (#2787) * refactor: make `truncate` and `padRight` take irrelevant argument * fix: proofs of properties following #2769 and #2795; deprecate `truncate-irrelevant` * fix: deprecation in `CHANGELOG` * fix: duplication after resolving merge conflict * fix: alignment * add: specialised versions of `padRight-drop` and `padRight-take` * fix: whitespace * reset: `CHANGELOG` * restore: new `CHANGELOG` entries * refactor: weaken types of `truncate` properties * fix:`CHANGELOG` to reflect weakened types * fix: whitespace * final tweak * final tweak
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: