@@ -425,6 +425,58 @@ last combines the left inverse of `B ≲ A` with the equivalences of
425425the ` to ` and ` from ` components from the two embeddings to obtain
426426the right inverse of the isomorphism.
427427
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 =
442+ record
443+ { to = to A≲B
444+ ; from = from A≲B
445+ ; from∘to = from∘to A≲B
446+ ; to∘from = from∘to B≲A
447+ }
448+ ```
449+
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.
461+
462+ One subtlety is why Agda accepts these ` refl ` patterns at all. The
463+ equalities compare projections from two records, rather than variables
464+ written directly on the left-hand side. Agda silently η-expands record
465+ 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
469+
470+ record
471+ { to = to A≲B
472+ ; from = from A≲B
473+ ; from∘to = from∘to A≲B
474+ }
475+
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 ` .
479+
428480# Equational reasoning for embedding
429481
430482We can also support tabular reasoning for embedding,
0 commit comments