| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Half adjoint equivalences |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Function.Properties.Inverse.HalfAdjointEquivalence where |
| 10 |
|
| 11 |
open import Function.Base using (id; _∘_) |
| 12 |
open import Function.Bundles using (Inverse; _↔_; mk↔ₛ′) |
| 13 |
open import Level using (Level; _⊔_) |
| 14 |
open import Relation.Binary.PropositionalEquality |
| 15 |
using (_≡_; refl; cong; sym; trans; trans-reflʳ; cong-≡id; cong-∘; naturality |
| 16 |
; cong-id; trans-assoc; trans-symˡ; module ≡-Reasoning) |
| 17 |
|
| 18 |
private |
| 19 |
variable |
| 20 |
a b : Level |
| 21 |
A B : Set a |
| 22 |
|
| 23 |
-- Half adjoint equivalences (see the HoTT book). |
| 24 |
-- |
| 25 |
-- They are inverses with an extra coherence condition that the left |
| 26 |
-- and right inversion proofs interact the right way with `cong`. |
| 27 |
|
| 28 |
infix 4 _≃_ |
| 29 |
|
| 30 |
record _≃_ (A : Set a) (B : Set b) : Set (a ⊔ b) where |
| 31 |
field |
| 32 |
to : A → B |
| 33 |
from : B → A |
| 34 |
left-inverse-of : ∀ x → from (to x) ≡ x |
| 35 |
right-inverse-of : ∀ x → to (from x) ≡ x |
| 36 |
left-right : ∀ x → cong to (left-inverse-of x) ≡ right-inverse-of (to x) |
| 37 |
|
| 38 |
-- The forward direction of a half adjoint equivalence is injective. |
| 39 |
|
| 40 |
injective : ∀ {x y} → to x ≡ to y → x ≡ y |
| 41 |
injective {x} {y} to-x≡to-y = |
| 42 |
x ≡⟨ sym (left-inverse-of _) ⟩ |
| 43 |
from (to x) ≡⟨ cong from to-x≡to-y ⟩ |
| 44 |
from (to y) ≡⟨ left-inverse-of _ ⟩ |
| 45 |
y ∎ |
| 46 |
where open ≡-Reasoning |
| 47 |
|
| 48 |
-- Half adjoint equivalences can be turned into inverses. |
| 49 |
|
| 50 |
≃⇒↔ : A ≃ B → A ↔ B |
| 51 |
≃⇒↔ A≃B = mk↔ₛ′ to from right-inverse-of left-inverse-of |
| 52 |
where open _≃_ A≃B |
| 53 |
|
| 54 |
-- Inverses can be turned into half adjoint equivalences. |
| 55 |
-- |
| 56 |
-- (This proof is based on one in the HoTT book.) |
| 57 |
|
| 58 |
↔⇒≃ : A ↔ B → A ≃ B |
| 59 |
↔⇒≃ A↔B = record |
| 60 |
{ to = to |
| 61 |
; from = from |
| 62 |
; left-inverse-of = strictlyInverseʳ |
| 63 |
; right-inverse-of = right-inverse-of |
| 64 |
; left-right = left-right |
| 65 |
} |
| 66 |
where |
| 67 |
open ≡-Reasoning |
| 68 |
open module A↔B = Inverse A↔B |
| 69 |
|
| 70 |
right-inverse-of : ∀ x → to (from x) ≡ x |
| 71 |
right-inverse-of x = |
| 72 |
to (from x) ≡⟨ sym (A↔B.strictlyInverseˡ _) ⟩ |
| 73 |
to (from (to (from x))) ≡⟨ cong to (strictlyInverseʳ _) ⟩ |
| 74 |
to (from x) ≡⟨ A↔B.strictlyInverseˡ _ ⟩ |
| 75 |
x ∎ |
| 76 |
|
| 77 |
left-right : |
| 78 |
∀ x → |
| 79 |
cong to (strictlyInverseʳ x) ≡ right-inverse-of (to x) |
| 80 |
left-right x = |
| 81 |
cong to (strictlyInverseʳ x) ≡⟨⟩ |
| 82 |
|
| 83 |
trans refl (cong to (strictlyInverseʳ _)) ≡⟨ cong (λ p → trans p (cong to (strictlyInverseʳ _))) |
| 84 |
(sym (trans-symˡ (A↔B.strictlyInverseˡ _))) ⟩ |
| 85 |
trans (trans (sym (A↔B.strictlyInverseˡ _)) |
| 86 |
(A↔B.strictlyInverseˡ _)) |
| 87 |
(cong to (strictlyInverseʳ _)) ≡⟨ trans-assoc (sym (A↔B.strictlyInverseˡ _)) ⟩ |
| 88 |
|
| 89 |
trans (sym (A↔B.strictlyInverseˡ _)) |
| 90 |
(trans (A↔B.strictlyInverseˡ _) |
| 91 |
(cong to (strictlyInverseʳ _))) ≡⟨ cong (trans (sym (A↔B.strictlyInverseˡ _))) lemma ⟩ |
| 92 |
|
| 93 |
trans (sym (A↔B.strictlyInverseˡ _)) |
| 94 |
(trans (cong to (strictlyInverseʳ _)) |
| 95 |
(trans (A↔B.strictlyInverseˡ _) refl)) ≡⟨⟩ |
| 96 |
|
| 97 |
right-inverse-of (to x) ∎ |
| 98 |
where |
| 99 |
lemma = |
| 100 |
trans (A↔B.strictlyInverseˡ _) |
| 101 |
(cong to (strictlyInverseʳ _)) ≡⟨ cong (trans (A↔B.strictlyInverseˡ _)) (sym (cong-id _)) ⟩ |
| 102 |
|
| 103 |
trans (A↔B.strictlyInverseˡ _) |
| 104 |
(cong id (cong to (strictlyInverseʳ _))) ≡⟨ sym (naturality A↔B.strictlyInverseˡ) ⟩ |
| 105 |
|
| 106 |
trans (cong (to ∘ from) |
| 107 |
(cong to (strictlyInverseʳ _))) |
| 108 |
(A↔B.strictlyInverseˡ _) ≡⟨ cong (λ p → trans p (A↔B.strictlyInverseˡ _)) |
| 109 |
(sym (cong-∘ _)) ⟩ |
| 110 |
trans (cong (to ∘ from ∘ to) |
| 111 |
(strictlyInverseʳ _)) |
| 112 |
(A↔B.strictlyInverseˡ _) ≡⟨ cong (λ p → trans p (A↔B.strictlyInverseˡ _)) |
| 113 |
(cong-∘ _) ⟩ |
| 114 |
trans (cong to |
| 115 |
(cong (from ∘ to) |
| 116 |
(strictlyInverseʳ _))) |
| 117 |
(A↔B.strictlyInverseˡ _) ≡⟨ cong (λ p → trans (cong to p) (strictlyInverseˡ (to x))) |
| 118 |
(cong-≡id strictlyInverseʳ) ⟩ |
| 119 |
trans (cong to (strictlyInverseʳ _)) |
| 120 |
(A↔B.strictlyInverseˡ _) ≡⟨ cong (trans (cong to (strictlyInverseʳ _))) |
| 121 |
(sym (trans-reflʳ _)) ⟩ |
| 122 |
trans (cong to (strictlyInverseʳ _)) |
| 123 |
(trans (A↔B.strictlyInverseˡ _) refl) ∎ |