@@ -375,6 +375,8 @@ lookup∘update′ {i = i} {j} i≢j xs y = lookup∘updateAt′ i j i≢j xs
375
375
open VecCast public
376
376
using (cast-is-id; cast-trans)
377
377
378
+ open VecCast using (≈-cong′)
379
+
378
380
subst-is-cast : (eq : m ≡ n) (xs : Vec A m) → subst (Vec A) eq xs ≡ cast eq xs
379
381
subst-is-cast refl xs = sym (cast-is-id refl xs)
380
382
@@ -398,9 +400,7 @@ map-const (_ ∷ xs) y = cong (y ∷_) (map-const xs y)
398
400
399
401
map-cast : (f : A → B) .(eq : m ≡ n) (xs : Vec A m) →
400
402
map f (cast eq xs) ≡ cast eq (map f xs)
401
- map-cast {n = zero} f eq [] = refl
402
- map-cast {n = suc _} f eq (x ∷ xs)
403
- = cong (f x ∷_) (map-cast f (suc-injective eq) xs)
403
+ map-cast f _ _ = sym (≈-cong′ (map f) refl)
404
404
405
405
map-++ : ∀ (f : A → B) (xs : Vec A m) (ys : Vec A n) →
406
406
map f (xs ++ ys) ≡ map f xs ++ map f ys
@@ -494,13 +494,11 @@ toList-map f (x ∷ xs) = cong (f x List.∷_) (toList-map f xs)
494
494
495
495
cast-++ˡ : ∀ .(eq : m ≡ o) (xs : Vec A m) {ys : Vec A n} →
496
496
cast (cong (_+ n) eq) (xs ++ ys) ≡ cast eq xs ++ ys
497
- cast-++ˡ {o = zero} eq [] {ys} = cast-is-id refl (cast eq [] ++ ys)
498
- cast-++ˡ {o = suc o} eq (x ∷ xs) {ys} = cong (x ∷_) (cast-++ˡ (cong pred eq) xs)
497
+ cast-++ˡ _ _ {ys} = ≈-cong′ (_++ ys) refl
499
498
500
499
cast-++ʳ : ∀ .(eq : n ≡ o) (xs : Vec A m) {ys : Vec A n} →
501
500
cast (cong (m +_) eq) (xs ++ ys) ≡ xs ++ cast eq ys
502
- cast-++ʳ {m = zero} eq [] {ys} = refl
503
- cast-++ʳ {m = suc m} eq (x ∷ xs) {ys} = cong (x ∷_) (cast-++ʳ eq xs)
501
+ cast-++ʳ _ xs = ≈-cong′ (xs ++_) refl
504
502
505
503
lookup-++-< : ∀ (xs : Vec A m) (ys : Vec A n) →
506
504
∀ i (i<m : toℕ i < m) →
@@ -929,8 +927,7 @@ map-∷ʳ f x (y ∷ xs) = cong (f y ∷_) (map-∷ʳ f x xs)
929
927
930
928
cast-∷ʳ : ∀ .(eq : suc n ≡ suc m) x (xs : Vec A n) →
931
929
cast eq (xs ∷ʳ x) ≡ (cast (cong pred eq) xs) ∷ʳ x
932
- cast-∷ʳ {m = zero} eq x [] = refl
933
- cast-∷ʳ {m = suc m} eq x (y ∷ xs) = cong (y ∷_) (cast-∷ʳ (cong pred eq) x xs)
930
+ cast-∷ʳ _ x _ = ≈-cong′ (_∷ʳ x) refl
934
931
935
932
-- _++_ and _∷ʳ_
936
933
@@ -1034,23 +1031,14 @@ reverse-++-eqFree : ∀ (xs : Vec A m) (ys : Vec A n) → let eq = +-comm m n in
1034
1031
reverse-++-eqFree {m = zero} {n = n} [] ys = ≈-sym (++-identityʳ-eqFree (reverse ys))
1035
1032
reverse-++-eqFree {m = suc m} {n = n} (x ∷ xs) ys = begin
1036
1033
reverse (x ∷ xs ++ ys) ≂⟨ reverse-∷ x (xs ++ ys) ⟩
1037
- reverse (xs ++ ys) ∷ʳ x ≈⟨ ≈-cong (_∷ʳ x) (cast-∷ʳ (cong suc (+-comm m n)) x (reverse (xs ++ ys)))
1038
- (reverse-++-eqFree xs ys) ⟩
1034
+ reverse (xs ++ ys) ∷ʳ x ≈⟨ ≈-cong′ (_∷ʳ x) (reverse-++-eqFree xs ys) ⟩
1039
1035
(reverse ys ++ reverse xs) ∷ʳ x ≈⟨ ++-∷ʳ-eqFree x (reverse ys) (reverse xs) ⟩
1040
1036
reverse ys ++ (reverse xs ∷ʳ x) ≂⟨ cong (reverse ys ++_) (reverse-∷ x xs) ⟨
1041
1037
reverse ys ++ (reverse (x ∷ xs)) ∎
1042
1038
where open CastReasoning
1043
1039
1044
1040
cast-reverse : ∀ .(eq : m ≡ n) → cast eq ∘ reverse {A = A} {n = m} ≗ reverse ∘ cast eq
1045
- cast-reverse {n = zero} eq [] = refl
1046
- cast-reverse {n = suc n} eq (x ∷ xs) = begin
1047
- reverse (x ∷ xs) ≂⟨ reverse-∷ x xs ⟩
1048
- reverse xs ∷ʳ x ≈⟨ ≈-cong (_∷ʳ x) (cast-∷ʳ eq x (reverse xs))
1049
- (cast-reverse (cong pred eq) xs) ⟩
1050
- reverse (cast _ xs) ∷ʳ x ≂⟨ reverse-∷ x (cast (cong pred eq) xs) ⟨
1051
- reverse (x ∷ cast _ xs) ≈⟨⟩
1052
- reverse (cast eq (x ∷ xs)) ∎
1053
- where open CastReasoning
1041
+ cast-reverse _ _ = ≈-cong′ reverse refl
1054
1042
1055
1043
------------------------------------------------------------------------
1056
1044
-- _ʳ++_
@@ -1094,8 +1082,7 @@ map-ʳ++ {ys = ys} f xs = begin
1094
1082
cast eq ((xs ++ ys) ʳ++ zs) ≡ ys ʳ++ (xs ʳ++ zs)
1095
1083
++-ʳ++-eqFree {m = m} {n} {o} xs {ys} {zs} = begin
1096
1084
((xs ++ ys) ʳ++ zs) ≂⟨ unfold-ʳ++ (xs ++ ys) zs ⟩
1097
- reverse (xs ++ ys) ++ zs ≈⟨ ≈-cong (_++ zs) (cast-++ˡ (+-comm m n) (reverse (xs ++ ys)))
1098
- (reverse-++-eqFree xs ys) ⟩
1085
+ reverse (xs ++ ys) ++ zs ≈⟨ ≈-cong′ (_++ zs) (reverse-++-eqFree xs ys) ⟩
1099
1086
(reverse ys ++ reverse xs) ++ zs ≈⟨ ++-assoc-eqFree (reverse ys) (reverse xs) zs ⟩
1100
1087
reverse ys ++ (reverse xs ++ zs) ≂⟨ cong (reverse ys ++_) (unfold-ʳ++ xs zs) ⟨
1101
1088
reverse ys ++ (xs ʳ++ zs) ≂⟨ unfold-ʳ++ ys (xs ʳ++ zs) ⟨
@@ -1107,8 +1094,7 @@ map-ʳ++ {ys = ys} f xs = begin
1107
1094
ʳ++-ʳ++-eqFree {m = m} {n} {o} xs {ys} {zs} = begin
1108
1095
(xs ʳ++ ys) ʳ++ zs ≂⟨ cong (_ʳ++ zs) (unfold-ʳ++ xs ys) ⟩
1109
1096
(reverse xs ++ ys) ʳ++ zs ≂⟨ unfold-ʳ++ (reverse xs ++ ys) zs ⟩
1110
- reverse (reverse xs ++ ys) ++ zs ≈⟨ ≈-cong (_++ zs) (cast-++ˡ (+-comm m n) (reverse (reverse xs ++ ys)))
1111
- (reverse-++-eqFree (reverse xs) ys) ⟩
1097
+ reverse (reverse xs ++ ys) ++ zs ≈⟨ ≈-cong′ (_++ zs) (reverse-++-eqFree (reverse xs) ys) ⟩
1112
1098
(reverse ys ++ reverse (reverse xs)) ++ zs ≂⟨ cong ((_++ zs) ∘ (reverse ys ++_)) (reverse-involutive xs) ⟩
1113
1099
(reverse ys ++ xs) ++ zs ≈⟨ ++-assoc-eqFree (reverse ys) xs zs ⟩
1114
1100
reverse ys ++ (xs ++ zs) ≂⟨ unfold-ʳ++ ys (xs ++ zs) ⟨
@@ -1338,8 +1324,7 @@ fromList-reverse (x List.∷ xs) = begin
1338
1324
fromList (List.reverse (x List.∷ xs)) ≈⟨ cast-fromList (List.ʳ++-defn xs) ⟩
1339
1325
fromList (List.reverse xs List.++ List.[ x ]) ≈⟨ fromList-++ (List.reverse xs) ⟩
1340
1326
fromList (List.reverse xs) ++ [ x ] ≈⟨ unfold-∷ʳ-eqFree x (fromList (List.reverse xs)) ⟨
1341
- fromList (List.reverse xs) ∷ʳ x ≈⟨ ≈-cong (_∷ʳ x) (cast-∷ʳ (cong suc (List.length-reverse xs)) _ _)
1342
- (fromList-reverse xs) ⟩
1327
+ fromList (List.reverse xs) ∷ʳ x ≈⟨ ≈-cong′ (_∷ʳ x) (fromList-reverse xs) ⟩
1343
1328
reverse (fromList xs) ∷ʳ x ≂⟨ reverse-∷ x (fromList xs) ⟨
1344
1329
reverse (x ∷ fromList xs) ≈⟨⟩
1345
1330
reverse (fromList (x List.∷ xs)) ∎
0 commit comments