-
Notifications
You must be signed in to change notification settings - Fork 2
/
ZF.v
1152 lines (960 loc) · 25.1 KB
/
ZF.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
Require Export basic.
Require Import Sublogic.
Require Export ZFdef.
(** We assume the existence of a model of IZF: *)
Require ZFskolEm.
Module IZF : IZF_R_sig CoqSublogicThms := ZFskolEm.IZF_R.
(*Import IZF.*)
Include IZF.
Notation morph1 := (Proper (eq_set ==> eq_set)).
Notation morph2 := (Proper (eq_set ==> eq_set ==> eq_set)).
Instance eq_set_equiv: Equivalence eq_set.
Proof.
split; red; intros; rewrite eq_set_ax in *; intros.
reflexivity.
symmetry; trivial.
transitivity (x0 ∈ y); trivial.
Qed.
Lemma eq_set_morph : Proper (eq_set ==> eq_set ==> iff) eq_set.
auto with *.
Qed.
Lemma eq_intro : forall x y,
(forall z, z ∈ x -> z ∈ y) ->
(forall z, z ∈ y -> z ∈ x) ->
eq_set x y.
intros.
rewrite eq_set_ax; split; auto.
Qed.
Lemma eq_elim : forall x y y',
y == y' ->
x ∈ y ->
x ∈ y'.
intros.
rewrite eq_set_ax in H.
destruct (H x); auto.
Qed.
Instance in_set_morph : Proper (eq_set ==> eq_set ==> iff) in_set.
apply morph_impl_iff2; auto with *.
do 4 red; intros.
apply in_reg with x; trivial.
apply eq_elim with x0; trivial.
Qed.
Definition incl_set x y := forall z, z ∈ x -> z ∈ y.
Notation "x ⊆ y" := (incl_set x y).
Instance incl_set_pre : PreOrder incl_set.
split; do 2 red; intros; eauto.
Qed.
Instance incl_set_morph : Proper (eq_set ==> eq_set ==> iff) incl_set.
apply morph_impl_iff2; auto with *.
unfold incl_set; do 4 red; intros.
rewrite <- H0; rewrite <- H in H2; auto.
Qed.
Lemma incl_eq x y : x ⊆ y -> y ⊆ x -> x == y.
intros.
apply eq_intro; auto.
Qed.
Lemma eq_incl x y : x == y -> x ⊆ y.
intro h; rewrite h; reflexivity.
Qed.
Instance Fmono_morph F : Proper (incl_set==>incl_set) F -> morph1 F.
do 2 red; intros.
apply incl_eq; apply H; rewrite H0; reflexivity.
Qed.
Hint Resolve Fmono_morph.
(** Extensional equivalences *)
Definition eq_fun dom F G :=
forall x x', x ∈ dom -> x == x' -> F x == G x'.
Instance eq_fun_sym : forall dom, Symmetric (eq_fun dom).
do 2 red; intros.
rewrite H1 in H0.
symmetry in H1.
symmetry; apply H; auto.
Qed.
Instance eq_fun_trans : forall dom, Transitive (eq_fun dom).
do 2 red; intros.
transitivity (y x'); auto.
apply H0.
rewrite <- H2; trivial.
reflexivity.
Qed.
Definition ext_fun dom f := eq_fun dom f f.
Definition ext_fun2 A B f :=
forall x x' y y', x ∈ A -> x == x' -> y ∈ B x -> y == y' -> f x y == f x' y'.
Lemma eq_fun_ext : forall dom F G, eq_fun dom F G -> ext_fun dom F.
red; intros.
transitivity G; trivial.
symmetry; trivial.
Qed.
Lemma morph_is_ext : forall F X, morph1 F -> ext_fun X F.
red; red; intros.
apply H; trivial.
Qed.
Hint Resolve morph_is_ext.
Lemma cst_is_ext : forall X o, ext_fun o (fun _ => X).
do 2 red; reflexivity.
Qed.
Hint Resolve cst_is_ext.
Definition eq_pred dom (P Q : set -> Prop) :=
forall x, x ∈ dom -> (P x <-> Q x).
Instance eq_pred_set : forall dom, Equivalence (eq_pred dom).
firstorder.
Qed.
Definition ext_rel dom (R:set->set->Prop) :=
forall x x' y y', x ∈ dom -> x == x' -> y == y' -> (R x y <-> R x' y').
Definition eq_index x F y G :=
(forall a, a ∈ x -> exists2 b, b ∈ y & F a == G b) /\
(forall b, b ∈ y -> exists2 a, a ∈ x & F a == G b).
Lemma eq_index_sym : forall x F y G, eq_index x F y G -> eq_index y G x F.
destruct 1; split; intros.
apply H0 in H1; destruct H1.
symmetry in H2.
exists x0; trivial.
apply H in H1; destruct H1.
symmetry in H2.
exists x0; trivial.
Qed.
Lemma eq_index_eq : forall x F y G,
x == y ->
eq_fun x F G ->
eq_index x F y G.
red; intros.
split; intros.
exists a.
rewrite H in H1; trivial.
apply H0; auto with *.
rewrite <- H in H1; trivial.
exists b; trivial.
apply H0; auto with *.
Qed.
Definition typ_fun f A B := forall x, x ∈ A -> f x ∈ B.
Instance typ_fun_morph0 : Proper (eq ==> eq_set ==> eq_set ==> iff) typ_fun.
apply morph_impl_iff3; auto with *.
do 6 red; intros.
subst y.
rewrite <- H1; rewrite <- H0 in H3; auto.
Qed.
(** Rephrasing axioms *)
Lemma empty_ext : forall e, (forall x, ~x ∈ e) -> e == empty.
Proof.
intros.
apply eq_intro; intros.
elim H with (1 := H0).
elim empty_ax with (1 := H0).
Qed.
Lemma pair_intro1 : forall x y, x ∈ pair x y.
Proof.
intros.
elim (pair_ax x y x); intros; auto.
apply H0; left; reflexivity.
Qed.
Lemma pair_intro2 : forall x y, y ∈ pair x y.
Proof.
intros.
elim (pair_ax x y y); intros; auto.
apply H0; right; reflexivity.
Qed.
Hint Resolve pair_intro1 pair_intro2.
Lemma pair_elim : forall x a b, x ∈ pair a b -> x == a \/ x == b.
Proof.
intros.
elim (pair_ax a b x); auto.
Qed.
Lemma pair_ext : forall p a b,
a ∈ p -> b ∈ p -> (forall x, x ∈ p -> x == a \/ x == b) ->
p == pair a b.
Proof.
intros; apply eq_intro; intros.
elim H1 with (1 := H2); intro x_eq; rewrite x_eq; trivial.
elim pair_elim with (1 := H2); intro x_eq; rewrite x_eq; trivial.
Qed.
Instance pair_morph : morph2 pair.
do 3 red; intros.
apply pair_ext; intros.
rewrite <- H; apply pair_intro1.
rewrite <- H0; apply pair_intro2.
rewrite <- H; rewrite <- H0.
apply pair_elim in H1; auto.
Qed.
Lemma union_intro : forall x y z, x ∈ y -> y ∈ z -> x ∈ union z.
Proof.
intros.
elim (union_ax z x); intros.
apply H2.
exists y; trivial.
Qed.
Lemma union_elim : forall x z, x ∈ union z -> exists2 y, x ∈ y & y ∈ z.
Proof.
intros.
elim (union_ax z x); auto.
Qed.
Lemma union_ext :
forall u z,
(forall x y, x ∈ y -> y ∈ z -> x ∈ u) ->
(forall x, x ∈ u -> exists2 y, x ∈ y & y ∈ z) ->
u == union z.
Proof.
intros; apply eq_intro; intros.
elim H0 with (1 := H1); intros.
apply union_intro with x; trivial.
elim union_elim with (1 := H1); intros; eauto.
Qed.
Instance union_morph : morph1 union.
do 2 red; intros.
apply union_ext; intros.
eapply union_intro; eauto.
rewrite H; trivial.
elim union_elim with (1 := H0); intros.
exists x1; trivial.
rewrite <- H; trivial.
Qed.
Instance union_mono : Proper (incl_set ==> incl_set) union.
do 3 red; intros.
apply union_elim in H0.
destruct H0.
apply union_intro with x0; auto.
Qed.
Lemma union_empty_eq : union empty == empty.
Proof.
symmetry in |- *.
apply union_ext; intros.
elim empty_ax with (1 := H0).
elim empty_ax with (1 := H).
Qed.
Lemma power_intro :
forall x y, (forall z, z ∈ x -> z ∈ y) -> x ∈ power y.
Proof.
intros.
elim (power_ax y x); intros; auto.
Qed.
Lemma power_elim : forall x y z, x ∈ power y -> z ∈ x -> z ∈ y.
Proof.
intros.
elim (power_ax y x); intros; auto.
Qed.
Lemma power_mono : Proper (incl_set ==> incl_set) power.
do 3 red; intros.
apply power_intro; intros.
apply H.
apply power_elim with z; trivial.
Qed.
Lemma power_ext :
forall p a,
(forall x, (forall y, y ∈ x -> y ∈ a) -> x ∈ p) ->
(forall x y, x ∈ p -> y ∈ x -> y ∈ a) ->
p == power a.
Proof.
intros; apply eq_intro; intros.
apply power_intro; eauto.
apply H; intros; eapply power_elim; eauto.
Qed.
Instance power_morph : morph1 power.
do 2 red; intros.
apply power_ext; intros.
apply power_intro; intros.
rewrite H; auto.
rewrite <- H.
eapply power_elim; eauto.
Qed.
Lemma empty_incl_all a : empty ⊆ a.
red; intros; apply empty_ax in H; contradiction.
Qed.
Lemma empty_in_power : forall x, empty ∈ power x.
Proof.
intros.
apply power_intro; intros.
elim empty_ax with (1:=H).
Qed.
Hint Resolve empty_incl_all empty_in_power.
Lemma union_in_power :
forall x X, x ⊆ power X -> union x ∈ power X.
intros.
apply power_intro; intros.
elim union_elim with (1:=H0); clear H0; intros.
apply power_elim with x0; auto.
Qed.
Lemma subset_ax' x P z :
Proper (eq_set==>iff) P ->
(z ∈ subset x P <-> z ∈ x /\ P z).
intros.
rewrite subset_ax.
apply and_iff_morphism; auto with *.
split; intros.
destruct H0.
rewrite H0; trivial.
exists z; auto with *.
Qed.
Lemma subset_intro : forall a (P:set->Prop) x,
x ∈ a -> P x -> x ∈ subset a P.
Proof.
intros.
elim (subset_ax a P x); intros.
apply H2; split; trivial.
exists x; trivial; reflexivity.
Qed.
Lemma subset_elim1 : forall a (P:set->Prop) x, x ∈ subset a P -> x ∈ a.
Proof.
intros.
elim (subset_ax a P x); intros.
elim H0; trivial.
Qed.
Lemma subset_elim2 : forall a (P:set->Prop) x, x ∈ subset a P ->
exists2 x', x==x' & P x'.
Proof.
intros.
elim (subset_ax a P x); intros.
elim H0; trivial.
Qed.
Lemma subset_ext :
forall s a (P:set->Prop),
(forall x, x ∈ a -> P x -> x ∈ s) ->
(forall x, x ∈ s -> x ∈ a) ->
(forall x, x ∈ s -> exists2 x', x==x' & P x') ->
s == subset a P.
Proof.
intros; apply eq_intro; intros.
elim H1 with (1:=H2); intros.
rewrite H3.
apply subset_intro; auto.
rewrite <- H3; auto.
elim subset_elim2 with (1:=H2); intros.
rewrite H3.
apply H; trivial.
rewrite <- H3.
apply subset_elim1 with P; auto.
Qed.
Lemma subset_morph :
forall x x', x == x' ->
forall (P P':set->Prop), eq_pred x P P' ->
subset x P == subset x' P'.
intros.
apply subset_ext; intros.
rewrite <- H in H1.
apply subset_intro; auto.
red in H0.
rewrite H0; trivial.
rewrite <- H.
apply subset_elim1 in H1; trivial.
specialize subset_elim2 with (1:=H1); intro.
destruct H2.
apply subset_elim1 in H1.
exists x1; trivial.
red in H0.
rewrite <- H0; trivial.
rewrite <- H2; trivial.
Qed.
Lemma union_subset_singl : forall x (P:set->Prop) y y',
y ∈ x ->
y == y' ->
P y' ->
(forall y y', y ∈ x -> y' ∈ x -> P y -> P y' -> y == y') ->
union (subset x P) == y.
intros.
symmetry; apply union_ext; intros.
setoid_replace y with y0; trivial.
elim subset_elim2 with (1:=H4); intros.
rewrite H5.
rewrite H0.
apply H2; trivial.
rewrite <- H0; trivial.
rewrite <- H5.
apply subset_elim1 with (1:=H4).
exists y; trivial.
rewrite H0.
apply subset_intro; trivial.
rewrite <- H0; trivial.
Qed.
(*Parameter replf : set -> (set->set) -> set.*)
Definition replf a (F:set->set) :=
repl a (fun x y => y == F x).
Instance replf_mono_raw :
Proper (incl_set ==> (eq_set ==> eq_set) ==> incl_set) replf.
unfold replf.
do 4 red; intros.
assert (xm : morph1 x0).
do 2 red; intros.
transitivity (y0 y1); auto.
symmetry; apply H0; reflexivity.
assert (ym : morph1 y0).
do 2 red; intros.
transitivity (x0 x1); auto.
symmetry; apply H0; reflexivity.
rewrite repl_ax in H1.
rewrite repl_ax.
destruct H1.
exists x1; auto.
rewrite H2; apply H0; reflexivity.
intros.
rewrite <- H4; rewrite H5; auto.
intros.
rewrite H3; rewrite H4; reflexivity.
intros.
rewrite <- H4; rewrite H5; auto.
intros.
rewrite H3; rewrite H4; reflexivity.
Qed.
Instance replf_morph_raw :
Proper (eq_set ==> (eq_set ==> eq_set) ==> eq_set) replf.
do 3 red; intros.
apply eq_intro.
apply replf_mono_raw; auto.
rewrite H; reflexivity.
symmetry in H0.
apply replf_mono_raw; auto.
rewrite H; reflexivity.
Qed.
Lemma replf_ax : forall a F z,
ext_fun a F ->
(z ∈ replf a F <-> exists2 x, x ∈ a & z == F x).
unfold replf; intros.
rewrite repl_ax; intros.
split; intros.
destruct H0.
exists x; trivial.
destruct H0.
exists x; trivial.
rewrite <- H2; rewrite H3; auto.
rewrite H2; trivial.
Qed.
Lemma replf_intro : forall a F y x,
ext_fun a F -> x ∈ a -> y == F x -> y ∈ replf a F.
Proof.
intros a F y x Fext H1 H2.
rewrite replf_ax; trivial.
exists x; trivial.
Qed.
Lemma replf_elim : forall a F y,
ext_fun a F -> y ∈ replf a F -> exists2 x, x ∈ a & y == F x.
Proof.
intros a F y Fext H1.
rewrite replf_ax in H1; trivial.
Qed.
Lemma replf_ext : forall p a F,
ext_fun a F ->
(forall x, x ∈ a -> F x ∈ p) ->
(forall y, y ∈ p -> exists2 x, x ∈ a & y == F x) ->
p == replf a F.
intros.
apply eq_intro; intros.
apply H1 in H2; destruct H2.
apply replf_intro with x; auto.
apply replf_elim in H2; trivial; destruct H2.
rewrite H3; auto.
Qed.
Lemma replf_mono2 : forall x y F,
ext_fun y F ->
x ⊆ y ->
replf x F ⊆ replf y F.
red; intros.
assert (ext_fun x F).
do 2 red; auto.
apply replf_elim in H1; trivial.
destruct H1.
apply replf_intro with x0; auto.
Qed.
Lemma replf_morph_gen : forall x1 x2 F1 F2,
ext_fun x1 F1 ->
ext_fun x2 F2 ->
eq_index x1 F1 x2 F2 ->
replf x1 F1 == replf x2 F2.
Proof.
destruct 3.
apply replf_ext; intros; trivial.
apply H2 in H3; destruct H3.
apply replf_intro with x0; trivial.
symmetry; trivial.
apply replf_elim in H3; trivial; destruct H3.
apply H1 in H3; destruct H3.
rewrite H5 in H4.
exists x0; auto.
Qed.
Lemma replf_morph : forall x1 x2 F1 F2,
x1 == x2 ->
eq_fun x1 F1 F2 ->
replf x1 F1 == replf x2 F2.
intros.
apply replf_morph_gen; intros.
apply eq_fun_ext in H0; trivial.
do 2 red; intros.
rewrite <- H in H1.
transitivity (F1 x); auto.
symmetry; apply H0; trivial; reflexivity.
apply eq_index_eq; trivial.
Qed.
Lemma replf_empty : forall F, replf empty F == empty.
Proof.
intros.
apply empty_ext.
red; intros.
apply replf_elim in H.
destruct H.
elim empty_ax with (1:=H).
do 2 red; intros.
elim empty_ax with (1:=H0).
Qed.
Lemma compose_replf : forall A F G,
ext_fun A F ->
ext_fun (replf A F) G ->
replf (replf A F) G == replf A (fun x => G (F x)).
intros.
assert (eGF : ext_fun A (fun x => G (F x))).
red; red; intros.
apply H0; auto.
rewrite replf_ax; trivial.
exists x; auto with *.
apply eq_intro; intros.
rewrite replf_ax in H1; trivial.
destruct H1.
rewrite replf_ax in H1; trivial.
destruct H1.
rewrite replf_ax; trivial.
exists x0; trivial.
rewrite H2; apply H0; trivial.
rewrite replf_ax; trivial.
exists x0; trivial.
rewrite replf_ax in H1; trivial.
destruct H1.
rewrite replf_ax; trivial.
exists (F x); trivial.
rewrite replf_ax; trivial.
exists x; auto with *.
Qed.
(** Conditional set *)
Definition cond_set P x := subset x (fun _ => P).
Instance cond_set_morph : Proper (iff ==> eq_set ==> eq_set) cond_set.
do 3 red; intros.
apply subset_morph; trivial.
red; auto.
Qed.
Lemma cond_set_ax P x z :
z ∈ cond_set P x <-> (z ∈ x /\ P).
unfold cond_set.
rewrite subset_ax.
split; destruct 1; split; trivial.
destruct H0; trivial.
exists z; auto with *.
Qed.
(* A more precise morphism lemma *)
Lemma cond_set_morph2 : forall P Q x y,
(P <-> Q) ->
(P -> x == y) ->
cond_set P x == cond_set Q y.
intros.
apply subset_ext; intros.
rewrite <- H in H2.
apply subset_intro; trivial.
rewrite H0; trivial.
rewrite cond_set_ax in H1; destruct H1.
rewrite <- H0; trivial.
rewrite cond_set_ax in H1; destruct H1.
exists x0; auto with *.
rewrite <- H; trivial.
Qed.
Lemma cond_set_ok (P:Prop) x : P -> cond_set P x == x.
intro p.
apply eq_intro; intros.
apply subset_elim1 in H; trivial.
apply subset_intro; trivial.
Qed.
Lemma cond_set_mt P x : ~P -> cond_set P x == empty.
intros.
apply empty_ext; red; intros.
rewrite cond_set_ax in H0.
destruct H0; auto.
Qed.
(** other properties of axioms *)
Lemma pair_commut : forall x y, pair x y == pair y x.
Proof.
intros.
apply pair_ext; intros; auto.
elim pair_elim with (1:=H); auto.
Qed.
Lemma pair_inv : forall x y x' y',
pair x y == pair x' y' -> (x==x' /\ y==y') \/ (x==y' /\ y==x').
Proof.
intros.
assert (x ∈ pair x' y').
rewrite <- H; auto.
assert (y ∈ pair x' y').
rewrite <- H; auto.
elim pair_elim with (1 := H0); intros; elim pair_elim with (1 := H1);
intros; auto.
left; split; trivial.
assert (y' ∈ pair x y).
rewrite H; auto.
rewrite H2 in H4.
rewrite H3 in H4.
rewrite H3.
symmetry in |- *.
elim pair_elim with (1:=H4); trivial.
right; split; trivial.
assert (x' ∈ pair x y).
rewrite H; auto.
rewrite H2 in H4.
rewrite H3 in H4.
rewrite H3.
symmetry in |- *.
elim pair_elim with (1:=H4); trivial.
Qed.
Lemma discr_mt_pair : forall a b, ~ empty == pair a b.
red; intros.
apply (empty_ax a).
rewrite H.
apply pair_intro1.
Qed.
(** macros *)
Definition singl x := pair x x.
Lemma singl_intro : forall x, x ∈ singl x.
Proof.
unfold singl in |- *; auto.
Qed.
Lemma singl_intro_eq : forall x y, x == y -> x ∈ singl y.
Proof.
intros.
rewrite H; apply singl_intro.
Qed.
Lemma singl_elim : forall x y, x ∈ singl y -> x == y.
Proof.
unfold singl; intros.
elim pair_elim with (1:=H); auto.
Qed.
Lemma singl_ext :
forall y x,
x ∈ y ->
(forall z, z ∈ y -> z == x) ->
y == singl x.
Proof.
intros; apply eq_intro; intros.
apply singl_intro_eq; auto.
rewrite (singl_elim _ _ H1); trivial.
Qed.
Instance singl_morph : morph1 singl.
unfold singl; do 2 red; intros.
rewrite H; reflexivity.
Qed.
Lemma union_singl_eq : forall x, union (singl x) == x.
Proof.
intros; apply eq_intro; intros.
elim union_elim with (1 := H); intros.
rewrite <- (singl_elim _ _ H1); trivial.
apply union_intro with (1 := H).
apply singl_intro.
Qed.
Lemma singl_inj : forall x y, singl x == singl y -> x == y.
Proof.
intros.
rewrite <- (union_singl_eq x); rewrite <- (union_singl_eq y).
apply union_morph;trivial.
Qed.
(** Union of 2 sets *)
Definition union2 x y := union (pair x y).
Infix "∪" := union2.
Lemma union2_intro1: forall x y z, z ∈ x -> z ∈ union2 x y.
Proof.
unfold union2 in |- *; intros.
apply union_intro with x; trivial.
Qed.
Lemma union2_intro2: forall x y z, z ∈ y -> z ∈ union2 x y.
Proof.
unfold union2 in |- *; intros.
apply union_intro with y; trivial.
Qed.
Lemma union2_elim : forall x y z, z ∈ x ∪ y -> z ∈ x \/ z ∈ y.
Proof.
unfold union2; intros.
elim union_elim with (1:=H); intros.
elim pair_elim with (1:=H1); intro x0_eq; rewrite <- x0_eq; auto.
Qed.
Lemma union2_ax x y z : z ∈ x ∪ y <-> z ∈ x \/ z ∈ y.
split; intros.
apply union2_elim in H; trivial.
destruct H; [apply union2_intro1|apply union2_intro2]; auto.
Qed.
Lemma union2_mono : forall A A' B B',
A ⊆ A' -> B ⊆ B' -> A ∪ B ⊆ A' ∪ B'.
red; intros.
red in H,H0|-.
elim union2_elim with (1:=H1); intros.
apply union2_intro1; auto.
apply union2_intro2; auto.
Qed.
Instance union2_morph : morph2 union2.
unfold union2; do 3 red; intros.
rewrite H; rewrite H0; reflexivity.
Qed.
Lemma union2_commut : forall x y, x ∪ y == y ∪ x.
Proof.
intros.
unfold union2; rewrite pair_commut; reflexivity.
Qed.
Lemma union2_mt_l x : empty ∪ x == x.
apply eq_set_ax; intros z; rewrite union2_ax.
split; auto.
destruct 1; trivial.
elim empty_ax with (1:=H).
Qed.
Lemma union2_mt_r x : x ∪ empty == x.
apply eq_set_ax; intros z; rewrite union2_ax.
split; auto.
destruct 1; trivial.
elim empty_ax with (1:=H).
Qed.
(** subtraction *)
Definition minus2 x y := subset x (fun x' => ~ (x' ∈ y)).
(** Upper bound of a family of sets *)
Definition sup x F := union (replf x F).
Lemma sup_ax : forall x F z,
ext_fun x F ->
(z ∈ sup x F <-> exists2 y, y ∈ x & z ∈ F y).
intros.
unfold sup.
rewrite union_ax.
split; destruct 1; intros.
apply replf_elim in H1; auto; destruct H1.
rewrite H2 in H0; clear H2.
exists x1; trivial.
exists (F x0); trivial.
apply replf_intro with x0; trivial.
reflexivity.
Qed.
Lemma sup_ext : forall y a F,
ext_fun a F ->
(forall x, x ∈ a -> F x ⊆ y) ->
(forall z, z ∈ y -> exists2 x, x ∈ a & z ∈ F x) ->
y == sup a F.
intros.
apply eq_intro; intros.
rewrite sup_ax; auto.
rewrite sup_ax in H2; trivial; destruct H2.
apply H0 in H3; trivial.
Qed.
Lemma sup_morph_gen : forall a F b G,
ext_fun a F ->
ext_fun b G ->
eq_index a F b G ->
sup a F == sup b G.
unfold sup; intros.
apply union_morph; apply replf_morph_gen; trivial.
Qed.
Lemma sup_morph : forall a F b G,
a == b ->
eq_fun a F G ->
sup a F == sup b G.
intros.
apply sup_morph_gen; intros.
apply eq_fun_ext in H0; trivial.
do 2 red; intros.
rewrite <- H in H1.
transitivity (F x); auto.
symmetry; apply H0; trivial; reflexivity.
apply eq_index_eq; trivial.
Qed.
Lemma sup_incl : forall a F x,
ext_fun a F -> x ∈ a -> F x ⊆ sup a F.
intros.
red; intros.
rewrite sup_ax; trivial.
exists x; trivial.
Qed.
Hint Resolve sup_incl.
Lemma sup_lub x f A :
ext_fun x f ->
(forall y, y ∈ x -> f y ⊆ A) ->
sup x f ⊆ A.
red; intros.
apply sup_ax in H1; trivial.
destruct H1 as (y,?,?).
apply H0 with (y:=y); trivial.
Qed.
Lemma replf_is_sup A F :
ext_fun A F ->
replf A F == sup A (fun x => singl (F x)).
intros.
assert (fm : ext_fun A (fun x => singl (F x))).
do 2 red; intros; apply singl_morph; apply H; trivial.
apply eq_intro; intros.
rewrite sup_ax; trivial.
rewrite replf_ax in H0; trivial.
revert H0; apply ex2_morph; red; intros; auto with *.
split; intros.
apply singl_elim in H0; trivial.
rewrite H0; apply singl_intro.
rewrite replf_ax; trivial.
rewrite sup_ax in H0; trivial.
revert H0; apply ex2_morph; red; intros; auto with *.
split; intros.
rewrite H0; apply singl_intro.
apply singl_elim in H0; trivial.
Qed.
Lemma union_is_sup a :
union a == sup a (fun x => x).
apply eq_intro; intros.
rewrite sup_ax;[|do 2 red; auto].
apply union_elim in H; destruct H.
eauto.
rewrite sup_ax in H;[|do 2 red; auto].
destruct H; eauto using union_intro.
Qed.
Lemma power_sup_closed a I f :
ext_fun I f ->
(forall x, x ∈ I -> f x ∈ power a) ->
sup I f ∈ power a.
intros fext tyf; apply power_intro; intros.
apply sup_ax in H; trivial.
destruct H as (?,?,tyz).
apply power_elim with (f x); auto.
Qed.
(** Conditional set *)
Definition if_prop P x y :=
cond_set P x ∪ cond_set (~P) y.
Instance if_prop_morph : Proper (iff ==> eq_set ==> eq_set ==> eq_set) if_prop.
do 4 red; intros.
unfold if_prop.
apply union2_morph.
apply cond_set_morph; auto.
apply cond_set_morph; auto.
rewrite H; reflexivity.
Qed.
Lemma if_left (P:Prop) x y : P -> if_prop P x y == x.
unfold if_prop; intros.
apply eq_intro; intros.
apply union2_elim in H0; destruct H0.
rewrite cond_set_ax in H0.
destruct H0; trivial.
rewrite cond_set_ax in H0; destruct H0; contradiction.
apply union2_intro1; rewrite cond_set_ax; auto.
Qed.
Lemma if_right (P:Prop) x y : ~P -> if_prop P x y == y.
unfold if_prop; intros.
apply eq_intro; intros.
apply union2_elim in H0; destruct H0.
rewrite cond_set_ax in H0; destruct H0; contradiction.
rewrite cond_set_ax in H0.
destruct H0; trivial.
apply union2_intro2; rewrite cond_set_ax; auto.
Qed.
(** Russel's paradox *)
Section Russell.