-
Notifications
You must be signed in to change notification settings - Fork 21
/
set_level_mathematics_exercises.v
432 lines (351 loc) · 11.7 KB
/
set_level_mathematics_exercises.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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
(** Imports *)
Require Export UniMath.Foundations.Propositions.
Axiom fill_me : forall {X : UU}, X. (* Remove this line when you are finished. *)
(** * The type of sets i.e. of types of h-level 2 in [UU] *)
Definition hSet : UU := ∑ X : UU, isaset X.
Definition hSetpair (X : UU) (i : isaset X) := tpair isaset X i : hSet.
Definition pr1hSet : hSet -> UU := @pr1 UU (λ X : UU, isaset X).
Coercion pr1hSet: hSet >-> UU.
Definition setproperty (X : hSet) := pr2 X.
(** * Applications of Hedberg's theorem *)
(** Define a map from [bool] to [UU] that maps
[true] to [unit] (the one-element type) and
[false] to [empty] (the empty type).
*)
Definition bool_to_type : bool -> UU
:= bool_rect (λ _ : bool, UU) unit empty.
(** Show that there is no path from [true] to [false]. *)
Theorem no_path_from_true_to_false : true != false.
Proof.
apply fill_me.
Defined.
(** Show that there is no path from [false] to [true]. *)
Theorem no_path_from_false_to_true : false != true.
Proof.
apply fill_me.
Defined.
(** Construct decidable equality on [bool]. *)
Theorem isdeceqbool : isdeceq bool.
Proof.
unfold isdeceq. intros x' x. induction x.
- induction x'.
+ unfold decidable.
apply fill_me.
+ apply fill_me.
- induction x'.
+ apply fill_me.
+ apply fill_me.
Defined.
Check isasetifdeceq.
Theorem isaset_bool : isaset bool.
Proof.
apply fill_me.
Defined.
(** * [nat] is a set *)
(** Define a map from [nat] to [UU] that maps
[0] to the singleton type and
[S n] to the empty type for any [n].
*)
Definition nat_to_type : nat -> UU
:= nat_rect _ unit (fun _ _ => empty).
Lemma no_path_from_zero_to_successor (x : nat) : 0 != S x.
Proof.
apply fill_me.
Defined.
Lemma no_path_from_successor_to_zero (x : nat) : S x != 0.
Proof.
apply fill_me.
Defined.
(** Define a predecessor function on [nat]:
[0] is mapped to [0]
[S m] is mapped to [m]
*)
Definition predecessor : nat -> nat
:= nat_rect _ 0 (fun m (r : nat) => m).
Lemma invmaponpathsS (n m : nat) : S n = S m -> n = m.
Proof.
apply fill_me.
Defined.
(** The following constant will be useful for the next lemma. *)
Check @negf.
Lemma noeqinjS (x x' : nat) : x != x' -> S x != S x'.
Proof.
apply fill_me.
Defined.
Theorem isdeceqnat : isdeceq nat.
Proof.
apply fill_me.
Defined.
Lemma isasetnat : isaset nat.
Proof.
apply fill_me.
Defined.
(** * Functions in sets *)
Definition is_injective {X Y : hSet} (f : X -> Y) : UU
:= ∏ (x x': X), f x = f x' -> x = x'.
(* This is a useful lemma for checking that dependent function types are propositions or sets *)
Check impred.
Lemma isaprop_is_injective {X Y : hSet} (f : X -> Y)
: isaprop (is_injective f).
Proof.
apply fill_me.
Defined.
(** Question: does the above proof need both X and Y to be sets? *)
(** * The universe is not a set *)
(** The next result requires univalence *)
Require Import UniMath.Foundations.UnivalenceAxiom.
Module universe_is_not_a_set.
(* We will show that bool has a weak equivalence besides the identity. *)
Lemma isweq_negb : isweq negb.
Proof.
use gradth.
- exact negb.
- intro x. induction x; apply idpath.
- intro x; induction x; apply idpath.
Defined.
Definition weq_negb : bool ≃ bool := make_weq negb isweq_negb.
(* Show that negb is not equal to the identity.
It suffices, using toforallpaths, to show that they differ on some element. *)
Check toforallpaths.
Lemma no_path_weq_negb_idweq : weq_negb != idweq bool.
Proof.
apply fill_me.
Defined.
(* Using Univalence, we can show that if the universe were a set, then
negb would have to be equal to the identity. *)
Definition isaset_UU_gives_path_weq_negb_idweq
: isaset UU → weq_negb = idweq bool.
Proof.
intro H.
set (H':= H bool bool).
set (T:= invmaponpathsweq (invweq (make_weq _ (univalenceAxiom bool bool)))).
apply T.
apply H'.
Defined.
Definition not_isaset_UU : ¬ isaset UU.
Proof.
apply fill_me.
Defined.
End universe_is_not_a_set.
(** * Relations *)
(** ** Definitions *)
Definition hrel (X : UU) : UU := X -> X -> hProp.
Definition isrefl {X : UU} (R : hrel X) : UU
:= ∏ x : X, R x x.
Definition istrans {X : UU} (R : hrel X) : UU := fill_me.
Definition issymm {X : UU} (R : hrel X) : UU := fill_me.
Definition ispreorder {X : UU} (R : hrel X) : UU := istrans R × isrefl R.
Definition iseqrel {X : UU} (R : hrel X) : UU := ispreorder R × issymm R.
Definition iseqrelconstr {X : UU} {R : hrel X}
(trans0 : istrans R)
(refl0 : isrefl R)
(symm0 : issymm R)
: iseqrel R
:= make_dirprod (make_dirprod trans0 refl0) symm0.
(** ** Eqivalence relations *)
Definition eqrel (X : UU) : UU
:= ∑ R : hrel X, iseqrel R.
Definition eqrelpair {X : UU} (R : hrel X) (is : iseqrel R)
: eqrel X
:= tpair (λ R : hrel X, iseqrel R) R is.
Definition eqrelconstr {X : UU} (R : hrel X)
(is1 : istrans R) (is2 : isrefl R) (is3 : issymm R) : eqrel X
:= eqrelpair R (make_dirprod (make_dirprod is1 is2) is3).
Definition pr1eqrel (X : UU) : eqrel X -> (X -> (X -> hProp)) := @pr1 _ _.
Coercion pr1eqrel : eqrel >-> Funclass.
Definition eqreltrans {X : UU} (R : eqrel X) : istrans R := pr1 (pr1 (pr2 R)).
Definition eqrelrefl {X : UU} (R : eqrel X) : isrefl R := pr2 (pr1 (pr2 R)).
Definition eqrelsymm {X : UU} (R : eqrel X) : issymm R := pr2 (pr2 R).
(** * The type of subtypes of a given type *)
Definition hsubtype (X : UU) : UU := X -> hProp.
(** The carrier of a subtype *)
Definition carrier {X : UU} (A : hsubtype X) : UU := ∑ x : X, A x.
Check isasethProp.
Check (impred 2).
Lemma isasethsubtype (X : UU) : isaset (hsubtype X).
Proof.
apply fill_me.
Defined.
(** ** A subtype with paths between any two elements is an [hProp]. *)
Lemma isapropsubtype {X : UU} (A : hsubtype X)
(is : ∏ (x1 x2 : X), A x1 -> A x2 -> x1 = x2)
: isaprop (carrier A).
Proof.
apply invproofirrelevance.
intros x x'.
assert (X0 : isincl (@pr1 _ A)).
{
apply isinclpr1.
intro x0.
apply (pr2 (A x0)).
}
apply (invmaponpathsincl (@pr1 _ A) X0).
induction x as [ x0 is0 ].
induction x' as [ x0' is0' ].
simpl.
apply (is x0 x0' is0 is0').
Defined.
(** ** Equivalence classes with respect to a given relation *)
Definition iseqclass {X : UU} (R : hrel X) (A : hsubtype X) : UU
:=
∥ carrier A ∥ (* is non-empty *)
×
((∏ x1 x2 : X, R x1 x2 -> A x1 -> A x2)
×
(∏ x1 x2 : X, A x1 -> A x2 -> R x1 x2)).
Definition iseqclassconstr {X : UU} (R : hrel X) {A : hsubtype X}
(ax0 : ishinh (carrier A))
(ax1 : ∏ x1 x2 : X, R x1 x2 -> A x1 -> A x2)
(ax2 : ∏ x1 x2 : X, A x1 -> A x2 -> R x1 x2)
: iseqclass R A
:= make_dirprod ax0 (make_dirprod ax1 ax2).
Definition eqax0 {X : UU} {R : hrel X} {A : hsubtype X}
: iseqclass R A -> ishinh (carrier A)
:= λ is : iseqclass R A, pr1 is.
Definition eqax1 {X : UU} {R : hrel X} {A : hsubtype X}
: iseqclass R A -> ∏ x1 x2 : X, R x1 x2 -> A x1 -> A x2
:= λ is : iseqclass R A, pr1 (pr2 is).
Definition eqax2 {X : UU} {R : hrel X} {A : hsubtype X}
: iseqclass R A -> ∏ x1 x2 : X, A x1 -> A x2 -> R x1 x2
:= λ is : iseqclass R A, pr2 (pr2 is).
Lemma isapropiseqclass {X : UU} (R : hrel X) (A : hsubtype X)
: isaprop (iseqclass R A).
Proof.
apply isofhleveldirprod.
- apply propproperty.
- apply fill_me.
Defined.
(** ** Setquotient defined in terms of equivalence classes *)
Definition setquot {X : UU} (R : hrel X) : UU
:= ∑ A : hsubtype X, iseqclass R A.
Definition setquotpair {X : UU} (R : hrel X) (A : hsubtype X)
(is : iseqclass R A)
: setquot R
:= A ,, is.
Definition pr1setquot {X : UU} (R : hrel X)
: setquot R -> hsubtype X
:= @pr1 _ (λ A : _, iseqclass R A).
Coercion pr1setquot : setquot >-> hsubtype.
Lemma isinclpr1setquot {X : UU} (R : hrel X) : isincl (pr1setquot R).
Proof.
apply isinclpr1.
intro x0.
apply isapropiseqclass.
Defined.
Definition setquottouu0 {X : UU} (R : hrel X) (a : setquot R)
:= carrier (pr1 a).
Coercion setquottouu0 : setquot >-> UU.
Theorem isasetsetquot {X : UU} (R : hrel X) : isaset (setquot R).
Proof.
apply (isasetsubset (@pr1 _ _) (isasethsubtype X)).
apply isinclpr1setquot.
Defined.
Theorem setquotpr {X : UU} (R : eqrel X) : X -> setquot R.
Proof.
intro x.
set (rax := eqrelrefl R).
set (sax := eqrelsymm R).
set (tax := eqreltrans R).
apply (tpair _ (λ x0 : X, R x x0)).
split.
- exact (hinhpr (tpair _ x (rax x))).
- split; intros x1 x2 X1 X2.
+ exact fill_me.
+ exact fill_me.
Defined.
Lemma setquotl0 {X : UU} (R : eqrel X) (c : setquot R) (x : c) :
setquotpr R (pr1 x) = c.
Proof.
Set Printing Coercions.
apply (invmaponpathsincl _ (isinclpr1setquot R)).
Unset Printing Coercions.
apply funextsec; intro x0.
apply hPropUnivalence; intro r.
- exact fill_me.
- exact fill_me.
Defined.
Theorem issurjsetquotpr {X : UU} (R : eqrel X) : issurjective (setquotpr R).
Proof.
unfold issurjective.
intro c. apply (@hinhuniv (carrier c)).
- intro x. apply hinhpr.
use tpair.
+ exact (pr1 x).
+ apply setquotl0.
- apply (eqax0 (pr2 c)).
Defined.
Lemma iscompsetquotpr {X : UU} (R : eqrel X) (x x' : X)
: R x x' -> setquotpr R x = setquotpr R x'.
Proof.
intro r.
Set Printing Coercions.
apply (invmaponpathsincl _ (isinclpr1setquot R)).
Unset Printing Coercions.
simpl. apply funextsec.
intro x0. apply hPropUnivalence.
- intro r0. exact fill_me.
- intro x0'. exact fill_me.
Defined.
(** *** Universal property of [seqtquot R] for functions to sets satisfying compatibility condition [iscomprelfun] *)
Definition iscomprelfun {X Y : UU} (R : hrel X) (f : X -> Y) : UU
:= ∏ x x' : X, R x x' -> f x = f x'.
Lemma isapropimeqclass {X : UU} (R : hrel X) (Y : hSet) (f : X -> Y)
(is : iscomprelfun R f) (c : setquot R) :
isaprop (image (λ x : c, f (pr1 x))).
Proof.
apply isapropsubtype.
intros y1 y2. simpl.
apply (@hinhuniv2 _ _ (make_hProp (y1 = y2) (pr2 Y y1 y2))).
intros x1 x2. simpl.
destruct c as [ A iseq ].
destruct x1 as [ x1 is1 ]. destruct x2 as [ x2 is2 ].
destruct x1 as [ x1 is1' ]. destruct x2 as [ x2 is2' ].
simpl in is1. simpl in is2. simpl in is1'. simpl in is2'.
assert (r : R x1 x2) by apply (eqax2 iseq _ _ is1' is2').
apply ( !is1 @ (is _ _ r) @ is2).
Defined.
Definition setquotuniv {X : UU} (R : hrel X) (Y : hSet) (f : X -> Y)
(is : iscomprelfun R f) (c : setquot R) : Y.
Proof.
apply (pr1image (λ x : c, f (pr1 x))).
apply (@squash_to_prop (carrier c)).
- apply (eqax0 (pr2 c)).
- apply isapropimeqclass. apply is.
- unfold carrier. apply prtoimage.
Defined.
(** Note : the axioms rax, sax and trans are not used in the proof of
setquotuniv. If we consider a relation which is not an equivalence relation
then setquot will still be the set of subsets which are equivalence classes.
Now however such subsets need not to cover all of the type. In fact their set
can be empty. Nevertheless setquotuniv will apply. *)
Theorem setquotunivcomm {X : UU} (R : eqrel X) (Y : hSet) (f : X -> Y)
(is : iscomprelfun R f) :
∏ x : X, setquotuniv R Y f is (setquotpr R x) = f x.
Proof.
intros.
apply idpath.
Defined.
Lemma setquotpr_eq_eqrel {X : UU} (R : eqrel X) (x x' : X)
: setquotpr R x = setquotpr R x' → R x x'.
Proof.
intro e.
set (e' := maponpaths (pr1setquot R) e). simpl in e'.
set (e'' := maponpaths (λ f : _, f x') e'). simpl in e''.
rewrite e''.
apply eqrelrefl.
Defined.
Theorem weqpathsinsetquot {X : UU} (R : eqrel X) (x x' : X) :
R x x' ≃ setquotpr R x = setquotpr R x'.
Proof.
intros.
exists (iscompsetquotpr R x x').
apply isweqimplimpl.
- intro e.
set (e' := maponpaths (pr1setquot R) e). simpl in e'.
set (e'' := maponpaths (λ f : _, f x') e'). simpl in e''.
rewrite e''.
apply eqrelrefl.
- apply propproperty.
- apply isasetsetquot.
Defined.
(* End of file *)