Skip to content

Commit 79060e0

Browse files
authored
[ refactor ] make m ≤ n argument to Data.Vec.Base.{truncate|padRight} 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
1 parent b4aa4eb commit 79060e0

File tree

3 files changed

+136
-84
lines changed

3 files changed

+136
-84
lines changed

CHANGELOG.md

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ Non-backwards compatible changes
2121
Minor improvements
2222
------------------
2323

24+
* The types of `Data.Vec.Base.{truncate|padRight}` have been weakened so
25+
that the argument of type `m ≤ n` is marked as irrelevant. This should be
26+
backwards compatible, but does change the intensional behaviour of these
27+
functions to be more eager, because no longer blocking on pattern matching
28+
on that argument. Corresponding changes have been made to the types of their
29+
properties (and their proofs). In particular, `truncate-irrelevant` is now
30+
deprecated, because definitionally trivial.
31+
2432
* The type of `Relation.Nullary.Negation.Core.contradiction-irr` has been further
2533
weakened so that the negated hypothesis `¬ A` is marked as irrelevant. This is
2634
safe to do, in view of `Relation.Nullary.Recomputable.Properties.¬-recompute`.
@@ -68,6 +76,11 @@ Deprecated names
6876
¬∀⟶∃¬- ↦ ¬∀⇒∃¬
6977
```
7078

79+
* In `Data.Vec.Properties`:
80+
```agda
81+
truncate-irrelevant ↦ Relation.Binary.PropositionalEquality.Core.refl
82+
```
83+
7184
* In `Relation.Nullary.Decidable.Core`:
7285
```agda
7386
⊤-dec ↦ ⊤?
@@ -236,46 +249,55 @@ Additions to existing modules
236249
* In `Data.Vec.Properties`:
237250
```agda
238251
map-removeAt : ∀ (f : A → B) (xs : Vec A (suc n)) (i : Fin (suc n)) →
239-
map f (removeAt xs i) ≡ removeAt (map f xs) i
252+
map f (removeAt xs i) ≡ removeAt (map f xs) i
240253
241254
updateAt-take : (xs : Vec A (m + n)) (i : Fin m) (f : A → A) →
242255
updateAt (take m xs) i f ≡ take m (updateAt xs (inject≤ i (m≤m+n m n)) f)
243256
244-
truncate-zipWith : (f : A → B → C) (m≤n : m ≤ n) (xs : Vec A n) (ys : Vec B n) →
245-
truncate m≤n (zipWith f xs ys) ≡ zipWith f (truncate m≤n xs) (truncate m≤n ys)
257+
truncate-zipWith : (f : A → B → C) .(m≤n : m ≤ n) (xs : Vec A n) (ys : Vec B n) →
258+
truncate m≤n (zipWith f xs ys) ≡ zipWith f (truncate m≤n xs) (truncate m≤n ys)
246259
247-
truncate-zipWith-truncate : (f : A → B → C) (m≤n : m ≤ n) (n≤o : n ≤ o) (xs : Vec A o) (ys : Vec B n) →
260+
truncate-zipWith-truncate : (f : A → B → C) .(m≤n : m ≤ n) .(n≤o : n ≤ o)
261+
(xs : Vec A o) (ys : Vec B n) →
248262
truncate m≤n (zipWith f (truncate n≤o xs) ys) ≡
249263
zipWith f (truncate (≤-trans m≤n n≤o) xs) (truncate m≤n ys)
250264
251-
truncate-updateAt : (m≤n : m ≤ n) (xs : Vec A n) (i : Fin m) (f : A → A) →
265+
truncate-updateAt : .(m≤n : m ≤ n) (xs : Vec A n) (i : Fin m) (f : A → A) →
252266
updateAt (truncate m≤n xs) i f ≡
253267
truncate m≤n (updateAt xs (inject≤ i m≤n) f)
254268
255269
updateAt-truncate : (xs : Vec A (m + n)) (i : Fin m) (f : A → A) →
256270
updateAt (truncate (m≤m+n m n) xs) i f ≡
257271
truncate (m≤m+n m n) (updateAt xs (inject≤ i (m≤m+n m n)) f)
258272
259-
map-truncate : (f : A → B) (m≤n : m ≤ n) (xs : Vec A n) →
260-
map f (truncate m≤n xs) ≡ truncate m≤n (map f xs)
273+
map-truncate : (f : A → B) .(m≤n : m ≤ n) (xs : Vec A n) →
274+
map f (truncate m≤n xs) ≡ truncate m≤n (map f xs)
261275
262-
padRight-lookup : (m≤n : m ≤ n) (a : A) (xs : Vec A m) (i : Fin m) → lookup (padRight m≤n a xs) (inject≤ i m≤n) ≡ lookup xs i
276+
padRight-lookup : .(m≤n : m ≤ n) (a : A) (xs : Vec A m) (i : Fin m) →
277+
lookup (padRight m≤n a xs) (inject≤ i m≤n) ≡ lookup xs i
263278
264-
padRight-map : (f : A → B) (m≤n : m ≤ n) (a : A) (xs : Vec A m) → map f (padRight m≤n a xs) ≡ padRight m≤n (f a) (map f xs)
279+
padRight-map : (f : A → B) .(m≤n : m ≤ n) (a : A) (xs : Vec A m) →
280+
map f (padRight m≤n a xs) ≡ padRight m≤n (f a) (map f xs)
265281
266-
padRight-zipWith : (f : A → B → C) (m≤n : m ≤ n) (a : A) (b : B) (xs : Vec A m) (ys : Vec B m) →
267-
zipWith f (padRight m≤n a xs) (padRight m≤n b ys) ≡ padRight m≤n (f a b) (zipWith f xs ys)
282+
padRight-zipWith : (f : A → B → C) .(m≤n : m ≤ n) (a : A) (b : B)
283+
(xs : Vec A m) (ys : Vec B m) →
284+
zipWith f (padRight m≤n a xs) (padRight m≤n b ys) ≡
285+
padRight m≤n (f a b) (zipWith f xs ys)
268286
269-
padRight-zipWith₁ : (f : A → B → C) (o≤m : o ≤ m) (m≤n : m ≤ n) (a : A) (b : B) (xs : Vec A m) (ys : Vec B o) →
270-
zipWith f (padRight m≤n a xs) (padRight (≤-trans o≤m m≤n) b ys) ≡
271-
padRight m≤n (f a b) (zipWith f xs (padRight o≤m b ys))
287+
padRight-zipWith₁ : (f : A → B → C) .(o≤m : o ≤ m) .(m≤n : m ≤ n) (a : A) (b : B)
288+
(xs : Vec A m) (ys : Vec B o) →
289+
zipWith f (padRight m≤n a xs) (padRight (≤-trans o≤m m≤n) b ys) ≡
290+
padRight m≤n (f a b) (zipWith f xs (padRight o≤m b ys))
272291
273-
padRight-take : (m≤n : m ≤ n) (a : A) (xs : Vec A m) .(n≡m+o : n ≡ m + o) → take m (cast n≡m+o (padRight m≤n a xs)) ≡ xs
292+
padRight-take : .(m≤n : m ≤ n) (a : A) (xs : Vec A m) .(n≡m+o : n ≡ m + o) →
293+
take m (cast n≡m+o (padRight m≤n a xs)) ≡ xs
274294
275-
padRight-drop : (m≤n : m ≤ n) (a : A) (xs : Vec A m) .(n≡m+o : n ≡ m + o) → drop m (cast n≡m+o (padRight m≤n a xs)) ≡ replicate o a
295+
padRight-drop : .(m≤n : m ≤ n) (a : A) (xs : Vec A m) .(n≡m+o : n ≡ m + o) →
296+
drop m (cast n≡m+o (padRight m≤n a xs)) ≡ replicate o a
276297
277-
padRight-updateAt : (m≤n : m ≤ n) (x : A) (xs : Vec A m) (f : A → A) (i : Fin m) →
278-
updateAt (padRight m≤n x xs) (inject≤ i m≤n) f ≡ padRight m≤n x (updateAt xs i f)
298+
padRight-updateAt : .(m≤n : m ≤ n) (x : A) (xs : Vec A m) (f : A → A) (i : Fin m) →
299+
updateAt (padRight m≤n x xs) (inject≤ i m≤n) f ≡
300+
padRight m≤n x (updateAt xs i f)
279301
```
280302

281303
* In `Relation.Binary.Construct.Add.Extrema.NonStrict`:

src/Data/Vec/Base.agda

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,14 @@ uncons (x ∷ xs) = x , xs
289289
-- Operations involving ≤
290290

291291
-- Take the first 'm' elements of a vector.
292-
truncate : {m n} m ≤ n Vec A n Vec A m
293-
truncate {m = zero} _ _ = []
294-
truncate (s≤s le) (x ∷ xs) = x ∷ (truncate le xs)
292+
truncate : .(m ≤ n) Vec A n Vec A m
293+
truncate {m = zero} _ _ = []
294+
truncate {m = suc _} le (x ∷ xs) = x ∷ (truncate (s≤s⁻¹ le) xs)
295295

296296
-- Pad out a vector with extra elements.
297-
padRight : {m n} m ≤ n A Vec A m Vec A n
298-
padRight z≤n a xs = replicate _ a
299-
padRight (s≤s le) a (x ∷ xs) = x ∷ padRight le a xs
297+
padRight : .(m ≤ n) A Vec A m Vec A n
298+
padRight {n = n} _ a [] = replicate n a
299+
padRight {n = suc _} le a (x ∷ xs) = x ∷ padRight (s≤s⁻¹ le) a xs
300300

301301
------------------------------------------------------------------------
302302
-- Operations for converting between lists

0 commit comments

Comments
 (0)