-
Notifications
You must be signed in to change notification settings - Fork 2
/
categories.v
2332 lines (1983 loc) · 71.1 KB
/
categories.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
(* Copyright (c) 2014, Robert Dockins *)
Require Import Setoid.
Require Import basics.
(** * Some elementary category theory.
Here we develop enough category theory to support our investigations
of domain theory. We follow the general strategy used by several
authors (FIXME look up citation) for defining category theory inside
type theory, which is to equip every hom-set with an equivalance relation.
Then the category axioms are all stated with respect to the setoid structure
on hom-sets, and furthermore composition and functor actions are required
to respect hom-set equality.
*)
Delimit Scope category_ob_scope with cat_ob.
Delimit Scope category_hom_scope with cat.
Delimit Scope category_ops_scope with cat_ops.
Open Scope category_ob_scope.
Open Scope category_hom_scope.
Open Scope category_ops_scope.
(** The [Comp] module represents the structure of composition
and an identity. Later we will layer on the category
axioms and the setoid structure. It is convenient to break
out just the operations into a separate structure from
the category structure.
*)
Module Comp.
Record mixin_of (ob:Type) (hom:ob -> ob -> Type) :=
Mixin
{ identity : forall A, hom A A
; comp : forall A B C, hom B C -> hom A B -> hom A C }.
Structure type : Type :=
Pack { ob : Type; hom : ob -> ob -> Type; mixin: mixin_of ob hom }.
End Comp.
Definition comp_op T := Comp.comp _ _ (Comp.mixin T).
Definition ident_op T := Comp.identity _ _ (Comp.mixin T).
Notation "x ∘ y" := (@comp_op _ _ _ _ (x)%cat (y)%cat) : category_hom_scope.
Notation "'id'" := (@ident_op _ _) : category_hom_scope.
Notation "'id' ( A )" := (@ident_op _ (A)%cat_ob) (only parsing)
: category_hom_scope.
(** Here we put together the pieces: the setoid structure
on hom-sets, the composition strucutre, and the category axioms.
*)
Module Category.
Section category.
Variable ob:Type.
Variable hom : ob -> ob -> Type.
Variable (EQ:forall A B, Eq.mixin_of (hom A B)).
Variable (COMP:Comp.mixin_of ob hom).
Canonical Structure cat_EQ A B := Eq.Pack _ (EQ A B).
Canonical Structure cat_COMP := Comp.Pack _ _ COMP.
Record axioms :=
Axioms
{ ident1 : forall A B (f:hom A B), f ∘ id(A) ≈ f
; ident2 : forall A B (f:hom A B), id(B) ∘ f ≈ f
; assoc : forall A B C D (f:hom C D) (g:hom B C) (h:hom A B),
f ∘ (g ∘ h) ≈ (f ∘ g) ∘ h
; respects : forall A B C (f f':hom B C) (g g':hom A B),
f ≈ f' -> g ≈ g' -> (f ∘ g) ≈ (f' ∘ g')
}.
End category.
Record category :=
Category
{ ob : Type
; hom : ob -> ob -> Type
; eq : forall A B, Eq.mixin_of (hom A B)
; comp : Comp.mixin_of ob hom
; cat_axioms : axioms ob hom eq comp
}.
End Category.
Notation category := Category.category.
Notation Category := Category.Category.
Notation ob := Category.ob.
Notation hom := Category.hom.
Notation "A → B" := (Category.hom _ A B) : category_hom_scope.
Bind Scope category_ob_scope with Category.ob.
Coercion ob : category >-> Sortclass.
Canonical Structure CAT_EQ (C:category) A B
:= Eq.Pack (hom C A B) (Category.eq C A B).
Canonical Structure CAT_COMP (C:category)
:= Comp.Pack (ob C) (hom C) (Category.comp C).
(** Here we define some easier-to-use versions of the catgory axioms.
*)
Section category_axioms.
Variable C:category.
Definition cat_ident1 := Category.ident1 _ _ _ _ (Category.cat_axioms C).
Definition cat_ident2 := Category.ident2 _ _ _ _ (Category.cat_axioms C).
Definition cat_assoc := Category.assoc _ _ _ _ (Category.cat_axioms C).
Definition cat_respects := Category.respects _ _ _ _ (Category.cat_axioms C).
End category_axioms.
(** Register composition as a morphism for the setoid equality. *)
Add Parametric Morphism (CAT:category) (A B C:ob CAT) :
(@comp_op (CAT_COMP CAT) A B C)
with signature (eq_op (CAT_EQ CAT B C)) ==>
(eq_op (CAT_EQ CAT A B)) ==>
(eq_op (CAT_EQ CAT A C))
as category_morphism.
Proof.
intros. apply cat_respects; trivial.
Qed.
(** Groupoids are categories in which every morphism has an inverse.
Groupoids generalize groups (hence the name) in the sense that
a groupoid with a single object forms a group.
When [f] is a morphism in a groupoid [f⁻¹] is its inverse.
*)
Module Groupoid.
Section groupoid.
Variables (ob:Type) (hom:ob -> ob -> Type).
Variable eq:forall A B:ob, Eq.mixin_of (hom A B).
Variable comp:Comp.mixin_of ob hom.
Variable cat_axioms : Category.axioms ob hom eq comp.
Section axioms.
Definition eq' A B := Eq.Pack _ (eq A B).
Definition comp' := Comp.Pack ob hom comp.
Canonical Structure eq'.
Canonical Structure comp'.
Variable inv : forall (A B:ob) (f:hom A B), hom B A.
Record axioms :=
Axioms
{ inv_id1 : forall A B (f:hom A B), f ∘ inv A B f ≈ id
; inv_id2 : forall A B (f:hom A B), inv A B f ∘ f ≈ id
}.
End axioms.
Record mixin_of :=
Mixin
{ inv : forall (A B:ob) (f:hom A B), hom B A
; groupoid_axioms : axioms inv
}.
End groupoid.
Record groupoid :=
Groupoid
{ ob : Type
; hom : ob -> ob -> Type
; eq_mixin : forall A B, Eq.mixin_of (hom A B)
; comp_mixin : Comp.mixin_of ob hom
; cat_axioms : Category.axioms ob hom eq_mixin comp_mixin
; mixin : mixin_of ob hom eq_mixin comp_mixin
}.
Definition eq (X:groupoid) (A B:ob X) :=
Eq.Pack (hom X A B) (eq_mixin X A B).
Definition comp (X:groupoid) :=
Comp.Pack (ob X) (hom X) (comp_mixin X).
Definition category (X:groupoid) : category :=
Category (ob X) (hom X) (eq_mixin X) (comp_mixin X) (cat_axioms X).
Definition inv_op (X:groupoid) := inv _ _ _ _ (mixin X).
End Groupoid.
Notation groupoid := Groupoid.groupoid.
Notation Groupoid := Groupoid.Groupoid.
Canonical Structure Groupoid.category.
Canonical Structure Groupoid.eq.
Canonical Structure Groupoid.comp.
Coercion Groupoid.category : groupoid >-> category.
Notation "f '⁻¹'" := (Groupoid.inv_op _ _ _ f) : category_hom_scope.
Lemma inv_id1 (X:groupoid) :
forall (A B:X) (f:A → B), f ∘ f⁻¹ ≈ id.
Proof (Groupoid.inv_id1 _ _ _ _ _
(Groupoid.groupoid_axioms _ _ _ _ (Groupoid.mixin X))).
Arguments inv_id1 [X A B] f.
Lemma inv_id2 (X:groupoid) :
forall (A B:X) (f:A → B), f⁻¹ ∘ f ≈ id.
Proof (Groupoid.inv_id2 _ _ _ _ _
(Groupoid.groupoid_axioms _ _ _ _ (Groupoid.mixin X))).
Arguments inv_id2 [X A B] f.
Lemma inv_inv (X:groupoid) :
forall (A B:X) (f:A → B), (f⁻¹)⁻¹ ≈ f.
Proof.
intros.
generalize (inv_id2 f⁻¹). intro.
generalize (inv_id2 f). intro.
transitivity ((f⁻¹)⁻¹ ∘ f⁻¹ ∘ f).
- rewrite <- (cat_assoc X).
rewrite H0. symmetry. apply cat_ident1.
- rewrite H. apply cat_ident2.
Qed.
Lemma inv_compose (X:groupoid) :
forall (A B C:X) (g:B → C) (f:A → B), (g ∘ f)⁻¹ ≈ f⁻¹ ∘ g⁻¹.
Proof.
intros.
generalize (inv_id2 (g ∘ f)). intro.
generalize (inv_id1 f). intro.
generalize (inv_id1 g). intro.
assert ((g ∘ f)⁻¹ ∘ (g ∘ f) ∘ f⁻¹ ≈ (g ∘ f)⁻¹ ∘ g).
{ rewrite <- (cat_assoc X).
rewrite <- (cat_assoc X).
rewrite H0.
rewrite (cat_assoc X).
apply cat_ident1.
}
rewrite H in H2.
rewrite (cat_ident2 X) in H2.
rewrite H2.
rewrite <- (cat_assoc X).
rewrite H1.
rewrite (cat_ident1 X).
auto.
Qed.
Lemma inv_eq (X:groupoid) (A B:X) (f g:A → B) :
f ≈ g -> f⁻¹ ≈ g⁻¹.
Proof.
intro.
generalize (inv_id1 f). intros.
transitivity (g⁻¹ ∘ (f ∘ f⁻¹)).
- rewrite H at 2.
rewrite (cat_assoc X).
generalize (inv_id2 g). intros.
rewrite H1.
rewrite (cat_ident2 X). auto.
- rewrite H0.
rewrite (cat_ident1 X). auto.
Qed.
Lemma inv_inj (X:groupoid) (A B:X) (f g:A → B) :
f⁻¹ ≈ g⁻¹ -> f ≈ g.
Proof.
intros.
apply (inv_eq X) in H.
rewrite inv_inv in H.
rewrite inv_inv in H.
auto.
Qed.
Add Parametric Morphism (X:groupoid) (A B:X) :
(Groupoid.inv_op X A B)
with signature (eq_op (Groupoid.eq X A B)) ==>
(eq_op (Groupoid.eq X B A))
as inv_morophism.
Proof (inv_eq X A B).
(** A monomorphism is a morphism which cancels on the left.
*)
Section mono.
Variable C:category.
Record monomorphism (A B:C) :=
Monomorphism
{ mono_hom : A → B
; mono_axiom : forall X (g h:X → A),
mono_hom ∘ g ≈ mono_hom ∘ h -> g ≈ h
}.
End mono.
Arguments mono_hom [C] [A] [B] m.
Arguments mono_axiom [C] [A] [B] m [X] [g] [h] _.
Coercion mono_hom : monomorphism >-> hom.
Notation "A ↣ B" := (monomorphism _ A B) : category_hom_scope.
Program Definition mono_eq (C:category) (A B:C) :=
Eq.Mixin (monomorphism C A B)
(fun f g => mono_hom f ≈ mono_hom g) _ _ _.
Next Obligation.
eauto.
Qed.
Program Definition mono_id (C:category) (A:C) :=
Monomorphism C A A (id(A)) _.
Next Obligation.
rewrite (cat_ident2 C) in H.
rewrite (cat_ident2 C) in H.
auto.
Qed.
Program Definition mono_compose
(C:category) (X Y Z:C) (g:Y ↣ Z) (f:X ↣ Y) :=
Monomorphism C X Z (mono_hom g ∘ mono_hom f) _.
Next Obligation.
intros.
rewrite <- (cat_assoc C) in H.
rewrite <- (cat_assoc C) in H.
apply mono_axiom in H.
apply mono_axiom in H.
auto.
Qed.
Definition mono_comp_mixin C :=
Comp.Mixin _ _ (mono_id C) (mono_compose C).
Program Definition mono_cat_axioms (C:category) :
Category.axioms (ob C) (monomorphism C)
(mono_eq C) (mono_comp_mixin C).
Proof.
constructor.
- intros. apply cat_ident1.
- intros. apply cat_ident2.
- intros. apply cat_assoc.
- intros. apply cat_respects; auto.
Qed.
Canonical Structure MONO_EQ (C:category) A B
:= Eq.Pack (monomorphism C A B) (mono_eq C A B).
Canonical Structure MONO_COMP (C:category)
:= Comp.Pack (ob C) (monomorphism C)
(Comp.Mixin _ _ (mono_id C) (mono_compose C)).
Canonical Structure MONO_CAT (C:category)
:= Category (ob C) (monomorphism C) (mono_eq C)
(mono_comp_mixin C) (mono_cat_axioms C).
(*
Canonical Structure MONO_CONCRETE
(C:category)
(CC : concrete C) :
concrete (MONO_COMP C) :=
Concrete (MONO_COMP C)
(fun X => obmap _ CC X)
(obeq _ CC)
(fun X Y f x => hommap _ CC (mono_hom f) x)
(fun X Y Z g f x =>
hommap_axiom _ CC (mono_hom g) (mono_hom f) x).
Arguments MONO_CONCRETE [C] [CC].
*)
(** Epimorphism are morphisms that cancel on the right.
*)
Section epic.
Variable C:category.
Record epimorphism (A B:C) :=
Epimorphism
{ epi_hom : A → B
; epi_axiom : forall X (g h:B → X),
g ∘ epi_hom ≈ h ∘ epi_hom ->
g ≈ h
}.
End epic.
Arguments epi_hom [C] [A] [B] e.
Arguments epi_axiom [C] [A] [B] e _ _ _ _.
Coercion epi_hom : epimorphism >-> hom.
Notation "A ↠ B" := (epimorphism _ A B) : category_hom_scope.
Program Definition epi_eq (C:category) (A B:C) :=
Eq.Mixin (epimorphism C A B)
(fun f g => epi_hom f ≈ epi_hom g) _ _ _.
Next Obligation.
eauto.
Qed.
Program Definition epi_id (C:category) (A:C) :=
Epimorphism C A A (id(A)) _.
Next Obligation.
rewrite (cat_ident1 C) in H.
rewrite (cat_ident1 C) in H.
auto.
Qed.
Program Definition epi_compose
(C:category) (X Y Z:C) (g:Y ↠ Z) (f:X ↠ Y) :=
Epimorphism C X Z (epi_hom g ∘ epi_hom f) _.
Next Obligation.
rewrite (cat_assoc C) in H.
rewrite (cat_assoc C) in H.
apply epi_axiom in H.
apply epi_axiom in H.
auto.
Qed.
Definition epi_comp_mixin C :=
Comp.Mixin _ _ (epi_id C) (epi_compose C).
Program Definition epi_cat_axioms (C:category) :
Category.axioms (ob C) (epimorphism C)
(epi_eq C) (epi_comp_mixin C).
Proof.
constructor.
intros. apply cat_ident1.
intros. apply cat_ident2.
intros. apply cat_assoc.
intros. apply cat_respects; auto.
Qed.
Canonical Structure EPI_EQ (C:category) A B
:= Eq.Pack (epimorphism C A B) (epi_eq C A B).
Canonical Structure EPI_COMP (C:category)
:= Comp.Pack (ob C) (epimorphism C) (epi_comp_mixin C).
Canonical Structure EPI_CAT (C:category)
:= Category (ob C) (epimorphism C) (epi_eq C)
(epi_comp_mixin C) (epi_cat_axioms C).
(*
Canonical Structure EPI_CONCRETE
(C:category)
(CC : concrete (CAT_COMP C)) :
concrete (EPI_COMP C) :=
Concrete (EPI_COMP C)
(fun X => obmap _ CC X)
(obeq _ CC)
(fun X Y f x => hommap _ CC (epi_hom f) x)
(fun X Y Z g f x =>
hommap_axiom _ CC (epi_hom g) (epi_hom f) x).
Arguments EPI_CONCRETE [C] [CC].
*)
(** An isomorphism is a pair of functions that, when composed
in each direction, are equal to the identity.
*)
Section iso.
Variable C:category.
Record isomorphism (A B: C) :=
Isomorphism
{ iso_hom : A → B
; iso_inv : B → A
; iso_axiom1 : iso_inv ∘ iso_hom ≈ id
; iso_axiom2 : iso_hom ∘ iso_inv ≈ id
}.
End iso.
Arguments iso_hom [C] [A] [B] i.
Arguments iso_inv [C] [A] [B] i.
Arguments iso_axiom1 [C] [A] [B] i.
Arguments iso_axiom2 [C] [A] [B] i.
Definition iso_hom' (C:category) (A B:C) (f:isomorphism C A B) : Comp.hom _ A B :=
iso_hom f.
Definition iso_hom'' (C:category) (A B:ob C) (f:isomorphism C A B) : CAT_EQ C A B :=
iso_hom f.
Coercion iso_hom : isomorphism >-> hom.
Coercion iso_hom' : isomorphism >-> Comp.hom.
Coercion iso_hom'' : isomorphism >-> Eq.carrier.
Notation "A ↔ B" := (isomorphism _ A B) : category_hom_scope.
Program Definition iso_eq (C:category) (A B:C) :=
Eq.Mixin (isomorphism C A B)
(fun f g => iso_hom f ≈ iso_hom g) _ _ _.
Next Obligation.
eauto.
Qed.
Program Definition iso_id (C:category) (A:C) :=
Isomorphism C A A id(A) id(A) _ _.
Next Obligation.
apply cat_ident1.
Qed.
Next Obligation.
apply cat_ident1.
Qed.
Program Definition iso_compose
(C:category) (X Y Z:C) (g:Y ↔ Z) (f:X ↔ Y) :=
Isomorphism C X Z (iso_hom g ∘ iso_hom f) (iso_inv f ∘ iso_inv g) _ _.
Next Obligation.
intros.
rewrite <- (cat_assoc C _ _ _ _ (iso_inv f) (iso_inv g) (iso_hom g ∘ iso_hom f)).
rewrite (cat_assoc C _ _ _ _ (iso_inv g) (iso_hom g) (iso_hom f)).
rewrite (iso_axiom1 g).
rewrite (cat_ident2 C).
rewrite (iso_axiom1 f).
auto.
Qed.
Next Obligation.
rewrite <- (cat_assoc C _ _ _ _ (iso_hom g) (iso_hom f) (iso_inv f ∘ iso_inv g)).
rewrite (cat_assoc C _ _ _ _(iso_hom f) (iso_inv f) (iso_inv g)).
rewrite (iso_axiom2 f).
rewrite (cat_ident2 C).
rewrite (iso_axiom2 g).
auto.
Qed.
Definition iso_comp_mixin C :=
Comp.Mixin _ _ (iso_id C) (iso_compose C).
Program Definition iso_cat_axioms (C:category) :
Category.axioms (ob C) (isomorphism C)
(iso_eq C) (iso_comp_mixin C).
Proof.
constructor.
- intros; simpl. apply cat_ident1.
- intros; simpl. apply cat_ident2.
- intros; simpl. apply cat_assoc.
- simpl; intros. apply cat_respects; auto.
Qed.
Definition iso_inverse (C:category) (A B:C) (f:A ↔ B) : B ↔ A :=
Isomorphism C B A (iso_inv f) (iso_hom f)
(iso_axiom2 f) (iso_axiom1 f).
Program Definition iso_groupoid_mixin (C:category) :=
Groupoid.Mixin (ob C) (isomorphism C)
(iso_eq C) (iso_comp_mixin C) (iso_inverse C) _.
Next Obligation.
constructor.
simpl; intros.
apply iso_axiom2.
apply iso_axiom1.
Qed.
(*
Canonical Structure ISO_EQ (C:category) A B
:= Eq.Pack (isomorphism C A B) (iso_eq C A B).
Canonical Structure ISO_COMP (C:category)
:= Comp.Pack (ob C) (isomorphism C) (iso_comp_mixin C).
Canonical Structure ISO_CAT (C:category)
:= Category (ob C) (isomorphism C)
(iso_eq C) (iso_comp_mixin C) (iso_cat_axioms C).
*)
Canonical Structure ISO_GROUPOID (C:category)
:= Groupoid (ob C) (isomorphism C)
(iso_eq C) (iso_comp_mixin C)
(iso_cat_axioms C) (iso_groupoid_mixin C).
(** Categories with terminal objects, which we call terminated categories.
Such categories have a distinguished object [terminus] (notation [!])
and a family of morphisms [terminate : A → !] for each object [A].
Furthermore, [terminate] is universial, in that every for every
[f : A → !], [f ≈ terminate].
*)
Module Terminated.
Section terminated.
Variables (ob:Type) (hom:ob -> ob -> Type).
Variable eq:forall A B:ob, Eq.mixin_of (hom A B).
Definition eq' A B := Eq.Pack _ (eq A B).
Canonical Structure eq'.
Record mixin_of :=
Mixin
{ terminus : ob
; terminate : forall A:ob, hom A terminus
; axiom : forall A (f:hom A terminus), f ≈ terminate A
}.
End terminated.
Record terminated :=
Terminated
{ ob : Type
; hom : ob -> ob -> Type
; eq_mixin : forall A B, Eq.mixin_of (hom A B)
; comp_mixin : Comp.mixin_of ob hom
; cat_axioms : Category.axioms ob hom eq_mixin comp_mixin
; mixin : mixin_of ob hom eq_mixin
}.
Canonical Structure eq (X:terminated) (A B:ob X) :=
Eq.Pack (hom X A B) (eq_mixin X A B).
Canonical Structure comp (X:terminated) :=
Comp.Pack (ob X) (hom X) (comp_mixin X).
Canonical Structure category (X:terminated) :=
Category (ob X) (hom X) (eq_mixin X) (comp_mixin X) (cat_axioms X).
Definition terminus_op (X:terminated) := terminus _ _ _ (mixin X).
Definition terminate_op (X:terminated) := terminate _ _ _ (mixin X).
End Terminated.
Notation terminated := Terminated.terminated.
Notation Terminated := Terminated.Terminated.
Canonical Structure Terminated.eq.
Canonical Structure Terminated.comp.
Canonical Structure Terminated.category.
Coercion Terminated.category : terminated >-> category.
Notation "'!'" := (Terminated.terminus_op _) : category_ob_scope.
Notation "'∗'" := (Terminated.terminate_op _ _) : category_ops_scope.
Lemma terminate_univ (X:terminated) :
forall (A:X) (f:A → !), f ≈ ∗.
Proof (Terminated.axiom _ _ _ (Terminated.mixin X)).
(** Categories with initial objects, called initilized categories.
Such categories have a distinguished object [initium] (notation [¡])
and a family of morphisms [initiate : ¡ → A] for each object [A].
Furthermore, [initiate] is universial, in that every for every
[f : ¡ → A], [f ≈ initiate].
*)
Module Initialized.
Section initialized.
Variables (ob:Type) (hom:ob -> ob -> Type).
Variable eq:forall A B:ob, Eq.mixin_of (hom A B).
Definition eq' A B := Eq.Pack _ (eq A B).
Canonical Structure eq'.
Record mixin_of :=
Mixin
{ initium : ob
; initiate : forall A:ob, hom initium A
; axiom : forall A (f:hom initium A), f ≈ initiate A
}.
End initialized.
Record initialized :=
Initialized
{ ob : Type
; hom : ob -> ob -> Type
; eq_mixin : forall A B, Eq.mixin_of (hom A B)
; comp_mixin : Comp.mixin_of ob hom
; cat_axioms : Category.axioms ob hom eq_mixin comp_mixin
; mixin : mixin_of ob hom eq_mixin
}.
Canonical Structure eq (X:initialized) (A B:ob X) :=
Eq.Pack (hom X A B) (eq_mixin X A B).
Canonical Structure comp (X:initialized) :=
Comp.Pack (ob X) (hom X) (comp_mixin X).
Canonical Structure category (X:initialized) :=
Category (ob X) (hom X) (eq_mixin X) (comp_mixin X) (cat_axioms X).
Definition initium_op (X:initialized) := initium _ _ _ (mixin X).
Definition initiate_op (X:initialized) := initiate _ _ _ (mixin X).
End Initialized.
Notation initialized := Initialized.initialized.
Notation Initialized := Initialized.Initialized.
Canonical Structure Initialized.eq.
Canonical Structure Initialized.comp.
Canonical Structure Initialized.category.
Coercion Initialized.category : initialized >-> category.
Notation "'¡'" := (Initialized.initium_op _) : category_ob_scope.
Notation initiate := (Initialized.initiate_op _ _).
Lemma initiate_univ (X:initialized) :
forall (A:X) (f:¡ → A), f ≈ initiate.
Proof (Initialized.axiom _ _ _ (Initialized.mixin X)).
(** Cocartesian categories have all finite coproducts. In particular
they are initialized and have a binary coproduct for every pair
of objects satisfying the usual universal property.
The coproduct of [A] and [B] is written [A + B]. The injection
functions are [ι₁] and [ι₂]. When we have [f:A → C] and [g:B → C],
the case function [either f g : A⊕B → C] is the mediating universal
morphism for the colimit diagram.
*)
Module Cocartesian.
Section cocartesian.
Variables (ob:Type) (hom:ob -> ob -> Type).
Variable eq:forall A B:ob, Eq.mixin_of (hom A B).
Variable comp:Comp.mixin_of ob hom.
Definition eq' A B := Eq.Pack _ (eq A B).
Definition comp' := Comp.Pack ob hom comp.
Canonical Structure eq'.
Canonical Structure comp'.
Section axioms.
Variable sum : ob -> ob -> ob.
Variable inl : forall A B, hom A (sum A B).
Variable inr : forall A B, hom B (sum A B).
Variable either : forall C A B:ob,
hom A C -> hom B C -> hom (sum A B) C.
Record axioms :=
Axioms
{ inl_commute : forall (C A B:ob) f g,
either C A B f g ∘ inl A B ≈ f
; inr_commute : forall (C A B:ob) f g,
either C A B f g ∘ inr A B ≈ g
; either_univ : forall (C A B:ob) f g h,
h ∘ inl A B ≈ f ->
h ∘ inr A B ≈ g ->
h ≈ either C A B f g
}.
End axioms.
Record mixin_of :=
Mixin
{ sum : ob -> ob -> ob
; inl : forall A B:ob, hom A (sum A B)
; inr : forall A B:ob, hom B (sum A B)
; either : forall C A B:ob, hom A C -> hom B C -> hom (sum A B) C
; cocartesian_axioms : axioms sum inl inr either
}.
End cocartesian.
Record cocartesian :=
Cocartesian
{ ob : Type
; hom : ob -> ob -> Type
; eq_mixin:forall A B:ob, Eq.mixin_of (hom A B)
; comp_mixin:Comp.mixin_of ob hom
; cat_axioms : Category.axioms ob hom eq_mixin comp_mixin
; init_mixin : Initialized.mixin_of ob hom eq_mixin
; mixin : mixin_of ob hom eq_mixin comp_mixin
}.
Definition sum_op (X:cocartesian) := sum _ _ _ _ (mixin X).
Definition inl_op (X:cocartesian) := inl _ _ _ _ (mixin X).
Definition inr_op (X:cocartesian) := inr _ _ _ _ (mixin X).
Definition either_op (X:cocartesian) := either _ _ _ _ (mixin X).
Definition eq (X:cocartesian) (A B:ob X) :=
Eq.Pack (hom X A B) (eq_mixin X A B).
Definition comp (X:cocartesian) :=
Comp.Pack (ob X) (hom X) (comp_mixin X).
Definition initalized (X:cocartesian) :=
Initialized (ob X) (hom X) (eq_mixin X) (comp_mixin X) (cat_axioms X) (init_mixin X).
Definition category (X:cocartesian) :=
Category (ob X) (hom X) (eq_mixin X) (comp_mixin X) (cat_axioms X).
End Cocartesian.
Notation cocartesian := Cocartesian.cocartesian.
Notation Cocartesian := Cocartesian.Cocartesian.
Canonical Structure Cocartesian.eq.
Canonical Structure Cocartesian.comp.
Canonical Structure Cocartesian.category.
Canonical Structure Cocartesian.initalized.
Coercion Cocartesian.initalized : cocartesian >-> initialized.
Coercion Cocartesian.category : cocartesian >-> category.
Notation "A + B" := (Cocartesian.sum_op _ A B)
: category_ob_scope.
Notation "'ι₁'" := (Cocartesian.inl_op _ _ _) : category_ops_scope.
Notation "'ι₂'" := (Cocartesian.inr_op _ _ _) : category_ops_scope.
Notation either := Cocartesian.either_op.
Arguments either [X C A B] f g.
Lemma inl_commute (X:cocartesian) :
forall (C A B:ob X) (f:A → C) (g:B → C), either f g ∘ ι₁ ≈ f.
Proof (Cocartesian.inl_commute _ _ _ _ _ _ _ _
(Cocartesian.cocartesian_axioms _ _ _ _ (Cocartesian.mixin X))).
Lemma inr_commute (X:cocartesian) :
forall (C A B:ob X) (f:A → C) (g:B → C), either f g ∘ ι₂ ≈ g.
Proof (Cocartesian.inr_commute _ _ _ _ _ _ _ _
(Cocartesian.cocartesian_axioms _ _ _ _ (Cocartesian.mixin X))).
Lemma either_univ (X:cocartesian) :
forall (C A B:ob X) (f:A → C) (g:B → C) (h:A+B → C),
h ∘ ι₁ ≈ f -> h ∘ ι₂ ≈ g -> h ≈ either f g.
Proof (Cocartesian.either_univ _ _ _ _ _ _ _ _
(Cocartesian.cocartesian_axioms _ _ _ _ (Cocartesian.mixin X))).
Program Definition sum_map (X:cocartesian) (A B C D:ob X)
(f:A → B) (g:C → D) : A+C → B+D := either (ι₁ ∘ f) (ι₂ ∘ g).
Arguments sum_map [X A B C D] f g.
Add Parametric Morphism (X:cocartesian) (C A B:ob X) :
(@Cocartesian.either_op X C A B)
with signature (eq_op (Cocartesian.eq X A C)) ==>
(eq_op (Cocartesian.eq X B C)) ==>
(eq_op (Cocartesian.eq X (A+B)%cat_ob C))
as either_morphism.
Proof.
intros. apply either_univ.
rewrite <- H. apply inl_commute.
rewrite <- H0. apply inr_commute.
Qed.
(** Cartesian categories have all finite products. In particular
they are terminated and have a binary product for every pair
of objects satisfying the usual universal property.
The product of [A] and [B] is written [A × B]. The projection
functions are [π₁] and [π₂]. When we have [f:C → A] and [g:C → B],
the pairing function [〈 f, g 〉 : C → A×B] is the mediating universal
morphism for the limit diagram.
*)
Module Cartesian.
Section cartesian.
Variables (ob:Type) (hom:ob -> ob -> Type).
Variable eq:forall A B:ob, Eq.mixin_of (hom A B).
Variable comp:Comp.mixin_of ob hom.
Definition eq' A B := Eq.Pack _ (eq A B).
Definition comp' := Comp.Pack ob hom comp.
Canonical Structure eq'.
Canonical Structure comp'.
Section axioms.
Variable product : ob -> ob -> ob.
Variable proj1 : forall A B, hom (product A B) A.
Variable proj2 : forall A B, hom (product A B) B.
Variable pairing : forall C A B:ob, hom C A -> hom C B -> hom C (product A B).
Record axioms :=
Axioms
{ proj1_commute : forall (C A B:ob) f g,
proj1 A B ∘ pairing C A B f g ≈ f
; proj2_commute : forall (C A B:ob) f g,
proj2 A B ∘ pairing C A B f g ≈ g
; pairing_univ : forall (C A B:ob) f g h,
proj1 A B ∘ h ≈ f ->
proj2 A B ∘ h ≈ g ->
h ≈ pairing C A B f g
}.
End axioms.
Record mixin_of :=
Mixin
{ product : ob -> ob -> ob
; proj1 : forall A B:ob, hom (product A B) A
; proj2 : forall A B:ob, hom (product A B) B
; pairing : forall C A B:ob, hom C A -> hom C B -> hom C (product A B)
; cartesian_axioms : axioms product proj1 proj2 pairing
}.
End cartesian.
Record cartesian :=
Cartesian
{ ob : Type
; hom : ob -> ob -> Type
; eq_mixin:forall A B:ob, Eq.mixin_of (hom A B)
; comp_mixin:Comp.mixin_of ob hom
; cat_axioms : Category.axioms ob hom eq_mixin comp_mixin
; term_mixin : Terminated.mixin_of ob hom eq_mixin
; mixin : mixin_of ob hom eq_mixin comp_mixin
}.
Definition product_op (X:cartesian) := product _ _ _ _ (mixin X).
Definition proj1_op (X:cartesian) := proj1 _ _ _ _ (mixin X).
Definition proj2_op (X:cartesian) := proj2 _ _ _ _ (mixin X).
Definition pairing_op (X:cartesian) := pairing _ _ _ _ (mixin X).
Definition eq (X:cartesian) (A B:ob X) :=
Eq.Pack (hom X A B) (eq_mixin X A B).
Definition comp (X:cartesian) :=
Comp.Pack (ob X) (hom X) (comp_mixin X).
Definition terminated (X:cartesian) :=
Terminated (ob X) (hom X) (eq_mixin X) (comp_mixin X) (cat_axioms X) (term_mixin X).
Definition category (X:cartesian) :=
Category (ob X) (hom X) (eq_mixin X) (comp_mixin X) (cat_axioms X).
End Cartesian.
Notation cartesian := Cartesian.cartesian.
Notation Cartesian := Cartesian.Cartesian.
Canonical Structure Cartesian.eq.
Canonical Structure Cartesian.comp.
Canonical Structure Cartesian.category.
Canonical Structure Cartesian.terminated.
Coercion Cartesian.terminated : cartesian >-> terminated.
Coercion Cartesian.category : cartesian >-> category.
Notation "A × B" := (Cartesian.product_op _ A B)
: category_ob_scope.
Notation "'π₁'" := (Cartesian.proj1_op _ _ _) : category_ops_scope.
Notation "'π₂'" := (Cartesian.proj2_op _ _ _) : category_ops_scope.
Notation "〈 f , g 〉" := (Cartesian.pairing_op _ _ _ _ f g)
: category_ops_scope.
Lemma proj1_commute (X:cartesian) :
forall (C A B:ob X) (f:C → A) (g:C → B), π₁ ∘ 〈 f, g 〉 ≈ f.
Proof (Cartesian.proj1_commute _ _ _ _ _ _ _ _
(Cartesian.cartesian_axioms _ _ _ _ (Cartesian.mixin X))).
Lemma proj2_commute (X:cartesian) :
forall (C A B:ob X) (f:C → A) (g:C → B), π₂ ∘ 〈 f, g 〉 ≈ g.
Proof (Cartesian.proj2_commute _ _ _ _ _ _ _ _
(Cartesian.cartesian_axioms _ _ _ _ (Cartesian.mixin X))).
Lemma pairing_univ (X:cartesian) :
forall (C A B:ob X) (f:C → A) (g:C → B) (h:C → A × B),
π₁ ∘ h ≈ f -> π₂ ∘ h ≈ g -> h ≈ 〈 f, g 〉.
Proof (Cartesian.pairing_univ _ _ _ _ _ _ _ _
(Cartesian.cartesian_axioms _ _ _ _ (Cartesian.mixin X))).
Program Definition pair_map (X:cartesian) (A B C D:ob X)
(f:A → B) (g:C → D) : A×C → B×D :=
〈 f ∘ π₁, g ∘ π₂ 〉.
Arguments pair_map [X A B C D] f g.
Add Parametric Morphism (X:cartesian) (C A B:ob X) :
(Cartesian.pairing_op X C A B)
with signature (eq_op (Cartesian.eq X C A)) ==>
(eq_op (Cartesian.eq X C B)) ==>
(eq_op (Cartesian.eq X C (A×B)%cat_ob))
as pairing_morphism.
Proof.
intros. apply pairing_univ.
rewrite proj1_commute. auto.
rewrite proj2_commute. auto.
Qed.
(** A distributive category has binary products and binary coproducts,
and sums distribute over products.
*)
Module Distributive.
Section distributive.
Variables (ob:Type) (hom:ob -> ob -> Type).
Variable eq:forall A B:ob, Eq.mixin_of (hom A B).
Variable comp:Comp.mixin_of ob hom.
Variable cat_axioms : Category.axioms ob hom eq comp.
Variable terminated : Terminated.mixin_of ob hom eq.
Variable cartesian : Cartesian.mixin_of ob hom eq comp.
Variable initialized : Initialized.mixin_of ob hom eq.
Variable cocartesian : Cocartesian.mixin_of ob hom eq comp.
Definition eq' A B := Eq.Pack _ (eq A B).
Definition comp' := Comp.Pack ob hom comp.
Definition cartesian' := Cartesian ob hom eq comp cat_axioms terminated cartesian.
Definition cocartesian' := Cocartesian ob hom eq comp cat_axioms initialized cocartesian.
Canonical Structure eq'.
Canonical Structure comp'.
Canonical Structure cartesian'.
Canonical Structure cocartesian'.
Record mixin_of :=
{ distrib_law : forall A B C:ob, A×(B+C) ↔ (A×B) + (A×C)
}.
End distributive.
Record distributive :=
Distributive
{ ob : Type
; hom : ob -> ob -> Type
; eq_mixin : forall A B:ob, Eq.mixin_of (hom A B)
; comp_mixin : Comp.mixin_of ob hom
; cat_axioms : Category.axioms ob hom eq_mixin comp_mixin
; terminated_mixin : Terminated.mixin_of ob hom eq_mixin
; cartesian_mixin : Cartesian.mixin_of ob hom eq_mixin comp_mixin
; initialized_mixin : Initialized.mixin_of ob hom eq_mixin
; cocartesian_mixin : Cocartesian.mixin_of ob hom eq_mixin comp_mixin
; mixin : mixin_of ob hom eq_mixin comp_mixin cat_axioms terminated_mixin cartesian_mixin initialized_mixin cocartesian_mixin
}.
Definition distrib_law_op (X:distributive) :=
distrib_law _ _ _ _ _ _ _ _ _ (mixin X).
Definition eq (X:distributive) (A B:ob X) :=
Eq.Pack (hom X A B) (eq_mixin X A B).
Definition comp (X:distributive) :=
Comp.Pack (ob X) (hom X) (comp_mixin X).
Definition category (X:distributive) : category :=
Category (ob X) (hom X) (eq_mixin X) (comp_mixin X) (cat_axioms X).
Definition terminated (X:distributive) : terminated :=
Terminated (ob X) (hom X) (eq_mixin X) (comp_mixin X) (cat_axioms X) (terminated_mixin X).
Definition cartesian (X:distributive) : cartesian :=
Cartesian (ob X) (hom X) (eq_mixin X) (comp_mixin X) (cat_axioms X)
(terminated_mixin X) (cartesian_mixin X).
Definition initialized (X:distributive) : initialized :=
Initialized (ob X) (hom X) (eq_mixin X) (comp_mixin X) (cat_axioms X) (initialized_mixin X).
Definition cocartesian (X:distributive) : cocartesian :=
Cocartesian (ob X) (hom X) (eq_mixin X) (comp_mixin X) (cat_axioms X)
(initialized_mixin X) (cocartesian_mixin X).
End Distributive.
Notation distributive := Distributive.distributive.