-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcoq_dissertation.v
3785 lines (3118 loc) · 124 KB
/
coq_dissertation.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
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*********************************************
Author: Jesús Héctor Domínguez Sánchez
June 2016
IMPORTANT: READ FILE "README.md" FIRST!!!!
This script is intended to be read side by side with the report.
This is why the author decided to place all results in one big script
file instead of splitting the script into modules. Of course, there are
small differences on how the results on the report are implemented
on this script, but the author hopes those differences are sufficiently
minimal so that a reader can still follow the script and the report
without trouble.
Modularity, reusability, or proof automation is not a concern here, as
this script is intended to be read by a person that is following the
report. This is the reason of why the author tried to use one
tactic per line inside proofs (and no automatic tactics, unless it is
obvious by computation) so that each step in the proof can clearly be seen
during execution of the script.
Of course, the author assumes the reader is already familiar with Coq.
*********************************************)
Require Import HoTT.
(*********************************
Chapter 1: Homotopy Type Theory
*********************************)
(* This part of the script includes results that are not directly available in the
HoTT library, so we need to prove them to be able to formalize Chapters 2 and 3
later.
I provide a quick reference of concepts available in the library.
Coq syntax Meaning
Empty Empty type
------------------------------------------------------------------------------
Unit Unit type
------------------------------------------------------------------------------
A * B Product type
------------------------------------------------------------------------------
A + B Sum type
------------------------------------------------------------------------------
A -> B Non-dependent function type
------------------------------------------------------------------------------
forall x: A, P x Dependent function type
Alternative syntax
for multiple inputs:
forall (x: A) (y: B), P x y
------------------------------------------------------------------------------
{x: A & P x} Depedent pair type
Alternative syntax:
{x: A | P x}
or:
exists x: A, P x
or for nested sigmas:
exists (x: A) (y: B), P x y
------------------------------------------------------------------------------
Type Universe at some level. Coq assigns
automatically the universe level.
------------------------------------------------------------------------------
Type@{i} Universe at level i. Here, i is a variable.
Coq does not allow explicit assignment of
levels (it is Coq the one that assigns the
levels), but we can at least refer to the
level assigned by Coq by using universe
variables like i.
------------------------------------------------------------------------------
a = b Identity type
Alternative syntax:
paths a b
------------------------------------------------------------------------------
nat Natural number type
------------------------------------------------------------------------------
f == g Pointwise identifiable functions.
(See Definition 1.6.7)
This is an abbreviation for type:
forall x: A, f x = g x
------------------------------------------------------------------------------
IsEquiv e e is an equivalence.
(See Definition 1.6.10)
The library uses the "half-adjoint"
definition of equivalence instead of the
"bi-invertible" map the author used in
the report. These two definitions are
equivalent (see Chapter 4 in the HoTT book)
------------------------------------------------------------------------------
A <~> B Equivalent types.
(See Definition 1.6.17)
This is an abbreviation for type:
{f: A -> B & IsEquiv f}, although the
library uses a record to represent the
sigma.
------------------------------------------------------------------------------
A <-> B Logical equivalence.
(See Definition 1.8.7)
This is an abbreviation for type:
(A -> B) * (B -> A)
------------------------------------------------------------------------------
~A Not.
This is an abbreviation for type:
A -> Empty
------------------------------------------------------------------------------
tt The unique term in Unit (the "star" term)
------------------------------------------------------------------------------
(a, b) Non-dependent pair
Coq treats differently sigma types and
product types, while in the report
product types are a special case of a sigma.
This is just a technicality, since one can
easily prove that types
{_: A & B} and A * B are equivalent.
------------------------------------------------------------------------------
(a ; b) Dependent pair
See note on the previous item.
------------------------------------------------------------------------------
fst p Projection functions for the product type
snd p
------------------------------------------------------------------------------
pr1 p Projection fuctions for the dependent pair
type
pr2 p
Alternative syntax:
p.1
p.2
------------------------------------------------------------------------------
inl a Injection functions for the sum type
inr b
------------------------------------------------------------------------------
fun x: A => g x Function (lambda term)
Alternative syntax for
multiple inputs:
fun (x: A) (y: B) => g x y
------------------------------------------------------------------------------
idpath Trivial proof of identity (trivial loop)
Alternative syntax:
1
------------------------------------------------------------------------------
p^ Symmetry operator
(See Lemma 1.5.59)
------------------------------------------------------------------------------
p @ q Transitivity operator
(See Lemma 1.5.60)
------------------------------------------------------------------------------
transport P q a Transport operator
(See Lemma 1.5.61)
Alternative syntax when
P is automatically inferred:
q # a
------------------------------------------------------------------------------
ap f p Application operator
(Lemma 1.5.62)
------------------------------------------------------------------------------
apD f p Dependent application operator
(Lemma 1.5.63)
------------------------------------------------------------------------------
e^-1 Inverse of equivalence e
(See Definition 1.6.12)
It can be applied when type "IsEquiv e" is
inhabited.
The notation can also be used on terms
e: A <~> B
------------------------------------------------------------------------------
f o g Function composition
(See Definition 1.5.13)
------------------------------------------------------------------------------
idmap Identity function
------------------------------------------------------------------------------
0 The natural number zero
Alternative syntax:
O (capital letter o)
------------------------------------------------------------------------------
S n Succesor of natural number n
Alternative syntax:
n.+1
------------------------------------------------------------------------------
hProp Universe of propositions
(See Definition 1.8.4)
Syntax with universe level
variable:
hProp@{i}
------------------------------------------------------------------------------
IsHProp A A is a proposition
(See Definition 1.8.4)
------------------------------------------------------------------------------
hSet Universe of sets
(See Definition 1.8.9)
Syntax with universe level
variable:
hSet@{i}
------------------------------------------------------------------------------
IsHSet A A is a set
(See Definition 1.8.9)
------------------------------------------------------------------------------
Contr A A is contractible
(See Definition 1.8.1)
*)
(*------ Section 1.6 ------- *)
(* Lemma 1.6.23
Here, "functor_sigma" is the Sigma_map function of
Lemma 1.5.28 *)
Lemma sigmas_assoc {A: Type} (P: A -> Type) (Q: {w: A & P w} -> Type) :
let T := fun w: A => {y: P w & Q (w ; y)} in
exists (m: forall y: {w: A & P w}, Q y -> T y.1),
IsEquiv (functor_sigma pr1 m).
Proof.
intro T.
transparent assert (m: (forall y: {w: A & P w}, Q y -> T y.1)).
(* Lemma 1.5.24 *)
refine (sig_ind _ _ _ _).
intros w y q.
exact (y ; q).
exists m.
transparent assert (inv: ({w: A & T w} -> {q: {w: A & P w} & Q q})).
refine (sig_ind _ _ _ _).
intros a b.
exact ((a ; b.1) ; b.2).
(* Lemma 1.6.16 *)
refine (isequiv_adjointify (functor_sigma pr1 m) inv _ _).
(* Apply sigma induction twice *)
refine (sig_ind _ _ _ _).
intro a.
refine (sig_ind _ _ _ _).
intros c d. (* By computation *)
reflexivity.
(* Again, apply sigma induction *)
refine (sig_ind _ _ _ _).
refine (sig_ind _ _ _ _).
intros a c d. (* By computation *)
reflexivity.
Qed.
(*------ Section 1.8 ------- *)
(* There are two ways of representing subtypes. One is (as in the report):
Subtype S := S -> hProp
Another way is by using a sigma type:
Subtype S := {f: S -> Type & forall w: S, IsHProp (f w)}
First, we prove these two representations are equivalent (we will use this fact
later).
*)
Lemma subtype_repr_equiv (S: Type) :
(S -> hProp) <~> {f: S -> Type & forall w: S, IsHProp (f w)}.
Proof. (* By Lemma 1.6.18 we need to provide
two functions that are inverses of each other. *)
transparent assert (f1: ((S -> hProp) -> {f : S -> Type & forall w : S, IsHProp (f w)})).
intro f. (* Here, "trunctype_type" and "istrunc_trunctype_type" are the accessor
functions for the first and second components on the sigma "hProp"
(which is encoded as a record type). *)
refine (fun w: S => trunctype_type (f w) ; _).
exact (fun w: S => istrunc_trunctype_type (f w)).
transparent assert (f2: ({f : S -> Type & forall w : S, IsHProp (f w)} -> (S -> hProp))).
intro p. (* Here, BuildhProp is the constructor for the "hProp" record. *)
exact (fun w: S => @BuildhProp (p.1 w) (p.2 w)).
refine (equiv_adjointify f1 f2 _ _).
(* By induction on sigma types *)
refine (sig_ind _ _ _ _).
intros w p. (* The rest is just computation *)
simpl. (* Notice this will use uniqueness of Pi-types *)
reflexivity.
intro f. (* Again, the rest is computation *)
simpl.
reflexivity.
Qed.
(*
On this script I prefer the sigma representation for subtypes, because sigmas can be
encoded as record types in Coq. And record types are more "user-friendly" in the sense
that records allow access to the components of a sigma by using accesor functions
instead of nested projection functions.
Also, records allow automatic coercion, so that when we have a subtype P: Subtype S
we can treat P automatically as a function P: S -> Type when necessary.
*)
Record Subtype (S: Type) := BuildSubtype {
subtype_func : S -> Type ;
subtype_hprop : forall w: S, IsHProp (subtype_func w)
}.
(* Make some arguments implicit. *)
Arguments BuildSubtype {_} _ {_}.
Arguments subtype_func {_} _ _.
Arguments subtype_hprop {_} _ _ _ _.
(* Make automatically available the proof that any subtype is a predicate. *)
Global Existing Instance subtype_hprop.
(* Treat subtypes as if they were functions when necessary *)
Coercion subtype_func : Subtype >-> Funclass.
(* The Subtype record is equivalent to a Sigma type. *)
Lemma subtype_as_sigma (S: Type) : {f: S -> Type & forall x: S, IsHProp (f x)}
<~> Subtype S.
Proof. (* Just apply the "issig" tactic available in the HoTT library.
This tactic transforms automatically between records and sigmas. *)
issig (@BuildSubtype S) (@subtype_func S) (@subtype_hprop S).
Defined.
(* If the underlying functions on two subtypes are equal, the subtypes are equal. *)
Lemma path_subtype {fext: Funext} {S: Type} {A B: Subtype S} :
subtype_func A = subtype_func B -> A = B.
Proof.
intro p. (* We prove that "A" and "B" seen as elements of the Sigma are equal, since
the Sigma and Record types are the same.
"@paths A a b" is just another way of writing "a = b" but the "@paths"
term allows specifying type A when Coq cannot deduce it from "a" and "b"
alone, as in this case. *)
assert ( @paths {f: S -> Type & forall x: S, IsHProp (f x)}
(subtype_func A ; subtype_hprop A)
(subtype_func B ; subtype_hprop B)
) as p1. (* The second components on both pairs are terms on mere propositions.
So, apply Lemma 1.8.14. *)
refine (path_sigma_hprop _ _ _).
exact p. (* Apply the equivalence of the record and the Sigma. *)
exact (ap (subtype_as_sigma S) p1).
Qed.
(* The subtype record is a set. *)
Global Instance subtype_is_set {univ: Univalence} (S: Type) : IsHSet (Subtype S).
Proof. (* We know the record and sigma forms are equivalent, and equivalences preserve
sets.
So, apply Lemma 1.8.16 *)
refine (trunc_equiv' _ (subtype_as_sigma S)). (* But we know the sigma is equivalent to
type "S -> hProp". *)
pose proof (subtype_repr_equiv S) as p1.
(* By Lemma 1.8.18, "hProp" is a set, which
implies that type "S -> hProp" is a set by the same Lemma.
Also, sets are preserved under equivalences by
Lemma 1.8.16 *)
exact (trunc_equiv' (S -> hProp) p1).
Qed.
(* Lemma 1.8.20
We use "Subtype A" instead of "A -> hProp" as this will be more convenient
for us. *)
Lemma cantor {fext: Funext} (A: Type) : ~(Subtype A <~> A).
Proof.
intro e.
set (k := BuildSubtype (fun a: A => ~(e^-1 a a))).
pose proof (ap subtype_func (eissect e k))^ as p1.
set (delta := e k).
pose proof (happly p1) as p2.
change (k == e^-1 delta) in p2.
assert (forall C: Type, (~C) = C -> Empty) as f.
intros C h1. (* equiv_path is function "idtoequiv" in the report *)
pose proof (equiv_path _ _ h1) as g1.
set (g3 := fun w: C => g1^-1 w w).
exact (g3 (g1 g3)).
exact (f (e^-1 delta delta) (p2 delta)).
Qed.
(*------ Section 1.8.1 ------- *)
(* To state the propositional rezising axiom, we need to follow the strategy explained
at "https://github.com/HoTT/HoTT/issues/783".
We will use a tag "PropResize" whenever we want to use
the propositional resizing axiom, in the same way as tags "Funext" and "Univalence"
are used in the HoTT library (I just copied the strategy from the HoTT library). *)
Monomorphic Axiom dummy_propresize_type : Type0.
Monomorphic Class PropResize := {dummy_propresize_value : dummy_propresize_type}.
(* In the report, we use GPRopR^-1 to resize a proposition into a lower
level.
But here, since GPRopR is not treated as an equivalence, usages of GPRopR on this
script will correspond to usages of GPRopR^-1 in the report. This is just a
mere technical issue due to limitations on Coq. However, this way of representing
propositional resizing is not fundamentally different to the way it is done in HoTT.
So, this axiom corresponds to Lemma 1.8.22
This axiom is expressing that any proposition can be sent to some type at some universe
level that is independent of the level of the original proposition
(due to universe polymorphism in Coq).
So, this axiom is not relating the resized proposition with the original proposition.
We need another axiom to relate them. *)
Axiom GPropR : forall `{PropResize} (A : Type) {Aprop : IsHProp A}, Type.
(* This axiom corresponds to Lemma 1.8.23
This is the axiom that relates the resized proposition to the original proposition,
by saying that the resized proposition is equivalent to the original proposition. *)
Axiom equiv_propresize : forall {propRes: PropResize} (P : Type) {Pprop : IsHProp P},
P <~> GPropR P.
(* Lemma 1.8.24
Notice how in the report the conclusion is written as "(GPropR P)^-1 -> A". *)
Lemma prop_resize_rec {propRes: PropResize} {P A: Type} {Pprop: IsHProp P} (f: P -> A) :
GPropR P -> A.
Proof.
intro p.
exact (f ((equiv_propresize _)^-1 p)).
Qed.
(* This is another part of Lemma 1.8.22
which says that the resized proposition IS a proposition.
We mark it as a global instance so that Coq can use it in automatic proofs. *)
Global Instance resized_is_prop {propRes: PropResize} (A: Type) {HA: IsHProp A} :
IsHProp (GPropR A).
Proof.
exact (trunc_equiv' A (equiv_propresize A)).
Qed.
(*------ Section 1.9 ------- *)
(* Definition 1.9.6
Again, we are using a record to represent a sigma.
The difference between a record and a class is that classes allow us to register
instances of the record (by using the commands "Global Instance" or "Local Instance")
into a database, so that they can be used in automatic proofs. *)
Class FunctorStr (H: Type -> Type) := BuildFunctorStr {
map : forall A B: Type@{i}, (A -> B) -> H A -> H B ;
id_preser : forall A: Type@{i}, map A A idmap == idmap ;
comp_preser : forall (A B C: Type@{i}) (g: A -> B) (h: B -> C),
map A C (h o g) == (map B C h) o (map A B g)
}.
(*
IMPORTANT: Notice we are using universe level annotations in the definition of
FunctorStr. If we remove them, Coq will wrongly collapse universe levels when
starting some proofs later in the development, resulting in a
"universe inconsistency error" that is not really there. The author does not know if
this is a bug on the version of Coq used by the HoTT library. But adding those
annotations in FunctorStr prevents this odd behaviour in Coq. Nevertheless, those
annotations do not change the meaning of FunctorStr since that is exactly how FunctorStr
was defined in the report (i.e. all types on the universal quantifiers live at the same
universe level).
*)
(* Make some arguments implicit. *)
Arguments BuildFunctorStr {_} _ _ _.
Arguments map _ {_} {_} {_} _ _.
Arguments id_preser _ {_} {_} _.
Arguments comp_preser _ {_} {_} {_} {_} _ _ _.
(* Definition 1.9.9
Since Coq is automatically managing the universe levels, we do not need to
define that a functor is an endofunctor, as this will be automatically handled
by Coq. *)
Class PreservesSets (H: Type -> Type) {FH: FunctorStr H} :=
set_preser_cond : forall A: Type, IsHSet A -> IsHSet (H A).
(* This will inform the automatic solver that "H A" is a set. *)
Global Existing Instance set_preser_cond.
(* Lemma 1.9.10 *)
Lemma funct_preserve_equiv {fext: Funext} (H: Type -> Type) {FH: FunctorStr H} {A B: Type}
(e: A -> B) {equiv: IsEquiv e} : IsEquiv (map H e).
Proof. (* Lemma 1.6.16 *)
refine (isequiv_adjointify (map H e) (map H e^-1) _ _).
intro b.
rewrite <- comp_preser. (* Function extensionality and
Lemma 1.6.15 *)
rewrite (path_forall _ _ (eisretr e)).
exact (id_preser H b).
intro a.
rewrite <- comp_preser. (* Function extensionality and
Lemma 1.6.15 *)
rewrite (path_forall _ _ (eissect e)).
exact (id_preser H a).
Qed.
(* Many Sigmas in the report consist of a type together with a property they need
to satisfy. For example, in the report an algebra was defined as:
Alg H := {A: Type & H A -> A}
It turns out that we can have greater flexibility in the code if we split these
definitions into two concepts: the property and those elements satisfying the property.
For example, we can split "Alg H" into two types:
IsAlg A H := H A -> A
Alg H := {A: Type & IsAlg A H}
We will follow this convention for almost all concepts on this script.
*)
(* Property part of Definition 1.9.11 *)
Class IsAlg (A: Type) (H: Type -> Type) {FH: FunctorStr H} :=
In : H A -> A.
(* Make some arguments implicit *)
Arguments In _ {_} {_} {_} _.
(* Definition 1.9.11 encoded as a record. *)
Record Alg (H: Type -> Type) {FH: FunctorStr H} := BuildAlg {
alg_obj : Type ;
alg_obj_is_alg : IsAlg alg_obj H
}.
(* Make some arguments implicit *)
Arguments BuildAlg {_} {_} _ _.
Arguments alg_obj {_} {_} _.
(* Make automatically available the proof IsAlg. *)
Global Existing Instance alg_obj_is_alg.
(* Treat an algebra as if it were a type when necessary. *)
Coercion alg_obj : Alg >-> Sortclass.
(* Property part of Definition 1.9.12 *)
Class IsAlgMor {H: Type -> Type} {FH: FunctorStr H} {A B: Type} {AA: IsAlg A H}
{AB: IsAlg B H} (f: A -> B) :=
alg_mor : f o (In A) == (In B) o (map H f).
(* Make some arguments implicit *)
Arguments alg_mor {_} {_} {_} {_} {_} {_} _ {_} _.
(* Definition 1.9.12 encoded as a record *)
Record AlgMor {H: Type -> Type} {FH: FunctorStr H} (A B: Type) {AA: IsAlg A H}
{AB: IsAlg B H} := BuildAlgMor {
alg_mor_fun : A -> B ;
fun_is_alg_mor : IsAlgMor alg_mor_fun
}.
(* Make some arguments implicit. *)
Arguments BuildAlgMor {_} {_} {_} {_} {_} {_} _ _.
Arguments alg_mor_fun {_} {_} {_} {_} {_} {_} _ _.
(* Make automatically available the proof IsAlgMor *)
Global Existing Instance fun_is_alg_mor.
(* Treat an AlgMor as if it were a function, when necessary. *)
Coercion alg_mor_fun : AlgMor >-> Funclass.
(* The AlgMor record is equivalent to a Sigma type. *)
Lemma algmor_as_sigma {H: Type -> Type} {FH: FunctorStr H} (A B: Type) {AA: IsAlg A H}
{AB: IsAlg B H} : {f: A -> B & IsAlgMor f} <~> AlgMor A B.
Proof. (* Just apply the "issig" tactic available in the HoTT library.
This tactic transforms automatically between records and sigmas. *)
issig (@BuildAlgMor H FH A B AA AB)
(@alg_mor_fun H FH A B AA AB)
(@fun_is_alg_mor H FH A B AA AB).
Defined.
(* Lemma 1.9.13 *)
Lemma alg_mor_compose {H: Type -> Type} {FH: FunctorStr H} {A B C: Type} {AA: IsAlg A H}
{AB: IsAlg B H} {AC: IsAlg C H} (f: AlgMor A B) (g: AlgMor B C) : IsAlgMor (g o f).
Proof.
intro w.
rewrite comp_preser.
rewrite <- (alg_mor g).
rewrite <- (alg_mor f).
reflexivity.
Qed.
(* Lemma 1.9.14 *)
Lemma id_alg_mor {H: Type -> Type} {FH: FunctorStr H} (A: Type) {AA: IsAlg A H} :
IsAlgMor idmap.
Proof.
intro w.
rewrite id_preser.
reflexivity.
Qed.
(*------ Section 1.10 ------- *)
(* Property part of Definition 1.10.4 *)
Class IsCoAlg (A: Type) (H: Type -> Type) {FH: FunctorStr H} :=
Out : A -> H A.
(* Make some arguments implicit *)
Arguments Out _ {_} {_} {_} _.
(* Definition 1.10.4 encoded as a record. *)
Record CoAlg (H: Type -> Type) {FH: FunctorStr H} := BuildCoAlg {
coalg_obj : Type ;
coalg_obj_is_coalg : IsCoAlg coalg_obj H
}.
(* Make some arguments implicit *)
Arguments BuildCoAlg {_} {_} _ _.
Arguments coalg_obj {_} {_} _.
(* Make automatically available the proof IsCoAlg. *)
Global Existing Instance coalg_obj_is_coalg.
(* Treat a coalgebra as if it were a type when necessary. *)
Coercion coalg_obj : CoAlg >-> Sortclass.
(* Property part of Definition 1.10.5 *)
Class IsCoAlgMor {H: Type -> Type} {FH: FunctorStr H} {A B: Type} {CA: IsCoAlg A H}
{CB: IsCoAlg B H} (f: A -> B) :=
coalg_mor : (map H f) o (Out A) == (Out B) o f.
(* Make some arguments implicit *)
Arguments coalg_mor {_} {_} {_} {_} {_} {_} _ {_} _.
(* Definition 1.10.5 encoded as a record *)
Record CoAlgMor {H: Type -> Type} {FH: FunctorStr H} (A B: Type) {CA: IsCoAlg A H}
{CB: IsCoAlg B H} := BuildCoAlgMor {
coalg_mor_fun : A -> B ;
fun_is_coalg_mor : IsCoAlgMor coalg_mor_fun
}.
(* Make some arguments implicit. *)
Arguments BuildCoAlgMor {_} {_} {_} {_} {_} {_} _ _.
Arguments coalg_mor_fun {_} {_} {_} {_} {_} {_} _ _.
(* Make automatically available the proof IsAlgMor *)
Global Existing Instance fun_is_coalg_mor.
(* Treat an AlgMor as if it were a function, when necessary. *)
Coercion coalg_mor_fun : CoAlgMor >-> Funclass.
(* The CoAlgMor record is equivalent to a Sigma type. *)
Lemma coalgmor_as_sigma {H: Type -> Type} {FH: FunctorStr H} (A B: Type)
{CA: IsCoAlg A H} {CB: IsCoAlg B H} : {f: A -> B & IsCoAlgMor f} <~> CoAlgMor A B.
Proof. (* Just apply the "issig" tactic available in the HoTT library.
This tactic transforms automatically between records and sigmas. *)
issig (@BuildCoAlgMor H FH A B CA CB)
(@coalg_mor_fun H FH A B CA CB)
(@fun_is_coalg_mor H FH A B CA CB).
Defined.
(* Lemma 1.10.6 *)
Lemma coalg_mor_compose {H: Type -> Type} {FH: FunctorStr H} {A B C: Type}
{CA: IsCoAlg A H} {CB: IsCoAlg B H} {CC: IsCoAlg C H} (f: CoAlgMor A B)
(g: CoAlgMor B C) : IsCoAlgMor (g o f).
Proof.
intro w.
rewrite comp_preser.
rewrite (coalg_mor f).
rewrite (coalg_mor g).
reflexivity.
Qed.
(* Lemma 1.10.7 *)
Lemma id_coalg_mor {H: Type -> Type} {FH: FunctorStr H} (A: Type) {CA: IsCoAlg A H} :
IsCoAlgMor idmap.
Proof.
intro w.
rewrite id_preser.
reflexivity.
Qed.
(*------ Section 1.11.1 ------- *)
(* (-1)-truncations are defined by "Trunc -1" in the HoTT library.
The (-1)-truncation constructor is "tr". *)
(* Theorem 1.11.6 *)
Theorem choice_thm {A: Type} {B: A -> Type} (P: forall w: A, B w -> Type) :
(forall w: A, exists a: B w, P w a) ->
exists (g: forall y: A, B y),
forall w: A, P w (g w).
Proof.
intro f.
set (g := fun y: A => (f y).1).
exists g.
intro w.
exact (f w).2.
Defined.
(* Lemma 1.11.8 *)
Lemma uni_choice {A: Type} (P: A -> Type) :
(forall w: A, IsHProp (P w)) ->
(forall w: A, Trunc -1 (P w)) ->
forall w: A, P w.
Proof.
intros h1 h2 w. (* Lemma 1.11.7
This is expressing that the (-1)-constructor
"tr: P w -> Trunc (-1) (P w)" is an equivalence. In the report
this is expressed as "P w <~> Trunc (-1) (P w)" *)
pose proof (isequiv_tr -1 (P w)).
pose proof (h2 w) as h.
exact (tr^-1 h).
Qed.
(* Definition 1.11.9 *)
Definition IsSurjection {A B: Type} (f: A -> B) :=
forall b: B, Trunc -1 (exists a: A, f a = b).
(* Lemma 1.11.10 *)
Lemma idmap_is_surjection (A: Type) : @IsSurjection A A idmap.
Proof.
intro a.
exact (tr (a ; idpath)).
Qed.
(* Lemma 1.11.11 *)
Lemma surjections_compose {A B C: Type} {f: A -> B} {g: B -> C} (fsur: IsSurjection f)
(gsur: IsSurjection g) : IsSurjection (g o f).
Proof.
intro c.
cut (Trunc -1 (exists b: B, g b = c)). (* (-1)-recursion *)
refine (Trunc_rec _). (* Induction on sigmas *)
refine (sig_ind _ _ _ _).
intros b p1.
cut (Trunc -1 (exists a: A, f a = b)). (* (-1)-recursion *)
refine (Trunc_rec _). (* Induction on sigmas *)
refine (sig_ind _ _ _ _).
intros a p2.
pose proof (ap g p2) as p3.
exact (tr (a ; p3 @ p1)).
exact (fsur b).
exact (gsur c).
Qed.
(*------ Section 1.11.3 ------- *)
(* Coequalizers are written as "Coeq f g" in the HoTT library.
The constructor is "coeq" *)
(* Lemma 1.11.17
This is the simplified induction principle for coequalizers. *)
Lemma coeq_ind_hprop {A B: Type} (f g: A -> B) (P: Coeq f g -> Type)
{Pprop: forall x: Coeq f g, IsHProp (P x)} :
(forall b: B, P (coeq b)) -> forall w: Coeq f g, P w.
Proof.
intro h. (* By the general induction principle for coequalizers
Definition 1.11.16 *)
refine (Coeq_ind P h _).
intro a. (* P is a mere proposition *)
apply path_ishprop.
Defined.
(* Lemma 1.11.19 *)
Lemma coeq_constructor_surjective {A B: Type} (f g: A -> B) :
IsSurjection (@coeq _ _ f g).
Proof. (* By the simplified induction principle *)
refine (coeq_ind_hprop _ _ _ _).
intro a.
exact (tr (a ; idpath)).
Qed.
(*------ Section 1.11.4 ------- *)
(* Pushouts are written as "pushout f g" in the HoTT library.
We need to do a little rewording so that definitions in the library look like the
definitions in the report. *)
(* These are the three constructors in Lemma 1.11.20.
Function "push" in the HoTT Library is defined by using "coeq", the constructor for
coequalizers. *)
Definition pushleft {A B C: Type} (g: A -> B) (f: A -> C) : B -> pushout g f :=
push o inl.
Definition pushright {A B C: Type} (g: A -> B) (f: A -> C) : C -> pushout g f :=
push o inr.
(* The higher constructor for pushouts is called "pp" in the library. We just reword it
using our pushleft and pushright functions. *)
Definition pushiden {A B C: Type} (g: A -> B) (f: A -> C) (a: A) :
pushleft g f (g a) = pushright g f (f a) := pp a.
(* Lemma 1.11.21 *)
Lemma pushout_ind_hprop {A B C: Type} (g: A -> B) (f: A -> C)
(P: pushout g f -> Type) {Pprop: forall x: pushout g f, IsHProp (P x)} :
(forall b: B, P (pushleft g f b)) ->
(forall c: C, P (pushright g f c)) ->
forall w: pushout g f, P w.
Proof.
intros pushB pushC.
refine (pushout_ind g f P (sum_ind _ pushB pushC) _).
intro a. (* P is a mere proposition *)
apply path_ishprop.
Defined.
(* Lemma 1.11.22
This is just a rewording of the recursion principle available in the library. *)
Lemma pushout_rec' {A B C: Type} {g: A -> B} {f: A -> C} {D: Type}
(h1: B -> D) (h2: C -> D) :
(forall a: A, h1 (g a) = h2 (f a)) -> (pushout g f) -> D.
Proof.
intro hyp.
refine (pushout_rec _ (sum_ind _ h1 h2) _).
exact hyp.
Defined.
(* First part of Lemma 1.11.23 *)
Lemma pushright_surjective {A B C: Type} (g: A -> B) (f: A -> C) :
IsSurjection g -> IsSurjection (pushright g f).
Proof.
intros gsur.
refine (pushout_ind_hprop g f _ _ _).
intro b.
cut (Trunc -1 (exists y: A, g y = b)). (* (-1)-recursion *)
refine (Trunc_rec _). (* Induction on sigmas *)
refine (sig_ind _ _ _ _).
intros y p1.
pose proof (ap (pushleft g f) p1) as p2.
pose proof (pushiden g f y)^ as p3.
exact (tr (f y ; p3 @ p2)).
exact (gsur b).
intro c.
exact (tr (c ; idpath)).
Qed.
(* Second part of Lemma 1.11.23 *)
Lemma pushleft_surjective {A B C: Type} (g: A -> B) (f: A -> C) :
IsSurjection f -> IsSurjection (pushleft g f).
Proof.
intros fsur.
refine (pushout_ind_hprop g f _ _ _).
intro b.
exact (tr (b ; idpath)).
intro c.
cut (Trunc -1 (exists y: A, f y = c)). (* (-1)-recursion *)
refine (Trunc_rec _). (* Induction on sigmas *)
refine (sig_ind _ _ _ _).
intros y p1.
pose proof (ap (pushright g f) p1) as p2.
pose proof (pushiden g f y) as p3.
exact (tr (g y ; p3 @ p2)).
exact (fsur c).
Qed.
(*------ Section 1.11.5 ------- *)
(* Quotients are written as "quotient R" in the library, where R is the mere relation.
The constructor is "class_of" and the higher constructor is
"related_classes_eq".
The library already provides a simplified induction principle "quotient_ind_prop"
and a recursion principle "quotient_rec". *)
(* Lemma 1.11.27 *)
Lemma class_of_surjective {A: Type} (R: A -> A -> Type)
{rprop: forall x y: A, IsHProp (R x y)} : IsSurjection (class_of R).
Proof. (* By the simplified induction principle *)
refine (quotient_ind_prop R _ _).
intro a.
exact (tr (a ; idpath)).
Qed.
(****************************************************
Chapter 2: Complete lattices and fixpoints in HoTT
****************************************************)
(*------ Section 2.1 ------- *)
(* Definition 2.1.1
Again, we are representing a sigma as a record.
*)
Class PosetStr (P: Type) := BuildPosetStr {
brel_p : P -> P -> Type ; (* It has a binary relation. *)
refle_p : forall w: P, brel_p w w ; (* Reflexivity. *)
antisym_p : forall w y: P, brel_p w y -> brel_p y w -> w = y ; (* Antisymmetry. *)
trans_p : forall w y z: P, brel_p w y -> brel_p y z -> brel_p w z ; (* Transitivity. *)
dom_p_hset : IsHSet P ; (* The domain is a set. *)
brel_hprop : forall w y: P, IsHProp (brel_p w y) (* The relation is a mere relation. *)