-
Notifications
You must be signed in to change notification settings - Fork 1
/
axioms.v
1263 lines (1017 loc) · 30.4 KB
/
axioms.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
Set Implicit Arguments.
Unset Strict Implicit.
Require Export tactics.
Module Axioms.
Require Import Arith.
Require Import List.
Parameter E : Type.
Notation E1 := (E -> E).
Notation E2 := (E -> E1).
Notation E3 := (E -> E2).
Notation E4 := (E -> E3).
Notation E5 := (E -> E4).
Notation E6 := (E -> E5).
(** thus for example E3 = E -> E -> E -> E **)
Fixpoint En (n : nat) : Type := match n with
| 0 => E
| S k => E -> En k
end.
Notation EP := (E -> Prop).
Notation E2P := (E -> EP).
Notation E3P := (E -> E2P).
Notation E4P := (E -> E3P).
Fixpoint EnP (n : nat) := match n with
| 0 => Prop
| S k => E -> EnP k
end.
Parameter inc : E -> E -> Prop.
Definition sub x y := forall a, inc a x -> inc a y.
Notation "a ∈ b" := (inc a b) (no associativity, at level 98).
Notation "a ∉ b" := (~ inc a b) (no associativity, at level 98).
Notation "a ⊂ b" := (sub a b) (no associativity, at level 98).
Lemma sub_refl : forall x, sub x x.
Proof.
ir;uhg;ir;am.
Qed.
Lemma sub_trans : forall x y, sub x y -> forall z, sub y z -> sub x z.
Proof.
ir;uhg;ir. ap H0;au.
Qed.
Axiom extensionality : forall x y, sub x y -> sub y x -> x=y.
(*** we also need extensionality for general product types ***)
(***) Axiom
prod_extensionality :
forall (x : Type) (y : x -> Type) (u v : forall a : x, y a),
(forall a : x, u a = v a) -> u = v.
Lemma arrow_extensionality :
forall (x y : Type) (u v : x -> y), (forall a : x, u a = v a) -> u = v.
Proof.
intros x y.
change
(forall u v : forall a : x, (fun i : x => y) a,
(forall a : x, u a = v a) -> u = v) in |- *.
intros. apply prod_extensionality. assumption.
Qed.
(*axiom of choice*)
Inductive nonemptyT (t : Type) : Prop :=
nonemptyT_intro : t -> nonemptyT t.
(***) Parameter chooseT : forall (t : Type) (p : t -> Prop), nonemptyT t -> t.
(***) Axiom
chooseT_pr :
forall (t : Type) (p : t -> Prop) (ne : nonemptyT t),
ex p -> p (chooseT p ne).
Axiom nonemptyE : nonemptyT E.
Definition choose : EP -> E.
ir. ap chooseT. exact X. exact nonemptyE.
Defined.
Lemma choose_pr : forall p, ex p -> p (choose p).
Proof.
ir. uf choose. ap chooseT_pr. am.
Qed.
(*** the following actually follow from the above as was shown in the
standard library but we write them as axioms for brevity **************)
(***) Axiom excluded_middle : forall P : Prop, ~ ~ P -> P.
(***) Axiom proof_irrelevance : forall (P : Prop) (q p : P), p = q.
(*** the following axioms can be obtained from the Ensembles library but we include it here
as an axiom; it is used for convenience, allowing us to replace iff by equality so as to
be able to rewrite using equality of propositions **********************************)
(***) Axiom iff_eq : forall P Q : Prop, (P -> Q) -> (Q -> P) -> P = Q.
(*by_cases*)
Lemma p_or_not_p : forall P : Prop, P \/ ~ P.
Proof.
ir.
eapply excluded_middle.
unfold not in |- *.
ir.
assert P; ap excluded_middle; unfold not in |- * ; au.
Qed.
Definition by_cases_pr (T : Type) (P : Prop) (a : P -> T)
(b : ~ P -> T) (x : T) :=
and (forall p : P, a p = x) (forall q : ~ P, b q = x).
Lemma by_cases_exists :
forall (T : Type) (P : Prop) (a : P -> T) (b : ~ P -> T),
exists x : T, by_cases_pr a b x.
Proof.
ir. assert (P \/ ~ P). ap p_or_not_p. nin H.
eapply ex_intro with (a H). unfold by_cases_pr in |- *. xd.
ir. assert (H = p). ap proof_irrelevance. rewrite H0. tv.
ir. pose (q H). elim f.
eapply ex_intro with (b H). unfold by_cases_pr in |- *. xd.
ir. pose (H p). elim f.
ir. assert (H = q). ap proof_irrelevance. rewrite H0. tv.
Qed.
Lemma by_cases_nonempty :
forall (T : Type) (P : Prop) (a : P -> T) (b : ~ P -> T), nonemptyT T.
Proof.
ir.
ir. assert (P \/ ~ P). ap p_or_not_p. nin H.
eapply nonemptyT_intro. exact (a H).
eapply nonemptyT_intro. exact (b H).
Qed.
Definition by_cases (T : Type) (P : Prop) (a : P -> T)
(b : ~ P -> T) :=
chooseT (fun x : T => by_cases_pr a b x) (by_cases_nonempty a b).
Lemma by_cases_property :
forall (T : Type) (P : Prop) (a : P -> T) (b : ~ P -> T),
by_cases_pr a b (by_cases a b).
Proof.
ir.
cp (by_cases_exists a b).
cp (by_cases_nonempty a b).
cp (chooseT_pr H0 H).
unfold by_cases in |- *.
assert (by_cases_nonempty a b = H0).
ap proof_irrelevance.
rewrite H2.
am.
Qed.
Lemma by_cases_unique :
forall (T : Type) (P : Prop) (a : P -> T) (b : ~ P -> T) (x : T),
by_cases_pr a b x -> by_cases a b = x.
Proof.
ir.
cp (by_cases_property a b).
ir. assert (P \/ ~ P). ap p_or_not_p. nin H1.
unfold by_cases_pr in H. unfold by_cases_pr in H0. xd.
transitivity (a H1). sy. au. au.
unfold by_cases_pr in H. unfold by_cases_pr in H0. xd.
transitivity (b H1). sy. au. au.
Qed.
Lemma by_cases_if :
forall (T : Type) (P : Prop) (a : P -> T) (b : ~ P -> T) (p : P),
by_cases a b = a p.
Proof.
ir. eapply by_cases_unique.
unfold by_cases_pr in |- *. xd.
ir. assert (p = p0). ap proof_irrelevance. rewrite H. tv.
ir. cp (q p). elim H.
Qed.
Lemma by_cases_if_not :
forall (T : Type) (P : Prop) (a : P -> T) (b : ~ P -> T) (q : ~ P),
by_cases a b = b q.
Proof.
ir. eapply by_cases_unique.
unfold by_cases_pr in |- *. xd.
ir.
cp (q p). elim H.
ir. assert (q = q0). ap proof_irrelevance. rewrite H. tv.
Qed.
(*Paire*)
Parameter doubleton : E2.
Axiom doubleton_pr : forall a b x, inc x (doubleton a b) = (x=a \/ x=b).
Lemma doubleton_or : forall a b x, inc x (doubleton a b) -> x=a\/x=b.
Proof.
ir. wr doubleton_pr. am.
Qed.
Lemma doubleton_inc : forall a b x, (x = a \/ x = b) -> inc x (doubleton a b).
Proof.
ir. rw doubleton_pr. am.
Qed.
Lemma doubleton_l : forall a b, inc a (doubleton a b).
Proof.
ir. rw doubleton_pr;au.
Qed.
Lemma doubleton_r : forall a b, inc b (doubleton a b).
Proof.
ir;rw doubleton_pr;au.
Qed.
Definition singleton a := doubleton a a.
Lemma singleton_inc : forall a, inc a (singleton a).
Proof.
ir. ap doubleton_l.
Qed.
Lemma singleton_eq : forall a x, inc x (singleton a) -> x=a.
Proof.
ir.
apply doubleton_or in H. nin H;am.
Qed.
Lemma singleton_rw : forall a x, inc x (singleton a) = (x=a).
Proof.
ir;ap iff_eq.
ap singleton_eq.
ir;subst. ap singleton_inc.
Qed.
Lemma doubleton_comm : forall a b, doubleton a b = doubleton b a.
Proof.
ir. ap extensionality;uhg;ir.
apply doubleton_or in H;ap doubleton_inc. nin H;au.
apply doubleton_or in H;ap doubleton_inc. nin H;au.
Qed.
Lemma doubleton_eq : forall a b c d, (doubleton a b = doubleton c d) = ((a=c & b=d)\/(a=d & b=c)).
Proof.
ir;ap iff_eq;ir.
assert (inc c (doubleton a b)). rw H. ap doubleton_l.
apply doubleton_or in H0. nin H0;subst.
assert (inc d (doubleton a b)). rw H. ap doubleton_r.
apply doubleton_or in H0;nin H0;subst.
assert (inc b (doubleton a a)).
wr H. ap doubleton_r.
apply singleton_eq in H0. subst. au.
au.
assert (inc d (doubleton a b)).
rw H. ap doubleton_r. apply doubleton_or in H0;nin H0;subst;au.
left. ee. ap singleton_eq.
uf singleton. wr H. ap doubleton_l. tv.
nin H;ee;subst.
tv. ap doubleton_comm.
Qed.
Lemma singleton_inj : forall a b, singleton a = singleton b -> a=b.
Proof.
ir. ap singleton_eq. wr H. ap singleton_inc.
Qed.
Parameter Z : E -> EP -> E.
Axiom Z_rw : forall a p x, inc x (Z a p) = (inc x a & p x).
Lemma Z_inc : forall a (p:EP) x, inc x a -> p x -> inc x (Z a p).
Proof.
ir. rw Z_rw. ee;am.
Qed.
Lemma Z_all : forall a p x, inc x (Z a p) -> (inc x a & p x).
Proof.
ir;wr Z_rw;am.
Qed.
Lemma Z_sub : forall a p, sub (Z a p) a.
Proof.
ir;uhg;ir. apply Z_all in H. am.
Qed.
Lemma Z_pr : forall a p x, inc x (Z a p) -> p x.
Proof.
ir;eapply Z_all. am.
Qed.
Ltac Ztac :=
match goal with
| id1:(inc ?X1 (Z _ _)) |- _ => apply Z_all in id1;nin id1
| |- (inc _ (Z _ _)) => ap Z_inc
| _ => idtac
end.
Lemma no_total_set : ~ exists x, forall y, inc y x.
Proof.
uhg;ir;nin H.
pose (z := Z x (fun y => ~ inc y y)).
assert (inc z z = ~ inc z z).
ap iff_eq;ir.
ufa z. Ztac. am.
ap Z_inc. ap H. am.
assert (~ inc z z).
uhg;ir. cp H1. rwi H0 H2. au.
ap H1. rw H0. am.
Qed.
Lemma always_other : forall x, exists y, ~ inc y x.
Proof.
ir;ap excluded_middle;uhg;ir.
ap no_total_set.
exists x. ir.
ap excluded_middle;uhg;ir.
ap H. exists y;am.
Qed.
Definition complement a b := Z a (fun x => ~ inc x b).
Lemma use_complement : forall a b x, inc x a -> ~ inc x (complement a b) -> inc x b.
Proof.
ir. ap excluded_middle;uhg;ir.
ap H0. ap Z_inc;am.
Qed.
Parameter union : E1.
Axiom union_rw : forall a x, inc x (union a) = (exists y, inc y a & inc x y).
Notation "⋃" := union.
Lemma union_inc : forall a x, (exists y, inc y a & inc x y) -> inc x (union a).
Proof.
ir;rw union_rw;am.
Qed.
Lemma union_ex : forall a x, inc x (union a) -> (exists y, inc y a & inc x y).
Proof.
ir;wr union_rw;am.
Qed.
Definition union2 a b := union (doubleton a b).
Lemma union2_or : forall a b x, inc x (union2 a b) -> (inc x a \/ inc x b).
Proof.
ir.
apply union_ex in H. nin H;ee. apply doubleton_or in H.
nin H;subst;au.
Qed.
Lemma union2_inc : forall a b x, (inc x a \/ inc x b) -> inc x (union2 a b).
Proof.
ir.
ap union_inc. nin H.
exists a;ee. ap doubleton_l. am.
exists b;ee. ap doubleton_r. am.
Qed.
Lemma union2_l : forall a b, sub a (union2 a b).
Proof.
uhg;ir. ap union_inc. exists a;ee. ap doubleton_l. am.
Qed.
Lemma union2_r : forall a b, sub b (union2 a b).
Proof.
uhg;ir;ap union_inc;exists b;ee;try am;ap doubleton_r.
Qed.
Lemma union2_rw : forall a b x, inc x (union2 a b) = (inc x a \/ inc x b).
Proof.
ir;ap iff_eq. ap union2_or. ap union2_inc.
Qed.
Definition tack_on a b := union2 a (singleton b).
Lemma tack_on_or : forall x y z : E, inc z (tack_on x y) ->
(inc z x \/ z = y).
Proof.
ir. ufi tack_on H. cp (union2_or H). nin H0.
Proof.
ap or_introl; am. ap or_intror. ap singleton_eq; am.
Qed.
Lemma tack_on_inc: forall x y z:E,
(inc z (tack_on x y) ) = (inc z x \/ z = y).
Proof.
ir. ap iff_eq. ir; ap tack_on_or. am. ir.
nin H. uf tack_on. ap union2_l. am.
uf tack_on. ap union2_r. rw H.
ap singleton_inc.
Qed.
Definition inter : E -> E.
intros a.
ap Z. exact (union a).
ir. exact (forall x', inc x' a -> inc X x').
Defined.
Notation "⋂" := inter.
Definition emptyset : E.
exact (choose (fun x => forall y, ~ inc y x)).
Defined.
Notation "∅" := emptyset.
Lemma emptyset_empty : forall x, ~ inc x emptyset.
Proof.
uf emptyset. ap choose_pr.
destruct nonemptyE.
exists (complement X X).
ir. uhg;ir;ufa complement;Ztac.
au.
Qed.
Lemma emptyset_sub_all : forall x, sub emptyset x.
Proof.
ir;uhg;ir. apply emptyset_empty in H. elim H.
Qed.
Lemma empty_emptyset : forall x, (forall y, inc y x -> False) -> x = emptyset.
Proof.
ir;ap extensionality.
uhg;ir. elim (H a H0).
ap emptyset_sub_all.
Qed.
Lemma emptyset_sub_is : forall x, sub x emptyset -> x = emptyset.
Proof.
ir;ap extensionality. am. ap emptyset_sub_all.
Qed.
Lemma union_empty : union emptyset = emptyset.
Proof.
ap empty_emptyset. ir.
apply union_ex in H;nin H;ee. apply emptyset_empty with x;am.
Qed.
Definition nonempty x := exists y, inc y x.
Lemma nonempty_not_emptyset_rw : forall x, nonempty x = (x<> emptyset).
Proof.
uf nonempty. ir;ap iff_eq;ir.
uhg;ir;subst. nin H.
apply emptyset_empty in H. am.
ap excluded_middle;uhg;ir.
ap H. ap empty_emptyset. ir. ap H0. exists y;am.
Qed.
Lemma inter_empty : inter emptyset = emptyset.
Proof.
ap emptyset_sub_is. eapply sub_trans. ap Z_sub.
rw union_empty. ap sub_refl.
Qed.
Lemma inter_rw : forall a, nonempty a -> forall x, inc x (inter a) = (forall y, inc y a -> inc x y).
Proof.
ir. uf inter.
ap iff_eq;ir.
apply Z_all in H0;nin H0.
apply union_ex in H0;nin H0;ee.
ap H2. am.
ap Z_inc. ap union_inc. nin H.
exists x0. ee. am. au.
am.
Qed.
Lemma inter_inc : forall a, nonempty a -> forall x, (forall y, inc y a -> inc x y) ->
inc x (inter a).
Proof.
ir;rw inter_rw. am. am.
Qed.
Lemma inter_all : forall a x, inc x (inter a) -> forall y, inc y a -> inc x y.
Proof.
ir.
apply Z_all in H. ee.
au.
Qed.
Definition inter2 a b := inter (doubleton a b).
Lemma inter2_rw : forall a b x, inc x (inter2 a b) = (inc x a & inc x b).
Proof.
ir. uf inter2. rw inter_rw.
ap iff_eq;ir.
ee;ap H. ap doubleton_l. ap doubleton_r.
apply doubleton_or in H0. nin H0;subst;am.
econstructor. ap doubleton_l.
Qed.
Lemma inter2_inc : forall a b x, inc x a -> inc x b -> inc x (inter2 a b).
Proof.
ir. rw inter2_rw. ee;am.
Qed.
Lemma inter2_and : forall a b x, inc x (inter2 a b) -> (inc x a & inc x b).
Proof.
ir. wr inter2_rw. am.
Qed.
Parameter powerset : E1.
Axiom powerset_rw : forall a x, inc x (powerset a) = sub x a.
Lemma powerset_sub : forall a x, inc x (powerset a) -> sub x a.
Proof.
ir. wr powerset_rw. am.
Qed.
Lemma powerset_inc : forall a x, sub x a -> inc x (powerset a).
Proof.
ir;rw powerset_rw;am.
Qed.
Lemma singleton_union : forall x, union (singleton x) = x.
Proof.
ir. ap extensionality;uhg;ir.
apply union_ex in H;nin H;ee. apply singleton_eq in H. subst. am.
ap union_inc. exists x. ee. ap singleton_inc. am.
Qed.
(*
Tuples
tuples are defined by a function create : list E -> E injective
a n-tuple is some x s.t. exists l, length l = n & x = create l
a pair is a 2-tuple
a relation is a set of pairs. for r relation, R r x y = inc (pair x y) r
a function is a functional relation
product a b = Im2 pair a b
then functions a -> b are subsets of product a b
if a is a tuple a1 ... an, we want pair (create (x1 ... xn)) y to be a tuple
then the function would be both a relation and a set of n+1-tuples
this makes defining morphisms later much easier :
a morphism on a signature between 2 structures (= assignements for the structure)
is a function preserving relations, and therefore passes for the structure's functions
then we have:
0-tuple : [] -> emptyset
1-tuple : x -> ??
2-tuple : x y -> pair x y
forall n, n+1-tuple : (x)n y -> pair (x)n y
pair x y = pair (x)1 y
so 1-tuple = identity ? not possible :
(x)1 = create [x] = x = create [x1 ; ... ; xn] even when x is n-tuple
maybe looking at product sets instead
() -> emptyset(or something)
(x) -> ??
(x*y) -> product x y = Im2 pair x y
(x1*...*xn*xn+1) -> product (x1...xn) xn+1
forall x ntuple y set, pair x y is n+1 tuple
(n>=1) n=0 -> no restr -> 1-tuple can be anything
so give up on full injectivity of create, only injective for same-length lists
*)
Definition adjoin a b := doubleton (singleton a) (doubleton a b).
Lemma adjoin_eq : forall a b c d, adjoin a b = adjoin c d -> (a=c & b=d).
Proof.
ir. ufi adjoin H;ufi singleton H.
repeat rwi doubleton_eq H.
nin H;ee;nin H;nin H0;ee;subst;au.
Qed.
Fixpoint create_tuple (l : list E) := match l with
| nil => emptyset
| x::nil => x
| x::tl => adjoin (create_tuple tl) x
end.
Lemma adjoin_nonempty : forall a b, nonempty (adjoin a b).
Proof.
ir. econstructor. ap doubleton_l.
Qed.
Lemma create_tuple_eq : forall l, l<>nil -> forall l',
length l = length l' -> create_tuple l = create_tuple l' -> l=l'.
Proof.
intros l Hl;nin l;ir;nin l';simpl in *;tv.
inversion H. inversion H.
inversion H;subst. clear H.
destruct l;destruct l'.
subst;tv.
inversion H2. inversion H2.
apply adjoin_eq in H0. ee.
subst. ap uneq. ap IHl. uhg;ir. inversion H0.
am.
am.
Qed.
Definition pair a b := create_tuple (b::a::nil).
Inductive is_pair : E -> Prop :=
| pair_is_pair : forall a b, is_pair (pair a b).
Lemma pair_eq_l : forall a b c d, pair a b = pair c d -> a=c.
Proof.
ir. apply create_tuple_eq in H.
inversion H;au.
uhg;ir. inversion H0.
tv.
Qed.
Lemma pair_eq_r : forall a b c d, pair a b = pair c d -> b=d.
Proof.
ir. apply create_tuple_eq in H. inversion H;subst.
tv.
uhg;ir;inversion H0. tv.
Qed.
Lemma pair_eq : forall a b c d, pair a b = pair c d -> (a=c & b=d).
Proof.
ir. apply create_tuple_eq in H;inversion H;subst. au.
uhg;ir;inversion H0. tv.
Qed.
Lemma pair_adjoin_eq : pair=adjoin.
Proof.
reflexivity.
Qed.
Lemma tuple_pair_S : forall l, l<>nil -> forall x,
create_tuple (x::l) = pair (create_tuple l) x.
Proof.
ir. simpl. destruct l. nin H;tv.
tv.
Qed.
(*
To prove that we made the right decisions we need to define
arbitrary-arity relations, and how they are related to functions
see (some other file, not yet decided)
*)
Notation J := pair.
Definition unicity (T : Type) (p : T -> Prop) := (forall y, p y -> forall y', p y' -> y=y').
Definition is_functional (r:E2P) := forall x, ex (r x) & (unicity (r x)).
Parameter replacement : E2P -> E1.
Axiom replacement_rw : forall r, is_functional r ->
forall x y, inc y (replacement r x) = exists x0, inc x0 x & r x0 y.
Lemma replacement_pr : forall r, is_functional r ->
forall x y, inc y (replacement r x) <-> exists x0, inc x0 x & r x0 y.
Proof.
ir. rw replacement_rw;au. split;ir;am.
Qed.
Lemma replacement_ex : forall r, is_functional r ->
forall x y, inc y (replacement r x) -> exists x0, inc x0 x & r x0 y.
Proof.
intros r H x y;eapply replacement_pr;am.
Qed.
Lemma replacement_inc : forall r, is_functional r ->
forall x y, (exists x0, inc x0 x & r x0 y) ->
inc y (replacement r x).
Proof.
intros r H x y;ap replacement_pr. am.
Qed.
Definition unique_choose (p : EP) : E.
ap union.
ap replacement.
ir. ap p. ap X0.
exact (singleton emptyset).
Defined.
Lemma unique_choose_pr : forall p, ex p ->
(unicity p) ->
p (unique_choose p).
Proof.
ir.
uf unique_choose.
assert (is_functional (fun _ X0 : E => p X0)).
uhg;ir;ee;ir. nin H;econstructor;am.
au.
cp (replacement_pr H1 (singleton emptyset)).
simpl in H2.
assert (forall y, inc y (replacement (fun _ X0 : E => p X0) (singleton ∅)) <->
p y).
ir;split;ir. apply H2 in H3. nin H3;am.
ap H2. exists emptyset. ee. ap singleton_inc. am.
nin H.
eapply eq_ind.
ap H.
ap extensionality;uhg;ir.
ap union_inc. econstructor. ee.
ap H3. ap H. am.
apply union_ex in H4;nin H4;ee.
apply H3 in H4.
eapply eq_ind. am.
au.
Qed.
Definition pr1 x := unique_choose (fun a => exists b, x = pair a b).
Definition pr2 x := unique_choose (fun b => exists a, x = pair a b).
(*
Definition pr1 x := choose (fun a => exists b, x = pair a b).
Definition pr2 x := choose (fun b => exists a, x = pair a b).
*)
Notation P := pr1.
Notation Q := pr2.
Lemma pr1_pr : forall a b, pr1 (pair a b) = a.
Proof.
ir. assert (exists b', J a b = J (P (J a b)) b'). uf P. ap unique_choose_pr.
exists a;exists b;tv.
uhg;ir. nin H;nin H0. apply pair_eq in H;apply pair_eq in H0;ee;subst;tv.
nin H. apply pair_eq in H;ee;au.
Qed.
Lemma pr2_pr : forall a b, pr2 (pair a b) = b.
Proof.
ir. assert (exists a', J a b = J a' (Q (J a b))). uf Q. ap unique_choose_pr.
exists b;exists a;tv.
uhg;ir. nin H;nin H0. apply pair_eq in H;apply pair_eq in H0;ee;subst;tv.
nin H. apply pair_eq in H;ee;au.
Qed.
Ltac clpr := repeat (first [rw pr1_pr | rw pr2_pr]).
Ltac clpri H := repeat (first [rwi pr1_pr H | rwi pr2_pr H]).
Lemma pair_recov : forall x, is_pair x -> x = pair (P x) (Q x).
Proof.
ir. nin H. clpr. tv.
Qed.
Definition Im f x := replacement (fun a b => b = f a) x.
Lemma Im_rw : forall f a y, inc y (Im f a) = (exists x, inc x a & y = f x).
Proof.
ir. uf Im. rw replacement_rw.
tv. uhg;ir;ee.
exists (f x);tv.
uhg;ir;subst;au.
Qed.
Lemma Im_inc : forall f a x, inc x a -> inc (f x) (Im f a).
Proof.
ir.
rw Im_rw. exists x;ee;au.
Qed.
Lemma Im_show_inc : forall f a y, (exists x, inc x a & y = f x) -> inc y (Im f a).
Proof.
ir. rw Im_rw. am.
Qed.
Lemma Im_ex : forall f a y, inc y (Im f a) -> exists x, inc x a & y = f x.
Proof.
ir. wr Im_rw. am.
Qed.
(*note: getting replacement from Im uses choice, but Im from replacement
doesn't*)
Definition Im2 (f : E2) (x y : E) := union (Im (fun a => Im (fun b => f a b) y) x).
Lemma Im2_rw : forall f x y z, inc z (Im2 f x y) = exists a, exists b, inc a x & inc b y & z = f a b.
Proof.
ir;ap iff_eq;ir.
apply union_ex in H. nin H. ee.
apply Im_ex in H;nin H. ee.
subst. apply Im_ex in H0;nin H0;ee. subst. exists x1;exists x0;ee;au.
nin H;nin H;ee;subst.
ap union_inc. econstructor. ee.
ap Im_inc. am. ap Im_inc. am.
Qed.
Lemma Im2_ex : forall f x y z, inc z (Im2 f x y) -> exists a, exists b, inc a x & inc b y & z=f a b.
Proof.
ir. wr Im2_rw. am.
Qed.
Lemma Im2_inc : forall f x y a b, inc a x -> inc b y -> inc (f a b) (Im2 f x y).
Proof.
ir. rw Im2_rw. exists a;exists b;ee;au.
Qed.
Lemma Im2_show_inc : forall f x y z, (exists a, exists b, inc a x & inc b y & z = f a b) ->
inc z (Im2 f x y).
Proof.
ir;rw Im2_rw;au.
Qed.
Definition product := Im2 pair.
Lemma product_pair_inc : forall a b x y, inc x a -> inc y b ->
inc (pair x y) (product a b).
Proof.
ap Im2_inc.
Qed.
Lemma product_pair_pr : forall a b x y, inc (pair x y) (product a b) ->
(inc x a & inc y b).
Proof.
ir. apply Im2_ex in H. nin H;nin H.
nin H;nin H0.
apply pair_eq in H1;ee;subst;am.
Qed.
Lemma product_inc : forall a b x, is_pair x -> inc (P x) a -> inc (Q x) b ->
inc x (product a b).
Proof.
ir. nin H. clpri H0. clpri H1.
ap product_pair_inc;am.
Qed.
Lemma product_pr : forall a b x, inc x (product a b) ->
(is_pair x & inc (P x) a & inc (Q x) b).
Proof.
ir.
apply Im2_ex in H. nin H;nin H.
ee; subst;clpr. ap pair_is_pair. am. am.
Qed.
Lemma product_rw : forall a b x, inc x (product a b) = (is_pair x & inc (P x) a & inc (Q x) b).
Proof.
ir;ap iff_eq.
ap product_pr.
ir;ap product_inc;am.
Qed.
Lemma product_pair_rw : forall a b x y, inc (J x y) (product a b) = (inc x a & inc y b).
Proof.
ir;ap iff_eq.
ap product_pair_pr.
ir;ap product_pair_inc;am.
Qed.
Lemma product_emptyset_r : forall x, product x emptyset = emptyset.
Proof.
ir;ap empty_emptyset;ir.
apply product_pr in H;ee. edestruct emptyset_empty;am.
Qed.
Lemma product_emptyset_l : forall x, product emptyset x = emptyset.
Proof.
ir;ap empty_emptyset;ir.
apply product_pr in H;ee. edestruct emptyset_empty;am.
Qed.
(* some basic utility stuff *)
Lemma extensionality_rw : forall x y, (forall a, inc a x = inc a y) -> x = y.
Proof.
ir;ap extensionality;uhg;ir;first [ rw H | wr H ];am.
Qed.
Lemma inter_sub : forall x y, inc y x -> sub (inter x) y.
Proof.
ir. uhg;ir. eapply inter_all. am. am.
Qed.
Definition rep x := choose (fun y => inc y x).
Lemma rep_inc : forall x, nonempty x -> inc (rep x) x.
Proof.
ir. uf rep. ap choose_pr. am.
Qed.
Lemma inter2_l : forall a b, sub (inter2 a b) a.
Proof.
uhg;ir. apply inter2_and in H;am.
Qed.
Lemma inter2_r : forall a b, sub (inter2 a b) b.
Proof.
uhg;ir;apply inter2_and in H;am.
Qed.
Lemma inter2_comm : forall a b, inter2 a b = inter2 b a.
Proof.
ir. uf inter2. rw doubleton_comm. tv.
Qed.
Lemma union2_comm : forall a b, union2 a b = union2 b a.
Proof.
ir. uf union2. rw doubleton_comm. tv.
Qed.
Parameter nNum : E.
Axiom emptyset_N : inc emptyset nNum.
Definition oS x := tack_on x x.
Lemma oS_inc : forall x y, inc y (oS x) = (inc y x \/ y=x).
Proof.
ir. uf oS. ap tack_on_inc.
Qed.
Axiom oS_nNum : forall n, inc n nNum -> inc (oS n) nNum.
Parameter nNum_rect : forall P : E -> Type,
P emptyset -> (forall n : E, inc n nNum -> P n -> P (oS n)) -> forall n : E, inc n nNum -> P n.
Axiom nNum_rect_0 : forall (P : E -> Type) (H0 : P emptyset) IH, nNum_rect H0 IH emptyset_N = H0.
Axiom nNum_rect_S : forall (P : E -> Type) (H0 : P emptyset) IH n (Hn : inc n nNum), nNum_rect H0 IH (oS_nNum Hn) = IH n Hn (nNum_rect H0 IH Hn).
Lemma nNum_destruct : forall x, inc x nNum -> (x = emptyset \/ exists y, inc y nNum & x = oS y).
Proof.
ap nNum_rect.
au. ir.
right. eau.
Qed.
Lemma eq_dec : forall x y:E, {x=y} + {x<>y}.
Proof.
ir. apply by_cases with (x=y);ir.
left. am. right. am.
Qed.
Lemma eq_dec_if : forall x T (a b : T), (if eq_dec x x then a else b) = a.
Proof.
ir. destruct (eq_dec x x). tv. nin n;au.
Qed.
Lemma eq_dec_if_not : forall x y, x<>y -> forall T (a b : T), (if eq_dec x y then a else b) = b.
Proof.
ir. destruct (eq_dec x y). nin e;au. nin H;au.
tv.
Qed.
Lemma P_dec : forall P, {P}+{~P}.
Proof.
ir. apply by_cases with P;ir.
left. am. right. am.
Qed.
Lemma P_dec_if : forall P : Prop, P -> forall T (a b :T), (if P_dec P then a else b) = a.
Proof.
ir. nin (P_dec P).
tv. nin b0;am.
Qed.
Lemma P_dec_if_not : forall P, ~P -> forall T (a b : T), (if P_dec P then a else b) = b.
Proof.
ir. nin (P_dec P).
nin H;am. tv.
Qed.
Lemma Im_uneq : forall f g x, (forall y, inc y x -> f y = g y) -> Im f x = Im g x.
Proof.
ir;ap extensionality;uhg;ir.
apply Im_ex in H0;nin H0;ee;subst. ap Im_show_inc;exists x0;ee. am.
ap H;am.
apply Im_ex in H0;nin H0;ee;subst. ap Im_show_inc;exists x0;ee. am.
symmetry;ap H;am.
Qed.
Ltac Im_nin H := apply Im_ex in H;nin H;nin H.
Ltac Im_incw x := ap Im_show_inc;exists x.
Ltac union_nin H := apply union_ex in H;nin H;nin H.
Lemma sub_complement : forall a b c, sub b c -> sub (complement a c) (complement a b).
Proof.
uhg;ir. apply Z_all in H0;ee;ap Z_inc.