@@ -166,19 +166,9 @@ example2b eq xs a ys = begin
166166
167167-- Oftentimes index-changing identities apply to only part of the proof
168168-- term. When reasoning about `_≡_`, `cong` shifts the focus to the
169- -- subterm of interest. In this library, `≈-cong` does a similar job.
170- -- Suppose `f : A → B`, `xs : B`, `ys zs : A`, `ys≈zs : ys ≈[ _ ] zs`
171- -- and `xs≈f⟨c·ys⟩ : xs ≈[ _ ] f (cast _ ys)`, we have
172- -- xs ≈⟨ ≈-cong f xs≈f⟨c·ys⟩ ys≈zs ⟩
173- -- f zs
174- -- The reason for having the extra argument `xs≈f⟨c·ys⟩` is to expose
175- -- `cast` in the subterm in order to apply the step `ys≈zs`. When using
176- -- ordinary `cong` the proof has to explicitly push `cast` inside:
177- -- xs ≈⟨ xs≈f⟨c·ys⟩ ⟩
178- -- f (cast _ ys) ≂⟨ cong f ys≈zs ⟩
179- -- f zs
180- -- Note. Technically, `A` and `B` should be vectors of different length
181- -- and that `ys`, `zs` are vectors of non-definitionally equal index.
169+ -- subterm of interest. In this library, `≈-cong′` does a similar job.
170+ -- For the typechecker to infer the congruence function `f`, it must be
171+ -- polymorphic in the length of the given vector,
182172example3a-fromList-++-++ : {xs ys zs : List A} →
183173 .(eq : List.length (xs List.++ ys List.++ zs) ≡
184174 List.length xs + (List.length ys + List.length zs)) →
@@ -211,15 +201,17 @@ example3b-fromList-++-++′ {xs = xs} {ys} {zs} eq = begin
211201 ∎
212202 where open CastReasoning
213203
214- -- `≈-cong` can be chained together much like how `cong` can be nested.
204+ -- `≈-cong′ ` can be chained together much like how `cong` can be nested.
215205-- In this example, `unfold-∷ʳ` is applied to the term `xs ++ [ a ]`
216206-- in `(_++ ys)` inside of `reverse`. Thus the proof employs two
217- -- `≈-cong`.
207+ -- `≈-cong′` usages, which is equivalent to using one `≈-cong′` with
208+ -- a single composed function.
218209example4-cong² : ∀ .(eq : (m + 1 ) + n ≡ n + suc m) a (xs : Vec A m) ys →
219210 cast eq (reverse ((xs ++ [ a ]) ++ ys)) ≡ ys ʳ++ reverse (xs ∷ʳ a)
220211example4-cong² {m = m} {n} eq a xs ys = begin
221212 reverse ((xs ++ [ a ]) ++ ys)
222- ≈⟨ ≈-cong′ (reverse ∘ (_++ ys)) (unfold-∷ʳ-eqFree a xs) ⟨
213+ ≈⟨ ≈-cong′ reverse (≈-cong′ (_++ ys) (unfold-∷ʳ-eqFree a xs)) ⟨
214+ -- the same as ≈-cong′ (reverse ∘ (_++ ys)) ...
223215 reverse ((xs ∷ʳ a) ++ ys)
224216 ≈⟨ reverse-++-eqFree (xs ∷ʳ a) ys ⟩
225217 reverse ys ++ reverse (xs ∷ʳ a)
0 commit comments