Debian Codegraph @

src/Function/Inverse.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- This module is DEPRECATED.
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8 {-# OPTIONS --warning=noUserWarning #-}
9
10 module Function.Inverse where
11
12 {-# WARNING_ON_IMPORT
13 "Function.Inverse was deprecated in v2.0.
14 Use the standard function hierarchy in Function/Function.Bundles instead."
15 #-}
16
17 open import Level
18 open import Function.Base using (flip)
19 open import Function.Bijection hiding (id; _∘_; bijection)
20 open import Function.Equality as F
21 using (_⟶_) renaming (_∘_ to _⟪∘⟫_)
22 open import Function.LeftInverse as Left hiding (id; _∘_)
23 open import Relation.Binary.Bundles using (Setoid)
24 open import Relation.Binary.Definitions using (Reflexive; TransFlip; Sym)
25 open import Relation.Binary.PropositionalEquality as ≡ using (_≗_; _≡_)
26 open import Relation.Unary using (Pred)
27
28 ------------------------------------------------------------------------
29 -- Inverses
30
31 record _InverseOf_ {f₁ f₂ t₁ t₂}
32 {From : Setoid f₁ f₂} {To : Setoid t₁ t₂}
33 (from : To ⟶ From) (to : From ⟶ To) :
34 Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where
35 field
36 left-inverse-of : from LeftInverseOf to
37 right-inverse-of : from RightInverseOf to
38 {-# WARNING_ON_USAGE _InverseOf_
39 "Warning: _InverseOf_ was deprecated in v2.0.
40 Please use Function.(Structures.)IsInverse instead."
41 #-}
42
43 ------------------------------------------------------------------------
44 -- The set of all inverses between two setoids
45
46 record Inverse {f₁ f₂ t₁ t₂}
47 (From : Setoid f₁ f₂) (To : Setoid t₁ t₂) :
48 Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where
49 field
50 to : From ⟶ To
51 from : To ⟶ From
52 inverse-of : from InverseOf to
53
54 open _InverseOf_ inverse-of public
55
56 left-inverse : LeftInverse From To
57 left-inverse = record
58 { to = to
59 ; from = from
60 ; left-inverse-of = left-inverse-of
61 }
62
63 open LeftInverse left-inverse public
64 using (injective; injection)
65
66 bijection : Bijection From To
67 bijection = record
68 { to = to
69 ; bijective = record
70 { injective = injective
71 ; surjective = record
72 { from = from
73 ; right-inverse-of = right-inverse-of
74 }
75 }
76 }
77
78 open Bijection bijection public
79 using (equivalence; surjective; surjection; right-inverse;
80 to-from; from-to)
81 {-# WARNING_ON_USAGE Inverse
82 "Warning: Inverse was deprecated in v2.0.
83 Please use Function.(Bundles.)Inverse instead."
84 #-}
85
86 ------------------------------------------------------------------------
87 -- The set of all inverses between two sets (i.e. inverses with
88 -- propositional equality)
89
90 infix 3 _↔_ _↔̇_
91
92 _↔_ : ∀ {f t} → Set f → Set t → Set _
93 From ↔ To = Inverse (≡.setoid From) (≡.setoid To)
94 {-# WARNING_ON_USAGE _↔_
95 "Warning: _↔_ was deprecated in v2.0.
96 Please use Function.(Bundles.)_↔_ instead."
97 #-}
98
99 _↔̇_ : ∀ {i f t} {I : Set i} → Pred I f → Pred I t → Set _
100 From ↔̇ To = ∀ {i} → From i ↔ To i
101 {-# WARNING_ON_USAGE _↔̇_
102 "Warning: _↔̇_ was deprecated in v2.0.
103 Please use Function.Indexed.(Bundles.)_↔ᵢ_ instead."
104 #-}
105
106 inverse : ∀ {f t} {From : Set f} {To : Set t} →
107 (to : From → To) (from : To → From) →
108 (∀ x → from (to x) ≡ x) →
109 (∀ x → to (from x) ≡ x) →
110 From ↔ To
111 inverse to from from∘to to∘from = record
112 { to = F.→-to-⟶ to
113 ; from = F.→-to-⟶ from
114 ; inverse-of = record
115 { left-inverse-of = from∘to
116 ; right-inverse-of = to∘from
117 }
118 }
119 {-# WARNING_ON_USAGE inverse
120 "Warning: inverse was deprecated in v2.0.
121 Please use Function.(Bundles.)mk↔ instead."
122 #-}
123
124 ------------------------------------------------------------------------
125 -- If two setoids are in bijective correspondence, then there is an
126 -- inverse between them
127
128 fromBijection :
129 ∀ {f₁ f₂ t₁ t₂} {From : Setoid f₁ f₂} {To : Setoid t₁ t₂} →
130 Bijection From To → Inverse From To
131 fromBijection b = record
132 { to = Bijection.to b
133 ; from = Bijection.from b
134 ; inverse-of = record
135 { left-inverse-of = Bijection.left-inverse-of b
136 ; right-inverse-of = Bijection.right-inverse-of b
137 }
138 }
139
140 ------------------------------------------------------------------------
141 -- Inverse is an equivalence relation
142
143 -- Reflexivity
144
145 id : ∀ {s₁ s₂} → Reflexive (Inverse {s₁} {s₂})
146 id {x = S} = record
147 { to = F.id
148 ; from = F.id
149 ; inverse-of = record
150 { left-inverse-of = LeftInverse.left-inverse-of id′
151 ; right-inverse-of = LeftInverse.left-inverse-of id′
152 }
153 } where id′ = Left.id {S = S}
154 {-# WARNING_ON_USAGE id
155 "Warning: id was deprecated in v2.0.
156 Please use either Function.Properties.Inverse.refl or
157 Function.Construct.Identity.inverse instead."
158 #-}
159
160 -- Transitivity
161
162 infixr 9 _∘_
163
164 _∘_ : ∀ {f₁ f₂ m₁ m₂ t₁ t₂} →
165 TransFlip (Inverse {f₁} {f₂} {m₁} {m₂})
166 (Inverse {m₁} {m₂} {t₁} {t₂})
167 (Inverse {f₁} {f₂} {t₁} {t₂})
168 f ∘ g = record
169 { to = to f ⟪∘⟫ to g
170 ; from = from g ⟪∘⟫ from f
171 ; inverse-of = record
172 { left-inverse-of = LeftInverse.left-inverse-of (Left._∘_ (left-inverse f) (left-inverse g))
173 ; right-inverse-of = LeftInverse.left-inverse-of (Left._∘_ (right-inverse g) (right-inverse f))
174 }
175 } where open Inverse
176 {-# WARNING_ON_USAGE _∘_
177 "Warning: _∘_ was deprecated in v2.0.
178 Please use either Function.Properties.Inverse.trans or
179 Function.Construct.Composition.inverse instead."
180 #-}
181
182 -- Symmetry.
183
184 sym : ∀ {f₁ f₂ t₁ t₂} →
185 Sym (Inverse {f₁} {f₂} {t₁} {t₂}) (Inverse {t₁} {t₂} {f₁} {f₂})
186 sym inv = record
187 { from = to
188 ; to = from
189 ; inverse-of = record
190 { left-inverse-of = right-inverse-of
191 ; right-inverse-of = left-inverse-of
192 }
193 } where open Inverse inv
194 {-# WARNING_ON_USAGE sym
195 "Warning: sym was deprecated in v2.0.
196 Please use either Function.Properties.Inverse.sym or
197 Function.Construct.Symmetry.inverse instead."
198 #-}
199
200 ------------------------------------------------------------------------
201 -- Transformations
202
203 map : ∀ {f₁ f₂ t₁ t₂} {From : Setoid f₁ f₂} {To : Setoid t₁ t₂}
204 {f₁′ f₂′ t₁′ t₂′}
205 {From′ : Setoid f₁′ f₂′} {To′ : Setoid t₁′ t₂′} →
206 (t : (From ⟶ To) → (From′ ⟶ To′)) →
207 (f : (To ⟶ From) → (To′ ⟶ From′)) →
208 (∀ {to from} → from InverseOf to → f from InverseOf t to) →
209 Inverse From To → Inverse From′ To′
210 map t f pres eq = record
211 { to = t to
212 ; from = f from
213 ; inverse-of = pres inverse-of
214 } where open Inverse eq
215
216 zip : ∀ {f₁₁ f₂₁ t₁₁ t₂₁}
217 {From₁ : Setoid f₁₁ f₂₁} {To₁ : Setoid t₁₁ t₂₁}
218 {f₁₂ f₂₂ t₁₂ t₂₂}
219 {From₂ : Setoid f₁₂ f₂₂} {To₂ : Setoid t₁₂ t₂₂}
220 {f₁ f₂ t₁ t₂} {From : Setoid f₁ f₂} {To : Setoid t₁ t₂} →
221 (t : (From₁ ⟶ To₁) → (From₂ ⟶ To₂) → (From ⟶ To)) →
222 (f : (To₁ ⟶ From₁) → (To₂ ⟶ From₂) → (To ⟶ From)) →
223 (∀ {to₁ from₁ to₂ from₂} →
224 from₁ InverseOf to₁ → from₂ InverseOf to₂ →
225 f from₁ from₂ InverseOf t to₁ to₂) →
226 Inverse From₁ To₁ → Inverse From₂ To₂ → Inverse From To
227 zip t f pres eq₁ eq₂ = record
228 { to = t (to eq₁) (to eq₂)
229 ; from = f (from eq₁) (from eq₂)
230 ; inverse-of = pres (inverse-of eq₁) (inverse-of eq₂)
231 } where open Inverse