-
Notifications
You must be signed in to change notification settings - Fork 21
/
set_level_mathematics_solutions.v
603 lines (481 loc) · 16.3 KB
/
set_level_mathematics_solutions.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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
(** Imports *)
Require Import UniMath.Foundations.All.
Require Import UniMath.MoreFoundations.All.
Require Import UniMath.Algebra.BinaryOperations.
Require Import UniMath.Algebra.Monoids.
(** * 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.
intro X. apply (transportf bool_to_type X tt).
Defined.
(** Show that there is no path from [false] to [true]. *)
Theorem no_path_from_false_to_true : false != true.
Proof.
intro X. apply (transportb bool_to_type X tt).
Defined.
(** Construct decidable equality on [bool]. *)
Theorem isdeceqbool : isdeceq bool.
Proof.
unfold isdeceq. intros x' x. induction x.
- induction x'.
+ unfold decidable.
apply ii1.
apply idpath.
+ apply ii2.
exact no_path_from_false_to_true.
- induction x'.
+ apply ii2.
exact no_path_from_true_to_false.
+ apply ii1.
apply idpath.
Defined.
Check isasetifdeceq.
Theorem isaset_bool : isaset bool.
Proof.
apply isasetifdeceq.
apply isdeceqbool.
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.
intro F.
exact (transportf nat_to_type F tt).
Defined.
Lemma no_path_from_successor_to_zero (x : nat) : S x != 0.
Proof.
intro X. apply (no_path_from_zero_to_successor x (pathsinv0 X)).
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.
intro e.
apply (maponpaths predecessor e).
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 (negf (invmaponpathsS x x')).
Defined.
Theorem isdeceqnat : isdeceq nat.
Proof.
intros m.
induction m as [ | m].
- intro n.
induction n as [ | n].
+ apply ii1. apply idpath.
+ apply ii2. apply no_path_from_zero_to_successor.
- intro n.
induction n as [ | n].
+ apply ii2. apply no_path_from_successor_to_zero.
+ set (IHm_n := IHm n).
induction IHm_n as [eq_m_n | not_eq_m_n ].
* apply ii1. apply (maponpaths S eq_m_n).
* apply ii2. apply noeqinjS. apply not_eq_m_n.
Defined.
Lemma isasetnat : isaset nat.
Proof.
apply isasetifdeceq.
apply isdeceqnat.
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.
unfold is_injective.
apply impred. intro x.
apply impred. intro y.
apply impred. intro e.
apply setproperty.
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 isweq_iso.
- 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.
intro H.
set (H':= toforallpaths _ _ _ (maponpaths pr1 H) true).
cbn in H'.
exact (no_path_from_false_to_true H').
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.
exact (funcomp isaset_UU_gives_path_weq_negb_idweq no_path_weq_negb_idweq).
Defined.
End universe_is_not_a_set.
Section Pointed.
Definition ptdset : UU := ∑ A : hSet, A.
Coercion ptdset_to_set (X : ptdset) : hSet := pr1 X.
Definition ptd (X : ptdset) : X := pr2 X.
Definition ptdset_iso (X Y : ptdset) : UU := ∑ f : X ≃ Y, f (ptd X) = ptd Y.
Definition id_weq (X Y : ptdset) : (X = Y) ≃ (X ╝ Y).
Proof.
apply total2_paths_equiv.
Defined.
Definition ptdset_iso_weq (X Y : ptdset) : (X ╝ Y) ≃ (ptdset_iso X Y).
Proof.
use weqtotal2.
+ Search ( (_ = _) ≃ ( _ ≃ _)).
use hSet_univalence.
+ intro p.
induction X as [X x].
induction Y as [Y y].
cbn in p.
induction p. cbn.
apply idweq.
Defined.
Definition sip_for_ptdset : ∏ (X Y : ptdset), (X = Y) ≃ ptdset_iso X Y.
Proof.
intros X Y.
eapply weqcomp.
- apply id_weq.
- apply ptdset_iso_weq.
Defined.
Definition transportf_ptdset :
∏ (P : ptdset → UU) (X Y : ptdset), ptdset_iso X Y → P X → P Y.
Proof.
intros P X Y f.
apply sip_for_ptdset in f.
exact (transportf P f).
Defined.
End Pointed.
Section Monoid.
(* see Algebra/Monoids2.v, monoid_univalence *)
Local Open Scope multmonoid.
Notation "x * y" := (op x y) : multmonoid.
Notation "1" := (unel _) : multmonoid.
Search monoid.
(*
Construct the following chain of equivalences
(X = Y) ≃ (X ╝ Y)
≃ (monoidiso' X Y)
≃ (monoidiso X Y).
*)
Definition monoidiso' (X Y : monoid) : UU :=
∑ g : (∑ f : X ≃ Y, isbinopfun f), (pr1 g) 1 = 1.
Definition monoid_univalence_weq1 (X Y : monoid) : (X = Y) ≃ (X ╝ Y) :=
total2_paths_equiv _ X Y.
Definition monoid_univalence_weq2 (X Y : monoid) : (X ╝ Y) ≃ (monoidiso' X Y).
Proof.
use weqbandf.
- exact (setwithbinop_univalence X Y).
- intros e. cbn. use invweq. induction X as [X Xop]. induction Y as [Y Yop]. cbn in e.
cbn. induction e. use weqimplimpl.
+ intros i. use proofirrelevance. use isapropismonoidop.
+ intros i. induction i. use idpath.
+ use setproperty.
+ use isapropifcontr. exact (@isapropismonoidop X (pr2 X) Xop Yop).
Defined.
Opaque monoid_univalence_weq2.
Definition monoid_univalence_weq3 (X Y : monoid) : (monoidiso' X Y) ≃ (monoidiso X Y) :=
weqtotal2asstor (λ w : X ≃ Y, isbinopfun w)
(λ y : (∑ w : weq X Y, isbinopfun w), (pr1 y) 1 = 1).
Definition monoid_univalence_map (X Y : monoid) : X = Y → monoidiso X Y.
Proof.
intro e. induction e. exact (idmonoidiso X).
Defined.
Lemma monoid_univalence_isweq (X Y : monoid) :
isweq (monoid_univalence_map X Y).
Proof.
use isweqhomot.
- exact (weqcomp (monoid_univalence_weq1 X Y)
(weqcomp (monoid_univalence_weq2 X Y) (monoid_univalence_weq3 X Y))).
- intros e. induction e.
refine (weqcomp_to_funcomp_app @ _).
use weqcomp_to_funcomp_app.
- use weqproperty.
Defined.
Definition monoid_univalence (X Y : monoid) : (X = Y) ≃ (monoidiso X Y)
:= make_weq
(monoid_univalence_map X Y)
(monoid_univalence_isweq X Y).
End Monoid.
(** * Relations *)
(** ** Definitions *)
Definition hrel (X : UU) : UU := X -> X -> hProp.
Definition istrans {X : UU} (R : hrel X) : UU
:= ∏ (x1 x2 x3 : X), R x1 x2 -> R x2 x3 -> R x1 x3.
Definition isrefl {X : UU} (R : hrel X) : UU
:= ∏ x : X, R x x.
Definition issymm {X : UU} (R : hrel X) : UU
:= ∏ (x1 x2 : X), R x1 x2 -> R x2 x1.
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 (impred 2).
intro x.
exact isasethProp.
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 isofhleveldirprod.
+ apply impred.
intro x.
apply impred.
intro x'.
apply impred.
intro r.
apply impred.
intro a.
apply propproperty.
+ repeat (apply impred; intro).
exact (pr2 (R t t0)).
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 (tax x x1 x2 X2 X1).
+ exact (tax x1 x x2 (sax x x1 X1) X2).
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 (eqax1 (pr2 c) (pr1 x) x0 r (pr2 x)).
- exact (eqax2 (pr2 c) (pr1 x) x0 (pr2 x) r).
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. apply (eqreltrans R _ _ _ (eqrelsymm R _ _ r) r0).
- intro x0'. apply (eqreltrans R _ _ _ r x0').
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 *)