-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsolutionsAndrejBauer.v
336 lines (247 loc) · 7.96 KB
/
solutionsAndrejBauer.v
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
From HoTT Require Import HoTT.
(* This file formalizes the exercises from the lectures "Introduction to HoTT". *)
Section Part_1_Martin_Lof_Type_Theory.
Section Exercise_1_1.
(* Construct an element of
(Π (x:A) . Σ (y:B) . C x y) → Σ (f : A → B) . Π (x : A) . C x (f x).
*)
Definition Exercise_1_1 (A : Type) (B : Type) (C : A -> B -> Type) :
(forall x, { y : B & C x y}) -> { f : A -> B & forall x, C x (f x) }
:= fun f => ( fun x => (f x).1 ; fun x => (f x).2 ).
End Exercise_1_1.
Section Exercise_1_2.
(* Use ind_ℕ to define double : ℕ → ℕ which doubles a number. *)
Definition double : nat -> nat :=
nat_rec _ O (fun _ k => S (S k)).
End Exercise_1_2.
Section Exercise_1_3.
(* Define halve : ℕ → ℕ which halves a number (rounded down). *)
Definition halve_helper : (nat -> nat * Bool)%type.
Proof.
intro n ; induction n as [|n [k b]].
- exact (O, true).
- exact ((if b then k else S k), negb b).
Defined.
Definition halve : nat -> nat := fst o halve_helper.
End Exercise_1_3.
End Part_1_Martin_Lof_Type_Theory.
Section Part_2_Identity_Types.
Section Exercise_2_1.
(* Construct a path between paths: p · idpath = p. *)
Theorem Exercise_2_1 (A : Type) (x y : A) (p : x = y) : p @ idpath y = p.
Proof.
induction p.
reflexivity.
Defined.
End Exercise_2_1.
Section Exercise_2_2.
(* Given a path p : x = y construct p⁻¹ : y = x and show that idpath⁻¹ = idpath. *)
Definition inv {A : Type} {x y : A} : x = y -> y = x.
Proof.
intro p ; induction p.
exact idpath.
Defined.
Definition inv' {A : Type} {x y : A} : x = y -> y = x.
Proof.
now intros [].
Defined.
Definition inv'' {A : Type} {x y : A} (p : x = y) : y = x :=
match p with
| idpath => idpath
end.
Definition inv_idpath {A : Type} {x : A} : inv (idpath x) = (idpath x).
Proof.
reflexivity.
Defined.
End Exercise_2_2.
Section Exercise_2_3.
(* Suppose
u, v : Σ (x : A) . B(x)
p : π₁ u = π₁ v
q : p . (π₂ u) = π₂ v
are given. Construct a path u = v. *)
Theorem squirrel {A : Type} {B : A -> Type} :
forall (x y : A) (p : x = y), forall (u : B x) (v : B y) (q : p # u = v), (x ; u) = (y ; v).
Proof.
intros x y p.
induction p.
intros u v q.
induction q.
reflexivity.
Defined.
Theorem Exercise_2_3
{A : Type} {B : A -> Type}
{u v : {x : A & B x}}
(p : u.1 = v.1)
(q : p # u.2 = v.2)
: u = v.
Proof.
transitivity (u.1 ; u.2).
- reflexivity.
- transitivity (v.1 ; v.2).
+ now srapply squirrel.
+ reflexivity.
Defined.
Theorem Exercise_2_3'
{A : Type} {B : A -> Type}
{u v : {x : A & B x}}
(p : u.1 = v.1)
(q : p # u.2 = v.2)
: u = v.
Proof.
now srapply path_sigma.
Defined.
End Exercise_2_3.
End Part_2_Identity_Types.
Section Part_3_Homotopy_Levels.
Section Exercise_3_1.
(* Construct a point if isContr A → Π (x y : A) . isContr (x = y) *)
Theorem Exercise_3_1 (A : Type) :
Contr A -> forall (x y : A), Contr (x = y).
Proof.
intros [a h] x y.
exists ((h x)^ @ (h y)).
intro p.
induction p.
apply concat_Vp.
Defined.
Theorem Exercise_3_1' (A : Type) :
Contr A -> forall (x y : A), Contr (x = y).
Proof.
apply @istrunc_succ.
Defined.
End Exercise_3_1.
Section Exercise_3_2.
(* Is contractibility a property or a structure? *)
Theorem Exercise_3_2 `{F : Funext} (A : Type) : IsHProp (Contr A).
Proof.
apply hprop_allpath.
intros [a h] [b g].
destruct (h b).
apply ap.
apply path_forall.
intro x.
srapply path_contr.
apply Exercise_3_1.
now exists a.
Defined.
Theorem Exercise_3_2' `{F : Funext} (A : Type) : IsHProp (Contr A).
Proof.
apply ishprop_istrunc.
Defined.
End Exercise_3_2.
Section Exercise_3_3.
(* Π (x : A) . isContr (Σ (y : A) . x = y *)
Theorem Exercise_3_3 (A : Type) :
forall (x : A), Contr ({ y : A & x = y}).
Proof.
intro x.
exists (x ; idpath).
intros [y p].
induction p.
reflexivity.
Defined.
End Exercise_3_3.
End Part_3_Homotopy_Levels.
Section Part_4_Equivalences.
Section Exercise_4_1.
(* (a) If P and Q are propostions then (P → Q) × (Q → P) → P ≃ Q *)
Variables P Q : HProp.
Context `{FE : Funext}.
Definition cow : (P -> Q) * (Q -> P) -> P <~> Q.
Proof.
intros [f g].
exists f.
apply isequiv_biinv.
split ; exists g ; intro x ; [ apply P | apply Q ].
Defined.
(* (b) The map above is an equivalence. *)
Definition moo : IsEquiv cow.
Proof.
apply isequiv_biinv.
split.
- now exists (fun (e : P <~> Q) => (equiv_fun e , e ^-1)).
- exists (fun (e : P <~> Q) => (equiv_fun e , e ^-1)).
intro e.
now apply @path_equiv.
Defined.
(* (c) If X and Y are sets then (X ≃ Y) ≃ (X ≅ Y). *)
(* The library does not seem to have an explicit definition of isIso,
so we include it here. *)
Definition isIso {A B} (f : A -> B) : Type :=
{ g : B -> A & (g o f == idmap) * (f o g == idmap) }%type.
Definition Iso X Y := {f : X -> Y & isIso f}.
Definition equiv2iso {A B} : Equiv A B -> Iso A B.
Proof.
intro e.
exists e, (e ^-1).
split.
- apply eissect.
- apply eisretr.
Defined.
Theorem rabbit (X Y : HSet) : Equiv X Y <~> Iso X Y.
Proof.
srapply equiv_adjointify.
- intro e.
exists e, (e ^-1).
split.
+ apply eissect.
+ apply eisretr.
- intros [f [g [gf_idmap fg_idmap]]].
exists f.
apply isequiv_biinv.
split ; now exists g.
- intros [f [g [gf_idmap fg_idmap]]].
srapply path_sigma ; try reflexivity.
srapply path_sigma ; try reflexivity.
srapply path_prod.
+ apply path_forall. intro. apply hset_path2.
+ apply path_forall. intro. apply hset_path2.
- intro e.
now apply path_equiv.
Defined.
End Exercise_4_1.
Section Exercise_4_2.
(* Use equivalence to express the fact that | |₋₁ : A → ∣|A||₋₁ is the
universal map from A to proposition. *)
(* Please formalize as follows:
Given a map q : A → Q, define a map e such that IsEquiv e expresses
the fact that q : A → Q is the propositional truncation of A.
*)
Definition isPropTruncation {A Q : Type} (q : A -> Q) :=
forall (P : HProp), IsEquiv (fun (f : Q -> P) => f o q).
End Exercise_4_2.
End Part_4_Equivalences.
Section Part_5_Univalence.
Section Exercise_5_1.
(* Show that the type of true propositions is contractible. *)
Context `{UA : Univalence}.
Theorem weasel : Contr { A : Type & IsHProp A * A }%type.
Proof.
srapply Build_Contr.
- exists Unit.
split.
+ apply istrunc_succ.
+ exact tt.
- intros [A [HA a]].
srapply path_sigma.
+ apply equiv_path_universe.
srapply symmetric_equiv.
srapply equiv_contr_unit.
now apply contr_inhabited_hprop.
+ apply path_prod ; apply path_ishprop.
Defined.
End Exercise_5_1.
Section Exercise_5_2.
(* Show that Σ (A : U) . isSet A is not a set. Hint: (2 ≃ 2) ≃ 2. *)
Definition two_equiv_two `{UA : Univalence} : Bool <~> (Bool = Bool).
Proof.
apply transitive_equiv with (y := (Bool <~> Bool)).
- apply equiv_bool_aut_bool.
- apply (equiv_path_universe Bool Bool).
Defined.
Lemma set_not_set : IsHSet { A : Type & IsHSet A } -> Empty.
Proof.
Admitted.
End Exercise_5_2.
End Part_5_Univalence.