Skip to content

Commit f94c2a1

Browse files
committed
rewritten as requested by @wadler
1 parent 0083290 commit f94c2a1

1 file changed

Lines changed: 34 additions & 58 deletions

File tree

src/plfa/part1/Isomorphism.lagda.md

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ are cut down versions of the similar proofs for isomorphism:
392392

393393
It is also easy to see that if two types embed in each other, and the
394394
embedding functions correspond, then they are isomorphic. This is a
395-
weak form of anti-symmetry:
395+
weak form of anti-symmetry. The proof does some of the work by
396+
matching the evidence that the functions correspond against `refl`:
396397

397398
```agda
398399
≲-antisym : ∀ {A B : Set}
@@ -402,43 +403,7 @@ weak form of anti-symmetry:
402403
→ (from A≲B ≡ to B≲A)
403404
-------------------
404405
→ A ≃ B
405-
≲-antisym A≲B B≲A to≡from from≡to =
406-
record
407-
{ to = to A≲B
408-
; from = from A≲B
409-
; from∘to = from∘to A≲B
410-
; to∘from = λ{y →
411-
begin
412-
to A≲B (from A≲B y)
413-
≡⟨ cong (to A≲B) (cong-app from≡to y) ⟩
414-
to A≲B (to B≲A y)
415-
≡⟨ cong-app to≡from (to B≲A y) ⟩
416-
from B≲A (to B≲A y)
417-
≡⟨ from∘to B≲A y ⟩
418-
y
419-
∎}
420-
}
421-
```
422-
423-
The first three components are copied from the embedding, while the
424-
last combines the left inverse of `B ≲ A` with the equivalences of
425-
the `to` and `from` components from the two embeddings to obtain
426-
the right inverse of the isomorphism.
427-
428-
The previous proof can also be shortened by doing more work in the
429-
patterns on the left-hand side. If the two proofs that the embedding
430-
functions correspond are both matched against `refl`, then Agda records
431-
that the corresponding functions are the same:
432-
433-
```agda
434-
≲-antisym′ : ∀ {A B : Set}
435-
→ (A≲B : A ≲ B)
436-
→ (B≲A : B ≲ A)
437-
→ (to A≲B ≡ from B≲A)
438-
→ (from A≲B ≡ to B≲A)
439-
-------------------
440-
→ A ≃ B
441-
≲-antisym′ A≲B B≲A refl refl =
406+
≲-antisym A≲B B≲A to≡from@refl from≡to@refl =
442407
record
443408
{ to = to A≲B
444409
; from = from A≲B
@@ -447,35 +412,46 @@ that the corresponding functions are the same:
447412
}
448413
```
449414

450-
After matching the third parameter, called `to≡from` above, against
451-
`refl`, Agda knows that `to A≲B` and `from B≲A` are the same function.
452-
After matching the fourth parameter, called `from≡to` above, against
453-
`refl`, Agda knows that `from A≲B` and `to B≲A` are the same function.
454-
Hence the type of `from∘to B≲A`,
455-
456-
∀ (y : B) → from B≲A (to B≲A y) ≡ y
457-
458-
is the same as the type required for `to∘from`,
459-
460-
∀ (y : B) → to A≲B (from A≲B y) ≡ y.
415+
The first three components are copied from the embedding `A≲B`. For
416+
the last component, matching `to≡from` against `refl` tells Agda that
417+
`to A≲B` and `from B≲A` are the same function, while matching
418+
`from≡to` against `refl` tells Agda that `from A≲B` and `to B≲A` are
419+
the same function. Hence `from∘to B≲A` has the required type.
461420

462421
One subtlety is why Agda accepts these `refl` patterns at all. The
463422
equalities compare projections from two records, rather than variables
464423
written directly on the left-hand side. Agda silently η-expands record
465424
values. This property is called η-equality for records: a record is
466-
determined by its fields. A value `A≲B` is definitionally the same as
467-
the record obtained by projecting out all its fields and putting them
468-
back together. For an embedding, this means `A≲B` is the same as
425+
determined by its fields. A record value is definitionally equal to the
426+
record obtained by projecting out all its fields and putting them back
427+
together. Thus, when checking the left-hand side, Agda may view the two
428+
embeddings as
469429

470430
record
471-
{ to = to A≲B
472-
; from = from A≲B
473-
; from∘to = from∘to A≲B
431+
{ to = f
432+
; from = g
433+
; from∘to = p
474434
}
475435

476-
and similarly for `B≲A`. This η-expansion lets pattern matching on
477-
`refl` refine the corresponding record fields, which is why the shorter
478-
proof can replace the whole equational derivation by `from∘to B≲A`.
436+
and
437+
438+
record
439+
{ to = h
440+
; from = k
441+
; from∘to = q
442+
}
443+
444+
where `f` is `to A≲B`, `g` is `from A≲B`, `h` is `to B≲A`, and `k` is
445+
`from B≲A`. After this expansion, the equality arguments have types
446+
`f ≡ k` and `g ≡ h`, so matching them against `refl` identifies
447+
`f` with `k`, and `g` with `h`. It is not that η-expanding `A≲B`
448+
computes `to A≲B` to something new; rather, η-expansion lets Agda
449+
expose the fields of record variables while solving the pattern match.
450+
Under these identifications, `from∘to B≲A` has type
451+
452+
∀ (y : B) → to A≲B (from A≲B y) ≡ y
453+
454+
which is exactly the type required for `to∘from`.
479455

480456
# Equational reasoning for embedding
481457

0 commit comments

Comments
 (0)