-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAPG_old.v
1486 lines (1318 loc) · 58.4 KB
/
APG_old.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
(* Coq Formalization of Algebraic Property Graphs, by Ryan Wisnesky. *)
Open Scope type_scope.
Set Implicit Arguments.
Require Import JMeq FunctionalExtensionality
ProofIrrelevance Logic.ClassicalEpsilon Setoid.
(* Helper functions ****************************************)
Lemma FnHelper {X Y} (x:X) {P Q:X->Y}
(pf: (fun x => P x) = (fun x => Q x)) : P x = Q x.
Proof.
refine (match pf in _ = y return P x = y x with
| refl_equal => refl_equal
end).
Qed.
Lemma ExPfIrr {X} {Q:X->Prop} (h1 h2 : { x | Q x } )
: (proj1_sig h1 = proj1_sig h2) -> h1 = h2.
Proof.
intros pf. destruct h1,h2;simpl in *. subst. f_equal.
apply proof_irrelevance.
Qed.
Lemma ExistTHelper {A T} a t a0 t0 :
a = a0 -> JMeq t t0 -> @existT A T a t = @existT A T a0 t0.
Proof.
intros pf. subst. intros pf. f_equal. auto. apply JMeq_eq. auto.
Qed.
Lemma EqDecAx {X} (x1 x2 : X) : {x1 = x2} + {x1 <> x2}.
Proof.
apply excluded_middle_informative.
Qed.
Record Quotient {T} {R: T->T->Prop} (pfA : equivalence T R) := mkQuo {
Quo : Type;
eqc : T -> Quo;
repr: Quo -> T;
pfResp1 : forall {a b}, R a b -> eqc a = eqc b;
pfResp2 : forall {p q}, eqc p = eqc q -> R p q;
pfSurj : forall q, eqc (repr q) = q;
pfMake : forall {X} (f: T -> X) (pf: forall t1 t2, R t1 t2 -> f t1 = f t2), Quo -> X ;
pfProp : forall {X} (f: T -> X) (pf: forall t1 t2, R t1 t2 -> f t1 = f t2)
(x:T) , (pfMake f pf (eqc x)) = f x;
}.
Definition mapQ {T1 T2 R1 R2} {pf1: equivalence T1 R1} {pf2: equivalence T2 R2}
(Q1 : Quotient pf1) (Q2 : Quotient pf2) (f: T1 -> T2)
(pf: forall x y, R1 x y -> R2 (f x) (f y)) : Quo Q1 -> Quo Q2.
apply (pfMake Q1 (fun x => eqc Q2 (f x)) (fun x y pf0 => pfResp1 Q2 (pf x y pf0) )).
Defined.
Axiom axiomQ : forall {T} {R:T->T->Prop} {pf: equivalence T R}, Quotient pf.
(* Category Theory ************************************************* *)
Record Category : Type := newCategory {
ob : Type;
hom : ob -> ob -> Type;
Id : forall {x}, hom x x;
Comp : forall {x y z}, hom x y -> hom y z -> hom x z;
catId1 : forall {x y} (f : hom x y), (Comp Id f) = f;
catId2 : forall {x y} (f : hom x y), Comp f Id = f;
catComp : forall {w x y z}
(f: hom w x) g (h: hom y z), Comp f (Comp g h) = Comp (Comp f g) h;
}.
Definition Ob {C} := ob C.
Definition Hom {C} x y := hom C x y.
Definition id {C} x := @Id C x.
Definition comp {C} {x y z : ob C} (f: Hom x y) (g: Hom y z) := Comp C f g.
Definition terminal {C} (x: ob C) := forall a, exists! (f: Hom a x), True.
Definition initial {C} (x: ob C) := forall a, exists! (f: Hom x a), True.
Definition product {C} (X1 X2 X: ob C) (p1 : Hom X X1) (p2 : Hom X X2) :=
forall Y (f1 : Hom Y X1) (f2 : Hom Y X2),
exists! (f: Hom Y X), comp f p1 = f1 /\ comp f p2 = f2.
Definition coproduct {C} (X1 X2 X: ob C) (i1 : Hom X1 X) (i2 : Hom X2 X) :=
forall Y (f1 : Hom X1 Y) (f2 : Hom X2 Y),
exists! (f: Hom X Y), comp i1 f = f1 /\ comp i2 f = f2.
Definition coequalizer {C} (X Y: ob C) (f g: Hom X Y) Q (q : Hom Y Q) := comp f q = comp g q /\
forall Q0 (q0 : Hom Y Q0), comp f q0 = comp g q0 ->
exists! (u: Hom Q Q0), comp q u = q0.
Definition equalizer {C} (X Y: ob C) (f g: Hom Y X) Q (q : Hom Q Y) := comp q f = comp q g /\
forall Q0 (q0 : Hom Q0 Y), comp q0 f = comp q0 g ->
exists! (u: Hom Q0 Q), comp u q = q0.
(* Functors *****************************)
Record Functor C D := newFunctor {
ApplyO : ob C -> ob D;
ApplyF : forall {x y}, hom C x y -> hom D (ApplyO x) (ApplyO y);
funId : forall {x}, ApplyF (id x) = id (ApplyO x);
funComp : forall {x y z} (f: hom C x y) (g: hom C y z),
ApplyF (comp f g) = comp (ApplyF f) (ApplyF g);
}.
Definition applyF {C D} (F: Functor C D) {x y} := @ApplyF C D F x y.
Definition applyO {C D} (F: Functor C D) := @ApplyO C D F .
Definition IdFunctor C : Functor C C. refine (
newFunctor C C (fun x => x) (fun x y f => f) _ _); auto.
Defined.
Definition CompFunctor {C D E} (F: Functor C D) (G: Functor D E) : Functor C E.
refine (newFunctor C E (fun x => applyO G (applyO F x))
(fun _ _ f => applyF G (applyF F f)) _ _).
destruct F,G; compute in *; congruence.
destruct F,G; compute in *; congruence.
Defined.
(* Natural Transformations *****************************)
Record Transform {C D} (F G : Functor C D) := newTransform {
component : forall x, Hom (applyO F x) (applyO G x);
natural : forall {x y} (f : hom C x y),
comp (component x) (applyF G f) = comp (applyF F f) (component y);
}.
Definition Component {C D} {F G : Functor C D} x := @component C D F G x.
Lemma TransPfIrr {C D} {F G : Functor C D} (h1 h2 : Transform F G)
: (Component h1 = Component h2) -> h1 = h2.
Proof.
intros pf. destruct h1,h2;simpl in *. subst. f_equal. apply proof_irrelevance.
Qed.
Definition IdTrans {C D} (F: Functor C D) : Transform F F.
refine (newTransform F F (fun c => id (applyO F c)) _). intros.
unfold comp. rewrite (@catId1 D). rewrite (@catId2 D). constructor.
Defined.
Definition CompTrans {C D} {F G H: @Functor C D}
(h1 : Transform F G) (h2: Transform G H) : Transform F H.
refine (newTransform F H (fun c => comp (Component h1 c) (Component h2 c)) _).
intros. unfold comp.
rewrite (@catComp D). rewrite <- (natural h1).
rewrite <- (catComp D). rewrite (natural h2). rewrite (@catComp D).
constructor.
Defined.
(* Examples *****************************)
Definition SET : Category. refine (newCategory (fun x y => x -> y)
(fun x => fun y:x => y) (fun x y z f g a => g (f a)) _ _ _).
constructor. constructor. constructor.
Defined.
Definition CSet (C: Category) : Category.
refine (@newCategory (Functor C SET) (Transform) IdTrans (@CompTrans C SET) _ _ _);
intros; try apply TransPfIrr; try apply PI; simpl in *;
apply functional_extensionality_dep ; intros;
apply functional_extensionality_dep; intros; auto.
Defined.
Theorem SetInitial : @initial SET Empty_set.
Proof.
intros a. exists (fun x : Empty_set => match x with end).
split; auto. intros. apply functional_extensionality_dep.
intros x; elim x; auto.
Qed.
Theorem SetTerminal : @terminal SET unit.
Proof.
intros a. exists (fun x => tt).
split; auto. intros. apply functional_extensionality_dep.
intros x; destruct (x' x); auto.
Qed.
Theorem SetProduct {X1 X2} : @product SET X1 X2 (X1 * X2) fst snd.
Proof.
intros X. intros. exists (fun x => (f1 x, f2 x)).
unfold unique. split; simpl; auto. intros f pf.
apply functional_extensionality_dep.
intros x. destruct pf. subst. destruct (f x). simpl. auto.
Qed.
Theorem SetCoProduct {X1 X2} : @coproduct SET X1 X2 (X1 + X2) (@inl X1 X2) (@inr X1 X2).
Proof.
intros X. intros. exists (fun x => match x with inl y => f1 y | inr y => f2 y end).
unfold unique. split; simpl; auto. intros f pf. destruct pf.
apply functional_extensionality_dep.
intros x. subst. destruct x; auto.
Qed.
Definition EqualizerHelper {Y Z} (f : Y -> Z) (g : Y -> Z) Q0
(q0 : Q0 -> Y) : forall
(pf:(fun a : Q0 => f (q0 a)) = (fun a : Q0 => g (q0 a))) (u : Q0),
{y : Y | f y = g y}.
intros pf q. exists (q0 q). simpl. refine (
match pf in _ = y return f (q0 q) = y q with
| refl_equal => refl_equal
end
).
Defined.
Theorem SetEqualizer {X Y} (f g : Hom Y X)
: @equalizer SET X Y f g { y:Y | f y = g y} (fun x => proj1_sig x).
Proof.
split. simpl. apply functional_extensionality_dep. intros. destruct x; auto.
intros. simpl in *.
exists (EqualizerHelper f g q0 H). split. split. intros u pf.
compute. apply functional_extensionality_dep. intros q0'.
apply ExPfIrr. simpl. subst. auto.
Qed.
Inductive Lift {S T:Type} (f g : S -> T) : T -> T -> Prop :=
| LiftRefl : forall {t}, Lift f g t t
| LiftSym : forall {t1 t2}, Lift f g t1 t2 -> Lift f g t2 t1
| LiftTrans: forall {t1 t2 t3}, Lift f g t1 t2 -> Lift f g t2 t3 -> Lift f g t1 t3
| LiftInj : forall {s}, Lift f g (f s) (g s).
Lemma LiftEquiv {S T:Type} (f g : S -> T) : equivalence _ (Lift f g).
Proof.
split; compute; intros. constructor. exact (LiftTrans H H0). exact (LiftSym H).
Qed.
Definition quotient {S T} (f g : S -> T) := Quo (@axiomQ _ (Lift f g) (LiftEquiv f g)).
Definition Eqc {S T} (f g : S -> T) := eqc (@axiomQ _ (Lift f g) (LiftEquiv f g)).
Definition Repr {S T} (f g : S -> T) := repr (@axiomQ _ (Lift f g) (LiftEquiv f g)).
Theorem SetCoEq {X Y} f g
: @coequalizer SET X Y f g (quotient f g) (Eqc f g).
Proof.
split. apply functional_extensionality_dep.
intros x. compute in *. destruct (axiomQ ). apply pfResp3. apply LiftInj.
intros. exists ( @comp SET _ _ _ (Repr f g) q0 ).
split.
apply functional_extensionality_dep. intros y.
rewrite (catComp SET). simpl in *.
unfold Repr,Eqc.
destruct (axiomQ). simpl.
induction (@pfResp4 (repr0 (eqc0 y)) y).
auto. etransitivity; eauto. congruence.
symmetry. change ((fun a : X => q0 (g a)) s = q0 (f s)).
rewrite <- H. reflexivity. auto.
intros u pf. subst. simpl in *.
unfold Repr,Eqc,quotient in *. compute in *. destruct (axiomQ ).
apply functional_extensionality_dep. intros q.
f_equal. apply pfSurj0.
Qed.
(* Algebraic Property Graphs ******************************************)
Section APG.
Variable B : Type.
Variable P : B -> Type.
Inductive Ty L :=
| Zero : Ty L
| One : Ty L
| Plus : Ty L -> Ty L -> Ty L
| Times : Ty L -> Ty L -> Ty L
| Base : B -> Ty L
| Label : L -> Ty L.
Inductive Term {E L} (lam : E -> L) : Ty L -> Type :=
| ID : forall e, Term lam (Label (lam e))
| Prim: forall b (c: P b), Term lam (Base _ b)
| Tt : Term lam (One _)
| Pair: forall {t t'}, Term lam t -> Term lam t' -> Term lam (Times t t')
| Inl : forall {t t'}, Term lam t -> Term lam (Plus t t')
| Inr : forall {t t'}, Term lam t'-> Term lam (Plus t t').
Fixpoint MapTy {L1 L2} (f: L1 -> @Ty L2) (ty: @Ty L1) : @Ty L2 :=
match ty with
| Zero _ => Zero _
| One _ => One _
| Plus a b => Plus (MapTy f a) (MapTy f b)
| Times a b => Times (MapTy f a) (MapTy f b)
| Label l => f l
| Base _ b => Base _ b
end.
Fixpoint MapTerm {E1 L1} {lam1 : E1 -> L1} {E2 L2} {lam2 : E2 -> L2}
(g : L1 -> Ty L2) (h : forall (e:E1), Term lam2 (g (lam1 e)))
{ty} (term: Term lam1 ty) : Term lam2 (MapTy g ty) :=
match term with
| ID _ e => h e
| Prim _ c => Prim lam2 c
| Tt _ => Tt _
| Pair x y => Pair (MapTerm g h x) (MapTerm g h y)
| Inl x => Inl (MapTerm g h x)
| Inr y => Inr (MapTerm g h y)
end.
Definition mapTy {L1 L2} (f: L1 -> L2) (ty: @Ty L1) : @Ty L2
:= MapTy (fun x => Label (f x)) ty.
Definition mapTerm {E1 L1} {lam1 : E1 -> L1} {E2 L2} {lam2 : E2 -> L2}
(f : L1 -> L2) (g : E1 -> E2) (pfNat : forall e, f (lam1 e) = lam2 (g e))
: forall {ty} (x:Term lam1 ty) , Term lam2 (mapTy f ty).
refine (fix mapTerm {ty} term := match term with
| ID _ e => _
| Prim _ c => Prim lam2 c
| Tt _ => Tt _
| Pair x y => Pair (mapTerm x) (mapTerm y)
| Inl x => Inl (mapTerm x)
| Inr y => Inr (mapTerm y)
end). simpl. pose (ID lam2 (g e)). rewrite <- (pfNat e) in t. exact t.
Defined.
Record APG := newAPG {
L : Type;
sigma : L -> Ty L;
E : Type;
lam : E -> L;
phi : forall e, Term lam (sigma (lam e));
}.
(* Morphisms of APGs **********************************************)
Record APGMorphism (G1 G2: APG) := newAPGMorphism {
lMap : L G1 -> L G2 ;
eMap : E G1 -> E G2 ;
pfNat : forall e, lMap (lam G1 e) = lam G2 (eMap e);
}.
Lemma APGMorphismEq (G1 G2: APG) (h1 h2 : APGMorphism G1 G2) :
lMap h1 = lMap h2 -> eMap h1 = eMap h2 -> h1 = h2.
Proof.
intros pf1 pf2. destruct h1,h2; simpl in *. subst. f_equal. apply proof_irrelevance.
Qed.
Definition TransHelper1 G H (j k:APGMorphism G H) e0 : eMap j e0 =
eMap k e0 -> lMap j (lam G e0) =
lMap k (lam G e0).
intros pf. rewrite (pfNat j e0) . rewrite (pfNat k e0) .
rewrite pf. auto.
Defined.
Definition IdApgMorphism G : APGMorphism G G.
refine (newAPGMorphism G G (fun l => l) (fun e => e) (fun e => refl_equal _)).
Defined.
Definition ApgMorphismCompose {G1 G2 G3} (F: APGMorphism G1 G2) (G: APGMorphism G2 G3) : APGMorphism G1 G3.
refine (newAPGMorphism G1 G3 (fun l => lMap G (lMap F l)) (fun e => eMap G (eMap F e)) _).
intros e. destruct F,G. simpl. rewrite pfNat0. rewrite pfNat1. reflexivity.
Defined.
Definition APGInst : Category.
refine (@newCategory APG APGMorphism IdApgMorphism (@ApgMorphismCompose) _ _ _).
intros. unfold IdApgMorphism,ApgMorphismCompose. destruct f. simpl. f_equal. apply proof_irrelevance.
intros. unfold IdApgMorphism,ApgMorphismCompose. destruct f. simpl. f_equal. apply proof_irrelevance.
intros. unfold IdApgMorphism,ApgMorphismCompose. destruct f,g,h. simpl in *. f_equal. apply proof_irrelevance.
Defined.
Lemma lemma1 {X Y}
(f g : Hom Y X)
(Q0 : ob APGInst)
(q0 : Hom Q0 Y)
(pf : comp q0 f = comp q0 g)
(l : L Q0)
(pfNq : lMap f (lMap q0 l) <>
lMap g (lMap q0 l)) : False.
Proof.
destruct f,g; simpl in *. unfold ApgMorphismCompose in *. simpl in *.
inversion pf. pose (FnHelper l H0). contradiction.
Qed.
Lemma lemma2 {X Y}
(f g : Hom Y X)
(Q0 : ob APGInst)
(q0 : Hom Q0 Y)
(pf : comp q0 f = comp q0 g)
(e : E Q0)
(pfNq : eMap f (eMap q0 e) <>
eMap g (eMap q0 e)) : False.
Proof.
destruct f,g; simpl in *. unfold ApgMorphismCompose in *. simpl in *.
inversion pf. pose (FnHelper e H1). contradiction.
Qed.
(* Constructions on APGs ******************************************)
Definition InitialAPG : APG := @newAPG Empty_set (fun x => match x with end)
Empty_set (fun x => match x with end) (fun x => match x with end).
Definition InitialAPGMorphism (G: APG) : APGMorphism InitialAPG G.
refine (newAPGMorphism InitialAPG G
(fun x => match x with end) (fun x => match x with end) _).
intros. elim e.
Defined.
Theorem APGInstInitial : @initial APGInst InitialAPG.
Proof.
intros a. exists (InitialAPGMorphism a).
split; auto. intros. apply APGMorphismEq.
apply functional_extensionality_dep. intros x; elim x.
apply functional_extensionality_dep. intros x; elim x.
Qed.
Definition TerminalAPG : APG := @newAPG unit (fun x => One _)
unit (fun x => tt) (fun x => Tt _).
Definition TerminalAPGMorphism (G: APG) : APGMorphism G TerminalAPG.
refine (newAPGMorphism G TerminalAPG (fun x => tt) (fun x => tt) _).
intros. auto.
Defined.
Theorem APGInstTerminal : @terminal APGInst TerminalAPG.
Proof.
intros a. exists (TerminalAPGMorphism a).
split; auto. intros h. intros pf; clear pf. apply APGMorphismEq.
apply functional_extensionality_dep. intros l.
unfold TerminalAPG,TerminalAPGMorphism;simpl.
match goal with [ _ : _ |- tt = ?x ] => destruct x end. auto.
unfold TerminalAPG,TerminalAPGMorphism;simpl.
apply functional_extensionality_dep. intros e.
match goal with [ _ : _ |- tt = ?x ] => destruct x end. auto.
Qed.
Definition CoProductAPG (G1 G2 : APG) : APG.
refine (@newAPG
(L G1 + L G2)
(fun l => match l with
| inl a => mapTy inl (sigma G1 a)
| inr b => mapTy inr (sigma G2 b)
end)
(E G1 + E G2)
(fun l => match l with
| inl a => inl (lam G1 a)
| inr b => inr (lam G2 b)
end)
(fun e => match e with
| inl a => mapTerm inl inl _ (phi G1 a)
| inr b => mapTerm inr inr _ (phi G2 b)
end)); auto.
Defined.
Definition InlAPGMorphism (G1 G2: APG)
: APGMorphism G1 (CoProductAPG G1 G2).
refine (newAPGMorphism G1 (CoProductAPG G1 G2) (inl) (inl) _).
intros. auto.
Defined.
Definition InrAPGMorphism (G1 G2: APG)
: APGMorphism G2 (CoProductAPG G1 G2).
refine (newAPGMorphism G2 (CoProductAPG G1 G2) (inr) (inr) _).
intros. auto.
Defined.
Definition APGCoproduct (X1 X2: APG)
Y (f1 : APGMorphism X1 Y) (f2 : APGMorphism X2 Y)
: APGMorphism (CoProductAPG X1 X2) Y.
refine (newAPGMorphism (CoProductAPG X1 X2) Y (fun l => match l with
| inl a => lMap f1 a
| inr b => lMap f2 b
end) (fun e => match e with
| inl a => eMap f1 a
| inr b => eMap f2 b
end) _). intros. destruct e; simpl. destruct f1. auto. destruct f2. auto.
Defined.
Theorem APGHasCoProducts {X1 X2} : @coproduct APGInst X1 X2 (CoProductAPG X1 X2) (InlAPGMorphism X1 X2) (InrAPGMorphism X1 X2).
intros X. intros. exists (@APGCoproduct X1 X2 X f1 f2).
split. split.
apply APGMorphismEq. auto. auto.
apply APGMorphismEq. auto. auto.
intros f pf. destruct pf as [pf1 pf2].
subst. simpl. destruct f,X1,X2,X; compute in *.
apply APGMorphismEq. simpl in *. apply functional_extensionality_dep. intros x; destruct x; auto.
simpl in *. apply functional_extensionality_dep. intros x; destruct x; auto.
Qed.
Definition ProductAPG (G1 G2 : APG) : APG.
refine (@newAPG
(L G1 * L G2)
(fun l => match l with
| (a, b) => Times (mapTy (fun x => (x, b)) (sigma G1 a))
(mapTy (fun x => (a, x)) (sigma G2 b))
end)
(E G1 * E G2)
(fun l => match l with
| (a, b) => (lam G1 a, lam G2 b)
end)
(fun e => match e with
| (a, b) => Pair
(mapTerm _ (fun x => (x, b)) _ (phi G1 a))
(mapTerm _ (fun x => (a, x)) _ (phi G2 b))
end)); auto.
Defined.
Definition FstAPGMorphism (G1 G2: APG)
: APGMorphism (ProductAPG G1 G2) G1.
refine (newAPGMorphism (ProductAPG G1 G2) G1 fst fst _).
intros. destruct e. compute. auto.
Defined.
Definition SndAPGMorphism (G1 G2: APG)
: APGMorphism (ProductAPG G1 G2) G2.
refine (newAPGMorphism (ProductAPG G1 G2) G2 snd snd _).
intros. destruct e. compute. auto.
Defined.
Definition APGProduct (X1 X2: APG)
Y (f1 : APGMorphism Y X1) (f2 : APGMorphism Y X2)
: APGMorphism Y (ProductAPG X1 X2).
refine (newAPGMorphism Y (ProductAPG X1 X2)
(fun l => (lMap f1 l, lMap f2 l))
(fun e => (eMap f1 e, eMap f2 e))
_). intros. simpl. f_equal. destruct f1. simpl. auto.
destruct f2. simpl. auto.
Defined.
Theorem APGHasProducts {X1 X2} : @product APGInst X1 X2 (ProductAPG X1 X2) (FstAPGMorphism X1 X2) (SndAPGMorphism X1 X2).
Proof.
intros X. intros. exists (@APGProduct X1 X2 X f1 f2).
split. split.
apply APGMorphismEq. auto. auto.
apply APGMorphismEq. auto. auto.
intros f pf. destruct pf as [pf1 pf2].
subst. simpl. destruct f,X1,X2,X; compute in *.
apply APGMorphismEq. simpl in *. apply functional_extensionality_dep.
intros x. destruct (lMap0 x). auto.
simpl in *. apply functional_extensionality_dep. intros x.
destruct (eMap0 x); auto.
Qed.
Definition EqualizerAPG {G H : APG} (j k : APGMorphism G H) : APG.
refine (@newAPG
{ l : L G | lMap j l = lMap k l }
(fun l => match l with
| exist _ l0 pf => MapTy (fun l1 =>
match EqDecAx (lMap j l1) (lMap k l1) with
| left pfEq => Plus (One _) (Label (exist _ l1 pfEq))
| right pfEq => One _
end) (sigma G l0)
end)
{ e : E G | eMap j e = eMap k e }
(fun e => match e with
| exist _ e0 pf => exist _ (lam G e0) (TransHelper1 j k e0 pf)
end)
(fun e => match e with
| exist _ e0 pf => MapTerm (fun l1 =>
match EqDecAx (lMap j l1) (lMap k l1) with
| left pfEq => Plus (One _) (Label (exist _ l1 pfEq))
| right pfEq => One _
end)
(fun e1 => match EqDecAx (eMap j e1) (eMap k e1) with
| left pfEq => _
| right pfEq => _ end ) (phi G e0)
end)
).
pose (TransHelper1 j k e1 pfEq).
pose (ID (fun
e2 : {e2 : E G |
eMap j e2 = eMap k e2}
=>
let (e3, pf0) := e2 in
exist
(fun l : L G =>
lMap j l = lMap k l)
(lam G e3)
(TransHelper1 j k e3 pf0)) (exist _ e1 pfEq)).
destruct ( EqDecAx (lMap j (lam G e1))
(lMap k (lam G e1)) ).
assert ((TransHelper1 j k e1 pfEq) = e3). apply proof_irrelevance. rewrite <- H0. exact (Inr t).
contradiction.
destruct ( EqDecAx (lMap j (lam G e1))
(lMap k (lam G e1)) ). apply Inl. apply Tt. apply Tt.
Defined.
Definition EqualizerAPGMorphism {G H : APG} (j k : APGMorphism G H)
: APGMorphism (EqualizerAPG j k) G.
refine (newAPGMorphism (EqualizerAPG j k) G
(fun l => proj1_sig l) (fun e => proj1_sig e) _).
intros. destruct e. simpl in *. auto.
Defined.
Definition ApgEqualizerHelper {X Y} (f g : Hom Y X)
(Q0 : ob APGInst) (q0 : Hom Q0 Y) (pf : comp q0 f = comp q0 g)
: Hom Q0 (EqualizerAPG f g).
refine (newAPGMorphism Q0 (EqualizerAPG f g)
(fun l => match EqDecAx (lMap f (lMap q0 l)) (lMap g (lMap q0 l)) with
| left pfEq => exist _ (lMap q0 l) pfEq
| right pfNq => match lemma1 pf l pfNq with end
end) (fun e => match EqDecAx (eMap f (eMap q0 e)) (eMap g (eMap q0 e)) with
| left pfEq => exist _ (eMap q0 e) pfEq
| right pfNq => match lemma2 pf e pfNq with end
end) _).
intros. destruct f,g; simpl in *.
unfold ApgMorphismCompose in *. simpl in *.
inversion pf. simpl in *.
destruct X,Y,q0,Q0; compute in *.
pose (FnHelper e H1). pose (FnHelper (lam2 e) H0).
simpl in *. destruct ( EqDecAx (lMap0 (lMap2 (lam2 e)))
(lMap1 (lMap2 (lam2 e))) ). simpl in *.
apply ExPfIrr. simpl. destruct (EqDecAx (eMap0 (eMap2 e))
(eMap1 (eMap2 e))). simpl. auto.
simpl. contradiction. simpl. contradiction.
Defined.
Theorem APGHasEqualizers {X Y} f g : @equalizer APGInst X Y f g
(EqualizerAPG f g) (EqualizerAPGMorphism f g).
Proof.
split. simpl. unfold EqualizerAPGMorphism,ApgMorphismCompose.
apply APGMorphismEq. simpl. apply functional_extensionality.
intros l0; destruct l0; simpl in *; auto.
simpl. apply functional_extensionality.
intros l0; destruct l0; simpl in *; auto.
intros Q0 q0 pf. exists (ApgEqualizerHelper pf).
destruct f,g. unfold ApgMorphismCompose in *.
unfold comp in *. unfold Comp in *. simpl in *. inversion pf. split.
apply APGMorphismEq. simpl. apply functional_extensionality.
intros l. pose (FnHelper l H0).
simpl in *. destruct ( EqDecAx (lMap0 (lMap q0 l))
(lMap1 (lMap q0 l)) ). simpl in *. auto.
contradiction. simpl in *.
apply functional_extensionality.
intros e. pose (FnHelper e H1). destruct ( EqDecAx (eMap0 (eMap q0 e))
(eMap1 (eMap q0 e)) ). simpl in *. auto.
simpl in *. contradiction.
intros u pf2. apply APGMorphismEq. simpl. apply functional_extensionality.
intros l. pose (FnHelper l H0).
simpl in *. destruct ( EqDecAx (lMap0 (lMap q0 l))
(lMap1 (lMap q0 l)) ). apply ExPfIrr. simpl.
subst. simpl in *. auto. contradiction.
simpl in *. apply functional_extensionality.
intros e. pose (FnHelper e H1). destruct ( EqDecAx (eMap0 (eMap q0 e))
(eMap1 (eMap q0 e)) ). simpl in *. apply ExPfIrr. simpl in *.
subst. simpl in *. auto. contradiction.
Qed.
(*******************************************************************)
(* For co-equalizers, we specialize the definitions. *)
Section coeq.
Variable sL : Type.
Variable ssigma : sL -> Ty sL.
Record sAPG := newsAPG {
sE : Type;
slam : sE -> sL;
sphi : forall e, Term slam (ssigma (slam e));
}.
Record sAPGMorphism (G1 G2: sAPG) := newsAPGMorphism {
seMap : sE G1 -> sE G2 ;
spfNat : forall e, (slam G1 e) = slam G2 (seMap e)
}.
Lemma sAPGMorphismEq (G1 G2: sAPG) (h1 h2 : sAPGMorphism G1 G2) :
seMap h1 = seMap h2 -> h1 = h2.
Proof.
intros pf1. destruct h1,h2; simpl in *. subst. f_equal. apply proof_irrelevance.
Qed.
Definition IdsApgMorphism G : sAPGMorphism G G.
refine (newsAPGMorphism G G (fun e => e) (fun e => refl_equal _)).
Defined.
Definition sApgMorphismCompose {G1 G2 G3} (F: sAPGMorphism G1 G2) (G: sAPGMorphism G2 G3) : sAPGMorphism G1 G3.
refine (newsAPGMorphism G1 G3 (fun e => seMap G (seMap F e)) _).
intros e. destruct F,G. simpl. rewrite spfNat0. rewrite spfNat1. reflexivity.
Defined.
Definition sAPGInst : Category.
refine (@newCategory sAPG sAPGMorphism IdsApgMorphism (@sApgMorphismCompose) _ _ _).
intros. unfold IdsApgMorphism,sApgMorphismCompose. destruct f. simpl. f_equal. apply proof_irrelevance.
intros. unfold IdsApgMorphism,sApgMorphismCompose. destruct f. simpl. f_equal. apply proof_irrelevance.
intros. unfold IdsApgMorphism,sApgMorphismCompose. destruct f,g,h. simpl in *. f_equal. apply proof_irrelevance.
Defined.
Definition mapTermAlt {E1} {lam1 : E1 -> sL} {E2}
(g : E1 -> E2) : forall
{ty} (x:Term lam1 ty) (lam2 : E2 -> sL)
(pfNat : forall e, (lam1 e) = lam2 (g e)) , Term lam2 ty.
refine (fix mapTermAlt {ty} term lam2 pf := match term with
| ID _ e => _
| Prim _ c => Prim _ c
| Tt _ => Tt _
| Pair x y => Pair (mapTermAlt x lam2 pf) (mapTermAlt y lam2 pf)
| Inl x => Inl (mapTermAlt x lam2 pf)
| Inr y => Inr (mapTermAlt y lam2 pf)
end). simpl. pose (ID lam2 (g e)). rewrite <- (pf e) in t. exact t.
Defined.
Definition CoEqualizersAPG {G1 G2} (j k : sAPGMorphism G1 G2)
(pf: forall x y, Lift (seMap j) (seMap k) x y -> slam G2 x = slam G2 y) : sAPG.
refine (@newsAPG (quotient (seMap j) (seMap k))
(fun e => slam G2 (Repr _ _ e)) (fun e => _ (sphi G2 (Repr _ _ e)))).
intros a.
apply (@mapTermAlt (sE G2) (slam G2) (quotient (seMap j) (seMap k)) (fun x => Eqc _ _ x) (ssigma (slam G2 (Repr _ _ e))) a (fun e => slam G2 (Repr _ _ e))).
intros x. apply pf. unfold Repr,Eqc,quotient in *.
destruct ( (axiomQ
)). simpl in *. apply pfResp4. auto.
Defined.
Definition CoEqualizersAPGMorphism {G1 G2} (j k : sAPGMorphism G1 G2)
(pf: forall x y, Lift (seMap j) (seMap k) x y -> slam G2 x = slam G2 y)
: sAPGMorphism G2 (CoEqualizersAPG j k pf).
destruct j,k,G2. refine (newsAPGMorphism _ (CoEqualizersAPG
{|
seMap := seMap0;
spfNat := spfNat0 |}
{|
seMap := seMap1;
spfNat := spfNat1 |} pf) (fun e => Eqc _ _ e) _).
compute in *.
destruct ( (axiomQ )). simpl in *.
intros e. apply pf. auto.
Defined.
Definition ApgCoEqualizerHelper
{G1 G2}
(j k : sAPGMorphism G1 G2)
(pf : forall x y : sE G2,
Lift (seMap j)
(seMap k) x y ->
slam G2 x = slam G2 y)
{Q0}
(q0 : sAPGMorphism G2 Q0)
(H : sApgMorphismCompose j q0 =
sApgMorphismCompose k q0)
: hom sAPGInst (CoEqualizersAPG j k pf) Q0.
refine (newsAPGMorphism (CoEqualizersAPG j k pf) Q0 (fun e => seMap q0 (Repr _ _ e)) _).
destruct j,k,q0,Q0. compute in *. destruct ( (axiomQ )).
intros q. apply spfNat2.
Defined.
Theorem APGHasCoEqualizers {G1 G2}
(j k : sAPGMorphism G1 G2)
(pf3: forall x y, Lift (seMap j) (seMap k) x y -> slam G2 x = slam G2 y)
: @coequalizer sAPGInst _ _ j k
(CoEqualizersAPG j k pf3) (CoEqualizersAPGMorphism j k pf3).
Proof.
split.
apply sAPGMorphismEq. apply functional_extensionality. intros e.
destruct j,k,G1,G2. compute in *.
destruct ( (axiomQ )).
apply pfResp3. apply LiftInj.
simpl in *. intros. exists (@ApgCoEqualizerHelper G1 G2 j k pf3 Q0 q0 H). split.
destruct j,k,q0,Q0,G1,G2. compute in *.
destruct ( (axiomQ )).
compute in *. apply sAPGMorphismEq. simpl in *.
inversion H; clear H. apply functional_extensionality_dep. intros e.
induction (pfResp4 e (repr0 (eqc0 e))). auto. auto. congruence. symmetry. apply (FnHelper s H1). auto.
intros u pf. destruct j,k,q0,Q0,G1,G2,u. compute in *.
destruct ( (axiomQ )).
inversion H; clear H.
inversion pf; clear pf. subst.
apply sAPGMorphismEq. simpl in *.
apply functional_extensionality_dep. intros q.
rewrite (pfSurj0 q). auto.
Qed.
End coeq.
(* The Commutative Square Category ********************************* *)
Inductive CD_O : Type := EE | TT | LL | VV.
Inductive CD_A : CD_O -> CD_O -> Type := | EEEE : CD_A EE EE | EEVV : CD_A EE VV | TTTT : CD_A TT TT | LLLL : CD_A LL LL | VVVV : CD_A VV VV | EELL : CD_A EE LL | LLTT : CD_A LL TT | VVTT : CD_A VV TT | EETT : CD_A EE TT.
Definition CD_id x: CD_A x x := match x as x return CD_A x x with | EE => EEEE | TT => TTTT | LL => LLLL | VV => VVVV end.
Definition CD_o1 x : forall z y (f: CD_A x y) (g: CD_A y z), CD_A x z.
refine (match x as x return forall z y (f: CD_A x y) (g: CD_A y z), CD_A x z with
| EE => fun z => match z as z return forall y (f: CD_A EE y) (g: CD_A y z), CD_A EE z with | EE => fun y f g => EEEE | TT => fun y f g => EETT | LL => fun y f g => EELL | VV => fun y f g => EEVV end
| TT => fun z => match z as z return forall y (f: CD_A TT y) (g: CD_A y z), CD_A TT z with | EE => fun y f g => _ | TT => fun y f g => TTTT | LL => fun y f g => _ | VV => fun y f g => _ end
| LL => fun z => match z as z return forall y (f: CD_A LL y) (g: CD_A y z), CD_A LL z with | EE => fun y f g => _ | TT => fun y f g => LLTT | LL => fun y f g => LLLL | VV => fun y f g => _ end
| VV => fun z => match z as z return forall y (f: CD_A VV y) (g: CD_A y z), CD_A VV z with | EE => fun y f g => _ | TT => fun y f g => VVTT | LL => fun y f g => _ | VV => fun y f g => VVVV end
end); destruct y; inversion f; try auto; inversion g; try auto.
Defined.
Definition CD_o x y z (f: CD_A x y) (g: CD_A y z) : CD_A x z := CD_o1 f g.
Definition CDCat : Category. refine (@newCategory CD_O CD_A CD_id CD_o _ _ _); intros.
destruct f; auto.
destruct f; auto.
inversion f; inversion g; inversion h;
subst; try auto; try discriminate.
Defined.
Lemma lEEEE (g : CD_A EE EE) : g = EEEE. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lLLLL (g : CD_A LL LL) : g = LLLL. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lTTTT (g : CD_A TT TT) : g = TTTT. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lVVVV (g : CD_A VV VV) : g = VVVV. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lEELL (g : CD_A EE LL) : g = EELL. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lEETT (g : CD_A EE TT) : g = EETT. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lVVTT (g : CD_A VV TT) : g = VVTT. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lLLTT (g : CD_A LL TT) : g = LLTT. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lEEVV (g : CD_A EE VV) : g = EEVV. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lVVEE (g : CD_A VV EE) : False. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lVVLL (g : CD_A VV LL) : False. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lTTEE (g : CD_A TT EE) : False. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lTTLL (g : CD_A TT LL) : False. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lLLEE (g : CD_A LL EE) : False. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lTTVV (g : CD_A TT VV) : False. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
Lemma lLLVV (g : CD_A LL VV) : False. Proof. refine (match g with | EEEE => _ | EEVV => _ | TTTT => _ | LLLL => _ | VVVV => _ | EELL => _ | LLTT => _ | VVTT => _ | EETT => _ end); compute; auto. Qed.
(* APG Morphisms as Natural Transformations *************************)
Definition APGtoFunctor (G:APG) : Functor CDCat SET. refine (
newFunctor CDCat SET
(fun x => match x with
| EE => E G
| TT => Ty (L G)
| LL => L G
| VV => sigT (Term (lam G))
end )
(fun z y f => match f with
| EEEE => fun x => x
| TTTT => fun x => x
| LLLL => fun x => x
| VVVV => fun x => x
| EEVV => fun x => existT _ _ (phi G x)
| EELL => fun x => lam G x
| LLTT => fun x => sigma G x
| VVTT => fun x => projT1 x
| EETT => fun x => sigma G (lam G x)
end) _ _).
intros. destruct x; auto.
intros. destruct x,y,z;simpl;
try (rewrite ( lEEEE g)); try (rewrite ( lLLLL g)); try (rewrite ( lTTTT g)); try (rewrite ( lVVVV g)); try (rewrite ( lEELL g)); try (rewrite ( lEETT g)); try (rewrite ( lVVTT g)); try (rewrite ( lLLTT g)); try (rewrite ( lEEVV g)); try (rewrite ( lVVEE g)); try (rewrite ( lVVLL g)); try (rewrite ( lTTEE g)); try (rewrite ( lTTLL g)); try (rewrite ( lLLEE g)); try (rewrite ( lTTVV g)); try (rewrite ( lLLVV g)); try (rewrite ( lEEEE f)); try (rewrite ( lLLLL f)); try (rewrite ( lTTTT f)); try (rewrite ( lVVVV f)); try (rewrite ( lEELL f)); try (rewrite ( lEETT f)); try (rewrite ( lVVTT f)); try (rewrite ( lLLTT f)); try (rewrite ( lEEVV f)); try (rewrite ( lVVEE f)); try (rewrite ( lVVLL f)); try (rewrite ( lTTEE f)); try (rewrite ( lTTLL f)); try (rewrite ( lLLEE f)); try (rewrite ( lTTVV f)); try (rewrite ( lLLVV f)) ; auto;
try (elim ( lEEEE g)); try (elim ( lLLLL g)); try (elim ( lTTTT g)); try (elim ( lVVVV g)); try (elim ( lEELL g)); try (elim ( lEETT g)); try (elim ( lVVTT g)); try (elim ( lLLTT g)); try (elim ( lEEVV g)); try (elim ( lVVEE g)); try (elim ( lVVLL g)); try (elim ( lTTEE g)); try (elim ( lTTLL g)); try (elim ( lLLEE g)); try (elim ( lTTVV g)); try (elim ( lLLVV g)); try (elim ( lEEEE f)); try (elim ( lLLLL f)); try (elim ( lTTTT f)); try (elim ( lVVVV f)); try (elim ( lEELL f)); try (elim ( lEETT f)); try (elim ( lVVTT f)); try (elim ( lLLTT f)); try (elim ( lEEVV f)); try (elim ( lVVEE f)); try (elim ( lVVLL f)); try (elim ( lTTEE f)); try (elim ( lTTLL f)); try (elim ( lLLEE f)); try (elim ( lTTVV f)); try (elim ( lLLVV f)).
Defined.
Definition APGInstBig : Category.
refine (
@newCategory APG
(fun x y => Transform (APGtoFunctor x) (APGtoFunctor y) )
(fun x => IdTrans (APGtoFunctor x) )
(fun x y z f g => CompTrans f g ) _ _ _ ).
intros; try apply TransPfIrr; try apply PI; simpl in *;
apply functional_extensionality_dep ; intros;
apply functional_extensionality_dep; intros; auto.
intros; try apply TransPfIrr; try apply PI; simpl in *;
apply functional_extensionality_dep ; intros;
apply functional_extensionality_dep; intros; auto.
intros; try apply TransPfIrr; try apply PI; simpl in *;
apply functional_extensionality_dep ; intros;
apply functional_extensionality_dep; intros; auto.
Defined.
(* Natural Transformations *************************************************)
Lemma ExistTHelper2 {A T} a t a0 t0 :
a = a0 -> (a = a0 -> JMeq t t0) -> @existT A T a t = @existT A T a0 t0.
Proof.
intros pf. subst. intros pf. f_equal. pose (pf (refl_equal _)).
clearbody j. clear pf. auto. apply JMeq_eq. auto.
Qed.
Lemma TyInvOne {L E} {lam1 : E -> L}
(x : Term lam1 (One L)) : x = (Tt lam1).
Proof.
refine (match x as x0 in Term _ z return z = One L -> JMeq x x0 -> x = Tt lam1 with
| ID _ e => fun pf pf2 => _
| Prim _ c => fun pf pf2 => _
| Tt _ => fun pf pf2 => _
| Pair x y => fun pf pf2 => _
| Inl x => fun pf pf2 => _
| Inr y => fun pf pf2 => _
end ( refl_equal _ ) (JMeq_refl _)); try discriminate; try auto.
apply JMeq_eq. auto.
Qed.
Lemma TyInvZero {L E} {lam1 : E -> L}
(x : Term lam1 (Zero L)) : False.
Proof.
refine (match x as x0 in Term _ z return z = Zero L -> JMeq x x0 -> False with
| ID _ e => fun pf pf2 => _
| Prim _ c => fun pf pf2 => _
| Tt _ => fun pf pf2 => _
| Pair x y => fun pf pf2 => _
| Inl x => fun pf pf2 => _
| Inr y => fun pf pf2 => _
end ( refl_equal _ ) (JMeq_refl _)); try discriminate; try auto.
Qed.
Lemma TyInvPair {L E} {lam1 : E -> L} {t1 t2}
(x : Term lam1 (Times t1 t2)) : exists a, exists b,
x = Pair a b.
Proof.
refine (match x as x0 in Term _ z return z = Times t1 t2 -> JMeq x x0 -> exists a, exists b,
x = Pair a b with
| ID _ e => fun pf pf2 => _
| Prim _ c => fun pf pf2 => _
| Tt _ => fun pf pf2 => _
| Pair x y => fun pf pf2 => _
| Inl x => fun pf pf2 => _
| Inr y => fun pf pf2 => _
end ( refl_equal _ ) (JMeq_refl _)); try discriminate; try auto.
assert (t0 = t2). injection pf. intros pf1. subst. auto.
subst. assert (t = t1). injection pf. auto. subst. clear pf.
exists x. exists y. apply JMeq_eq. auto.
Qed.
Lemma TyInvPlus {L E} {lam1 : E -> L} {t1 t2}
(x : Term lam1 (Plus t1 t2)) : (exists a, x = Inl a ) \/ (exists b, x = Inr b).
Proof.
refine (match x as x0 in Term _ z return z = Plus t1 t2 -> JMeq x x0 ->
(exists a, x = Inl a ) \/ (exists b, x = Inr b) with
| ID _ e => fun pf pf2 => _
| Prim _ c => fun pf pf2 => _
| Tt _ => fun pf pf2 => _
| Pair x y => fun pf pf2 => _
| Inl x => fun pf pf2 => _
| Inr y => fun pf pf2 => _
end ( refl_equal _ ) (JMeq_refl _)); try discriminate; try auto.
assert (t0 = t2). injection pf. intros pf1. subst. auto.
subst. assert (t = t1). injection pf. auto. subst. clear pf.
left. exists x. apply JMeq_eq. auto. right. assert (t0 = t2). injection pf. intros pf1. subst. auto.
subst. assert (t = t1). injection pf. auto. subst. clear pf.
exists y. apply JMeq_eq. auto.
Qed.
Definition APGMorphismToTransform {G1 G2:APG} (h: APGMorphism G1 G2)
(pfNatL : forall l, sigma G2 (lMap h l) = mapTy (lMap h) (sigma G1 l))
(pfNatE : forall e, mapTerm (lMap h) (eMap h) (pfNat h) (phi G1 e) =
match pfNatL (lam G1 e) in _ = y return Term (lam G2)
y with
| refl_equal => match symmetry (pfNat h e) in _ = z
return Term (lam G2) (sigma G2 z) with
| refl_equal => phi G2 (eMap h e)
end
end) : Transform (APGtoFunctor G1) (APGtoFunctor G2).
refine (@newTransform CDCat SET (APGtoFunctor G1) (APGtoFunctor G2)
(fun x => match x with
| EE => eMap h
| TT => mapTy (lMap h)
| LL => lMap h
| VV => fun v => existT _ (mapTy (lMap h) (projT1 v)) (mapTerm (lMap h) (eMap h) (pfNat h) (projT2 v) )
end) _).
intros;
destruct G1,G2,h,f; simpl in *; auto.
Focus 2. apply functional_extensionality_dep. auto.
Focus 2. apply functional_extensionality_dep. intros w. rewrite (pfNatL w). auto.
Focus 2. apply functional_extensionality_dep. intros w. rewrite <- (pfNat0 w). auto.
apply functional_extensionality_dep. intros w.
rewrite (pfNatE w). clear pfNatE. rewrite <- (pfNatL (lam0 w)).
rewrite (pfNat0 w). f_equal.
Qed.
Definition Gx1 : APG := @newAPG unit (fun x => Zero _)
Empty_set (fun x => match x with end) (fun x => match x with end).
Definition Gx2 : APG := @newAPG unit (fun x => One _)
Empty_set (fun x => match x with end) (fun x => match x with end).
Definition hx : APGMorphism Gx1 Gx2.
refine (newAPGMorphism Gx1 Gx2 (fun l => l) (fun e => match e with end) _).
intros. compute in *. elim e.
Defined.
Lemma ApgMorphismsNotNatural : exists l,
sigma Gx2 (lMap hx l) <> mapTy (lMap hx) (sigma Gx1 l).
Proof.
intros. exists tt. intros pf.
simpl in *. unfold mapTy in pf. simpl in pf. discriminate.
Qed.
(* Free BCCC ***************************************************)
Inductive term {L} {lam : L -> Ty L} : Ty L -> Ty L -> Type :=
| ELEM: forall l, term (Label l) (lam l)
| IDEN: forall {t}, term t t
| COMP: forall {s t u}, term s t -> term t u -> term s u
| PRIM: forall {b} (c: P b), term (One _) (Base _ b)
| tT : forall {t}, term t (One _)
| fF : forall {t}, term (Zero _) t
| PAIR: forall {s t t'}, term s t -> term s t'-> term s (Times t t')
| CASE: forall {s s' t }, term s t -> term s' t -> term (Plus s s') t
| INL : forall {s t }, term s (Plus s t)
| INR : forall {s t }, term t (Plus s t)
| FST : forall {s t }, term (Times s t) s
| SND : forall {s t }, term (Times s t) t.
Inductive termEq {L} {lam : L -> Ty L} : forall {a b}, @term L lam a b -> term a b -> Prop :=
| termRefl : forall {a b} (t: term a b), termEq t t
| termSym : forall {a b} (t1 t2: term a b),
termEq t1 t2 -> termEq t2 t1
| termTrans : forall {a b} (t1 t2 t3: term a b),
termEq t1 t2 -> termEq t2 t3 -> termEq t1 t3
| termCongComp : forall {a b c} (f f0 : term a b) (g g0 : term b c),
termEq f f0 -> termEq g g0 -> termEq (COMP f g) (COMP f0 g0)
| termCongPair : forall {a b c} (f f0 : term a b) (g g0 : term a c),
termEq f f0 -> termEq g g0 -> termEq (PAIR f g) (PAIR f0 g0)
| termCongCase : forall {a b c} (f f0 : term a c) (g g0 : term b c),
termEq f f0 -> termEq g g0 -> termEq (CASE f g) (CASE f0 g0)
| termId1 : forall {a b} (f: term a b), termEq (COMP IDEN f) f
| termId2 : forall {a b} (f: term a b), termEq (COMP f IDEN) f
| termAssoc : forall {a b c d} (f: term a b) (g: term b c) (h: term c d),
termEq (COMP (COMP f g) h) (COMP f (COMP g h))
| termOne : forall {a} (t: term a (One _)), termEq t (tT)
| termZero : forall {a} (t: term (Zero _) a), termEq t (fF )
| termTimesBeta1 : forall {a b c} (f: term a b) (g: term a c),
termEq (COMP (PAIR f g) FST) f
| termTimesBeta2 : forall {a b c} (f: term a b) (g: term a c),
termEq (COMP (PAIR f g) SND) g
| termPlusBeta1 : forall {a b c} (f: term b c) (g: term a c),
termEq (COMP INL (CASE f g)) f
| termPlusBeta2 : forall {a b c} (f: term b c) (g: term a c),
termEq (COMP INR (CASE f g)) g
| termTimesEta : forall {a b},
termEq (PAIR (@FST L lam a b) SND) IDEN
| termPlusEta : forall {a b},