/
contractible-types.lagda.md
314 lines (257 loc) · 9.32 KB
/
contractible-types.lagda.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# Contractible types
```agda
module foundation-core.contractible-types where
```
<details><summary>Imports</summary>
```agda
open import foundation.action-on-identifications-functions
open import foundation.dependent-pair-types
open import foundation.equality-cartesian-product-types
open import foundation.function-extensionality
open import foundation.implicit-function-types
open import foundation.universe-levels
open import foundation-core.cartesian-product-types
open import foundation-core.equality-dependent-pair-types
open import foundation-core.equivalences
open import foundation-core.homotopies
open import foundation-core.identity-types
open import foundation-core.retracts-of-types
open import foundation-core.transport-along-identifications
```
</details>
## Idea
Contractible types are types that have, up to identification, exactly one
element.
## Definition
```agda
is-contr :
{l : Level} → UU l → UU l
is-contr A = Σ A (λ a → (x : A) → a = x)
abstract
center :
{l : Level} {A : UU l} → is-contr A → A
center (pair c is-contr-A) = c
eq-is-contr' :
{l : Level} {A : UU l} → is-contr A → (x y : A) → x = y
eq-is-contr' (pair c C) x y = (inv (C x)) ∙ (C y)
eq-is-contr :
{l : Level} {A : UU l} → is-contr A → {x y : A} → x = y
eq-is-contr C {x} {y} = eq-is-contr' C x y
abstract
contraction :
{l : Level} {A : UU l} (is-contr-A : is-contr A) →
(x : A) → (center is-contr-A) = x
contraction C x = eq-is-contr C
coh-contraction :
{l : Level} {A : UU l} (is-contr-A : is-contr A) →
(contraction is-contr-A (center is-contr-A)) = refl
coh-contraction (pair c C) = left-inv (C c)
```
## Properties
### Retracts of contractible types are contractible
```agda
module _
{l1 l2 : Level} {A : UU l1} (B : UU l2)
where
abstract
is-contr-retract-of : A retract-of B → is-contr B → is-contr A
pr1 (is-contr-retract-of (pair i (pair r is-retraction-r)) H) = r (center H)
pr2 (is-contr-retract-of (pair i (pair r is-retraction-r)) H) x =
ap r (contraction H (i x)) ∙ (is-retraction-r x)
```
### Contractible types are closed under equivalences
```agda
module _
{l1 l2 : Level} {A : UU l1} (B : UU l2)
where
abstract
is-contr-is-equiv :
(f : A → B) → is-equiv f → is-contr B → is-contr A
is-contr-is-equiv f is-equiv-f =
is-contr-retract-of B (f , retraction-is-equiv is-equiv-f)
abstract
is-contr-equiv : (e : A ≃ B) → is-contr B → is-contr A
is-contr-equiv (pair e is-equiv-e) is-contr-B =
is-contr-is-equiv e is-equiv-e is-contr-B
module _
{l1 l2 : Level} (A : UU l1) {B : UU l2}
where
abstract
is-contr-is-equiv' :
(f : A → B) → is-equiv f → is-contr A → is-contr B
is-contr-is-equiv' f is-equiv-f is-contr-A =
is-contr-is-equiv A
( map-inv-is-equiv is-equiv-f)
( is-equiv-map-inv-is-equiv is-equiv-f)
( is-contr-A)
abstract
is-contr-equiv' : (e : A ≃ B) → is-contr A → is-contr B
is-contr-equiv' (pair e is-equiv-e) is-contr-A =
is-contr-is-equiv' e is-equiv-e is-contr-A
module _
{l1 l2 : Level} {A : UU l1} {B : UU l2}
where
abstract
is-equiv-is-contr :
(f : A → B) → is-contr A → is-contr B → is-equiv f
is-equiv-is-contr f is-contr-A is-contr-B =
is-equiv-is-invertible
( λ y → center is-contr-A)
( λ y → eq-is-contr is-contr-B)
( contraction is-contr-A)
equiv-is-contr : is-contr A → is-contr B → A ≃ B
pr1 (equiv-is-contr is-contr-A is-contr-B) a = center is-contr-B
pr2 (equiv-is-contr is-contr-A is-contr-B) =
is-equiv-is-contr _ is-contr-A is-contr-B
```
### Contractibility of cartesian product types
Given two types `A` and `B`, the following are equivalent:
1. The type `A × B` is contractible.
2. Both `A` and `B` are contractible.
```agda
module _
{l1 l2 : Level} (A : UU l1) (B : UU l2)
where
abstract
is-contr-left-factor-product : is-contr (A × B) → is-contr A
is-contr-left-factor-product is-contr-AB =
is-contr-retract-of
( A × B)
( pair
( λ x → pair x (pr2 (center is-contr-AB)))
( pair pr1 refl-htpy))
( is-contr-AB)
module _
{l1 l2 : Level} (A : UU l1) (B : UU l2)
where
abstract
is-contr-right-factor-product : is-contr (A × B) → is-contr B
is-contr-right-factor-product is-contr-AB =
is-contr-retract-of
( A × B)
( pair
( pair (pr1 (center is-contr-AB)))
( pair pr2 refl-htpy))
( is-contr-AB)
module _
{l1 l2 : Level} {A : UU l1} {B : UU l2}
where
abstract
is-contr-product : is-contr A → is-contr B → is-contr (A × B)
pr1 (pr1 (is-contr-product (pair a C) (pair b D))) = a
pr2 (pr1 (is-contr-product (pair a C) (pair b D))) = b
pr2 (is-contr-product (pair a C) (pair b D)) (pair x y) =
eq-pair (C x) (D y)
```
### Contractibility of Σ-types
```agda
module _
{l1 l2 : Level} {A : UU l1} {B : A → UU l2}
where
abstract
is-contr-Σ' :
is-contr A → ((x : A) → is-contr (B x)) → is-contr (Σ A B)
pr1 (pr1 (is-contr-Σ' (pair a H) is-contr-B)) = a
pr2 (pr1 (is-contr-Σ' (pair a H) is-contr-B)) = center (is-contr-B a)
pr2 (is-contr-Σ' (pair a H) is-contr-B) (pair x y) =
eq-pair-Σ
( inv (inv (H x)))
( eq-transpose-tr (inv (H x)) (eq-is-contr (is-contr-B a)))
abstract
is-contr-Σ :
is-contr A → (a : A) → is-contr (B a) → is-contr (Σ A B)
pr1 (pr1 (is-contr-Σ H a K)) = a
pr2 (pr1 (is-contr-Σ H a K)) = center K
pr2 (is-contr-Σ H a K) (pair x y) =
eq-pair-Σ
( inv (eq-is-contr H))
( eq-transpose-tr (eq-is-contr H) (eq-is-contr K))
```
**Note**: In the previous construction, we showed that `Σ A B` is contractible
whenever `A` is contractible and whenever `B a` is contractible for a specified
term `a : A`. We _could_ have chosen this term `a` to be the center of
contraction of `A`. However, it turns out to be better not to do so in the
construction of `is-contr-Σ`. The reason is that proofs of contractibility could
be quite complicated and difficult to normalize. If we would require in the
definition of `is-contr-Σ` that `B (center c)` is contractible, given the proof
`c` of contractibility of `A`, then the type inference algorithm of Agda will be
forced to normalize the proof `c` including the contraction. By instead
providing a center of contraction by hand, we avoid this unnecessary load on the
type inference algorithm, and hence any instance of `is-contr-Σ` will type check
more efficiently.
The general theme is that it may be computationally expensive to extract
information from proofs of propositions, such as the center of contraction of a
proof of contractibility. The reason for that is that when Agda normalizes an
element (as it inevitably will do sometimes) then in such cases it will not just
normalize the extracted information (in this case the first projection of the
proof of contractibility), but it will normalize the entire proof of
contractibility first, and then apply the projection.
### Contractible types are propositions
```agda
is-prop-is-contr :
{l : Level} {A : UU l} → is-contr A → (x y : A) → is-contr (x = y)
pr1 (is-prop-is-contr H x y) = eq-is-contr H
pr2 (is-prop-is-contr H x .x) refl = left-inv (pr2 H x)
```
### Products of families of contractible types are contractible
```agda
abstract
is-contr-Π :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} →
((x : A) → is-contr (B x)) → is-contr ((x : A) → B x)
pr1 (is-contr-Π {A = A} {B = B} H) x = center (H x)
pr2 (is-contr-Π {A = A} {B = B} H) f =
map-inv-is-equiv
( funext (λ x → center (H x)) f)
( λ x → contraction (H x) (f x))
abstract
is-contr-implicit-Π :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} →
((x : A) → is-contr (B x)) → is-contr ({x : A} → B x)
is-contr-implicit-Π H =
is-contr-equiv _ equiv-explicit-implicit-Π (is-contr-Π H)
```
### The type of functions into a contractible type is contractible
```agda
is-contr-function-type :
{l1 l2 : Level} {A : UU l1} {B : UU l2} →
is-contr B → is-contr (A → B)
is-contr-function-type is-contr-B = is-contr-Π (λ _ → is-contr-B)
```
### The type of equivalences between contractible types is contractible
```agda
module _
{l1 l2 : Level} {A : UU l1} {B : UU l2}
where
is-contr-equiv-is-contr :
is-contr A → is-contr B → is-contr (A ≃ B)
is-contr-equiv-is-contr (pair a α) (pair b β) =
is-contr-Σ
( is-contr-function-type (pair b β))
( λ x → b)
( is-contr-product
( is-contr-Σ
( is-contr-function-type (pair a α))
( λ y → a)
( is-contr-Π (is-prop-is-contr (pair b β) b)))
( is-contr-Σ
( is-contr-function-type (pair a α))
( λ y → a)
( is-contr-Π (is-prop-is-contr (pair a α) a))))
```
### Being contractible is a proposition
```agda
module _
{l : Level} {A : UU l}
where
abstract
is-contr-is-contr : is-contr A → is-contr (is-contr A)
is-contr-is-contr (pair a α) =
is-contr-Σ
( pair a α)
( a)
( is-contr-Π (is-prop-is-contr (pair a α) a))
abstract
is-property-is-contr : (H K : is-contr A) → is-contr (H = K)
is-property-is-contr H = is-prop-is-contr (is-contr-is-contr H) H
```