@@ -375,6 +375,8 @@ lookup∘update′ {i = i} {j} i≢j xs y = lookup∘updateAt′ i j i≢j xs
375375open VecCast public
376376 using (cast-is-id; cast-trans)
377377
378+ open VecCast using (≈-cong′)
379+
378380subst-is-cast : (eq : m ≡ n) (xs : Vec A m) → subst (Vec A) eq xs ≡ cast eq xs
379381subst-is-cast refl xs = sym (cast-is-id refl xs)
380382
@@ -398,9 +400,7 @@ map-const (_ ∷ xs) y = cong (y ∷_) (map-const xs y)
398400
399401map-cast : (f : A → B) .(eq : m ≡ n) (xs : Vec A m) →
400402 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)
404404
405405map-++ : ∀ (f : A → B) (xs : Vec A m) (ys : Vec A n) →
406406 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)
494494
495495cast-++ˡ : ∀ .(eq : m ≡ o) (xs : Vec A m) {ys : Vec A n} →
496496 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
499498
500499cast-++ʳ : ∀ .(eq : n ≡ o) (xs : Vec A m) {ys : Vec A n} →
501500 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
504502
505503lookup-++-< : ∀ (xs : Vec A m) (ys : Vec A n) →
506504 ∀ i (i<m : toℕ i < m) →
@@ -929,8 +927,7 @@ map-∷ʳ f x (y ∷ xs) = cong (f y ∷_) (map-∷ʳ f x xs)
929927
930928cast-∷ʳ : ∀ .(eq : suc n ≡ suc m) x (xs : Vec A n) →
931929 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
934931
935932-- _++_ and _∷ʳ_
936933
@@ -1034,23 +1031,14 @@ reverse-++-eqFree : ∀ (xs : Vec A m) (ys : Vec A n) → let eq = +-comm m n in
10341031reverse-++-eqFree {m = zero} {n = n} [] ys = ≈-sym (++-identityʳ-eqFree (reverse ys))
10351032reverse-++-eqFree {m = suc m} {n = n} (x ∷ xs) ys = begin
10361033 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) ⟩
10391035 (reverse ys ++ reverse xs) ∷ʳ x ≈⟨ ++-∷ʳ-eqFree x (reverse ys) (reverse xs) ⟩
10401036 reverse ys ++ (reverse xs ∷ʳ x) ≂⟨ cong (reverse ys ++_) (reverse-∷ x xs) ⟨
10411037 reverse ys ++ (reverse (x ∷ xs)) ∎
10421038 where open CastReasoning
10431039
10441040cast-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
10541042
10551043------------------------------------------------------------------------
10561044-- _ʳ++_
@@ -1094,8 +1082,7 @@ map-ʳ++ {ys = ys} f xs = begin
10941082 cast eq ((xs ++ ys) ʳ++ zs) ≡ ys ʳ++ (xs ʳ++ zs)
10951083++-ʳ++-eqFree {m = m} {n} {o} xs {ys} {zs} = begin
10961084 ((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) ⟩
10991086 (reverse ys ++ reverse xs) ++ zs ≈⟨ ++-assoc-eqFree (reverse ys) (reverse xs) zs ⟩
11001087 reverse ys ++ (reverse xs ++ zs) ≂⟨ cong (reverse ys ++_) (unfold-ʳ++ xs zs) ⟨
11011088 reverse ys ++ (xs ʳ++ zs) ≂⟨ unfold-ʳ++ ys (xs ʳ++ zs) ⟨
@@ -1107,8 +1094,7 @@ map-ʳ++ {ys = ys} f xs = begin
11071094ʳ++-ʳ++-eqFree {m = m} {n} {o} xs {ys} {zs} = begin
11081095 (xs ʳ++ ys) ʳ++ zs ≂⟨ cong (_ʳ++ zs) (unfold-ʳ++ xs ys) ⟩
11091096 (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) ⟩
11121098 (reverse ys ++ reverse (reverse xs)) ++ zs ≂⟨ cong ((_++ zs) ∘ (reverse ys ++_)) (reverse-involutive xs) ⟩
11131099 (reverse ys ++ xs) ++ zs ≈⟨ ++-assoc-eqFree (reverse ys) xs zs ⟩
11141100 reverse ys ++ (xs ++ zs) ≂⟨ unfold-ʳ++ ys (xs ++ zs) ⟨
@@ -1338,8 +1324,7 @@ fromList-reverse (x List.∷ xs) = begin
13381324 fromList (List.reverse (x List.∷ xs)) ≈⟨ cast-fromList (List.ʳ++-defn xs) ⟩
13391325 fromList (List.reverse xs List.++ List.[ x ]) ≈⟨ fromList-++ (List.reverse xs) ⟩
13401326 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) ⟩
13431328 reverse (fromList xs) ∷ʳ x ≂⟨ reverse-∷ x (fromList xs) ⟨
13441329 reverse (x ∷ fromList xs) ≈⟨⟩
13451330 reverse (fromList (x List.∷ xs)) ∎
0 commit comments