Debian Codegraph @

src/Function/Properties/Inverse.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties of inverses.
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Function.Properties.Inverse where
10
11 open import Axiom.Extensionality.Propositional using (Extensionality)
12 open import Data.Product.Base using (_,_; proj₁; proj₂)
13 open import Function.Bundles
14 import Function.Properties.RightInverse as RightInverse using (to-from)
15 open import Level using (Level; _⊔_)
16 open import Relation.Binary.Core using (REL)
17 open import Relation.Binary.Bundles using (Setoid)
18 open import Relation.Binary.Structures using (IsEquivalence)
19 open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
20 import Relation.Binary.Reasoning.Setoid as ≈-Reasoning
21 import Function.Consequences.Setoid as Consequences
22 using (inverseʳ⇒injective; inverseˡ⇒surjective; inverseᵇ⇒bijective)
23
24 import Function.Construct.Identity as Identity
25 import Function.Construct.Symmetry as Symmetry
26 import Function.Construct.Composition as Composition
27
28 private
29 variable
30 a b ℓ ℓ₁ ℓ₂ : Level
31 A B C D : Set a
32 S T U V : Setoid a ℓ
33
34 ------------------------------------------------------------------------
35 -- Setoid bundles
36
37 open Identity public using () renaming (inverse to refl)
38 open Symmetry public using () renaming (inverse to sym)
39 open Composition public using () renaming (inverse to trans)
40
41 isEquivalence : IsEquivalence (Inverse {a} {b})
42 isEquivalence = record
43 { refl = λ {x} → Identity.inverse x
44 ; sym = sym
45 ; trans = trans
46 }
47
48 ------------------------------------------------------------------------
49 -- Propositional bundles
50
51 ↔-refl : A ↔ A
52 ↔-refl = Identity.↔-id _
53
54 ↔-sym : A ↔ B → B ↔ A
55 ↔-sym = Symmetry.↔-sym
56
57 ↔-trans : A ↔ B → B ↔ C → A ↔ C
58 ↔-trans = Composition.inverse
59
60 -- need to η-expand for everything to line up properly
61 ↔-isEquivalence : IsEquivalence {ℓ = ℓ} _↔_
62 ↔-isEquivalence = record
63 { refl = ↔-refl
64 ; sym = ↔-sym
65 ; trans = ↔-trans
66 }
67
68 ------------------------------------------------------------------------
69 -- Conversion functions
70
71 toFunction : Inverse S T → Func S T
72 toFunction I = record { to = to ; cong = to-cong }
73 where open Inverse I
74
75 fromFunction : Inverse S T → Func T S
76 fromFunction I = record { to = from ; cong = from-cong }
77 where open Inverse I
78
79 Inverse⇒Injection : Inverse S T → Injection S T
80 Inverse⇒Injection {S = S} {T = T} I = record
81 { to = to
82 ; cong = to-cong
83 ; injective = inverseʳ⇒injective to inverseʳ
84 } where open Inverse I; open Consequences S T
85
86 Inverse⇒Surjection : Inverse S T → Surjection S T
87 Inverse⇒Surjection {S = S} {T = T} I = record
88 { to = to
89 ; cong = to-cong
90 ; surjective = inverseˡ⇒surjective inverseˡ
91 } where open Inverse I; open Consequences S T
92
93 Inverse⇒Bijection : Inverse S T → Bijection S T
94 Inverse⇒Bijection {S = S} {T = T} I = record
95 { to = to
96 ; cong = to-cong
97 ; bijective = inverseᵇ⇒bijective inverse
98 } where open Inverse I; open Consequences S T
99
100 Inverse⇒Equivalence : Inverse S T → Equivalence S T
101 Inverse⇒Equivalence I = record
102 { to = to
103 ; from = from
104 ; to-cong = to-cong
105 ; from-cong = from-cong
106 } where open Inverse I
107
108 ↔⇒⟶ : A ↔ B → A ⟶ B
109 ↔⇒⟶ = toFunction
110
111 ↔⇒⟵ : A ↔ B → B ⟶ A
112 ↔⇒⟵ = fromFunction
113
114 ↔⇒↣ : A ↔ B → A ↣ B
115 ↔⇒↣ = Inverse⇒Injection
116
117 ↔⇒↠ : A ↔ B → A ↠ B
118 ↔⇒↠ = Inverse⇒Surjection
119
120 ↔⇒⤖ : A ↔ B → A ⤖ B
121 ↔⇒⤖ = Inverse⇒Bijection
122
123 ↔⇒⇔ : A ↔ B → A ⇔ B
124 ↔⇒⇔ = Inverse⇒Equivalence
125
126 ↔⇒↩ : A ↔ B → A ↩ B
127 ↔⇒↩ = Inverse.leftInverse
128
129 ↔⇒↪ : A ↔ B → A ↪ B
130 ↔⇒↪ = Inverse.rightInverse
131
132 -- The functions above can be combined with the following lemma to
133 -- transport an arbitrary relation R (e.g. Injection) across
134 -- inverses.
135 transportVia : {R : ∀ {a b ℓ₁ ℓ₂} → REL (Setoid a ℓ₁) (Setoid b ℓ₂) (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂)} →
136 (∀ {a b c ℓ₁ ℓ₂ ℓ₃} {S : Setoid a ℓ₁} {T : Setoid b ℓ₂} {U : Setoid c ℓ₃} → R S T → R T U → R S U) →
137 (∀ {a b ℓ₁ ℓ₂} {S : Setoid a ℓ₁} {T : Setoid b ℓ₂} → Inverse S T → R S T) →
138 Inverse S T → R T U → Inverse U V → R S V
139 transportVia R-trans inv⇒R IBA RBC ICD =
140 R-trans (inv⇒R IBA) (R-trans RBC (inv⇒R ICD))
141
142 ------------------------------------------------------------------------
143 -- Other
144
145 module _ (ext : ∀ {a b} → Extensionality a b) where
146
147 ↔-fun : A ↔ B → C ↔ D → (A → C) ↔ (B → D)
148 ↔-fun A↔B C↔D = mk↔ₛ′
149 (λ a→c b → to C↔D (a→c (from A↔B b)))
150 (λ b→d a → from C↔D (b→d (to A↔B a)))
151 (λ b→d → ext λ _ → ≡.trans (strictlyInverseˡ C↔D _ ) (≡.cong b→d (strictlyInverseˡ A↔B _)))
152 (λ a→c → ext λ _ → ≡.trans (strictlyInverseʳ C↔D _ ) (≡.cong a→c (strictlyInverseʳ A↔B _)))
153 where open Inverse
154
155 module _ (I : Inverse S T) where
156 open Inverse I
157
158 to-from : ∀ {x y} → to x Eq₂.≈ y → from y Eq₁.≈ x
159 to-from = RightInverse.to-from rightInverse