-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzfc_structures.lean
1693 lines (1525 loc) · 58.2 KB
/
zfc_structures.lean
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
import order.lattice
set_option old_structure_cmd true
universe u
variable (α : Type u)
namespace zfc
class has_zmem extends has_mem α α
instance [has_zmem α] : has_subset α :=
⟨λ x y, ∀ z, z ∈ x → z ∈ y⟩
variable {α}
theorem subset.refl [has_zmem α] (x : α) : x ⊆ x := λ z, id
theorem subset.trans [has_zmem α] {x y z : α}
(hxy : x ⊆ y) (hyz : y ⊆ z) : x ⊆ z :=
λ p hp, hyz p $ hxy p hp
instance [has_zmem α] : preorder α :=
⟨(⊆), _, subset.refl, λ x y z, subset.trans⟩
variable α
class is_extensional extends has_zmem α :=
(ext : ∀ x y : α, (∀ z, z ∈ x ↔ z ∈ y) → x = y )
variable {α}
theorem subset.antisymm [is_extensional α] {x y : α}
(hxy : x ⊆ y) (hyx : y ⊆ x) : x = y :=
is_extensional.ext x y $ λ z, ⟨λ hx, hxy z hx, λ hy, hyx z hy⟩
instance partial_order [is_extensional α] : partial_order α :=
{ le_antisymm := λ x y, subset.antisymm,
.. zfc.preorder }
variable α
class has_zempty extends has_zmem α, has_emptyc α :=
(not_zmem_empty : ∀ x, x ∉ (∅:α))
class has_upair extends has_zmem α :=
(upair : α → α → α)
(zmem_upair_iff_eq_or_eq : ∀ x y z, z ∈ upair x y ↔ z = x ∨ z = y)
variable {α}
theorem not_zmem_empty [has_zempty α] : ∀ {x}, x ∉ (∅:α) :=
has_zempty.not_zmem_empty
def upair [has_upair α] : α → α → α :=
has_upair.upair
def zmem_upair_iff_eq_or_eq [has_upair α] {x y z : α} :
z ∈ upair x y ↔ z = x ∨ z = y :=
has_upair.zmem_upair_iff_eq_or_eq x y z
theorem zmem_upair_left [has_upair α] {x y : α} : x ∈ upair x y :=
zmem_upair_iff_eq_or_eq.2 $ or.inl rfl
theorem zmem_upair_right [has_upair α] {x y : α} : y ∈ upair x y :=
zmem_upair_iff_eq_or_eq.2 $ or.inr rfl
def opair [has_upair α] (x y : α) : α :=
upair (upair x x) (upair x y)
theorem opair.ext [has_upair α] {p q r s : α}
(h : opair p q = opair r s) : p = r ∧ q = s :=
begin
have h1 : upair p p ∈ opair p q,
from zmem_upair_left,
have h2 : upair p q ∈ opair p q,
from zmem_upair_right,
have h3 : p ∈ upair p p,
from zmem_upair_left,
have h4 : p ∈ upair p q,
from zmem_upair_left,
have h5 : q ∈ upair p q,
from zmem_upair_right,
have h6 : upair r r ∈ opair r s,
from zmem_upair_left,
have h7 : upair r s ∈ opair r s,
from zmem_upair_right,
have h8 : r ∈ upair r r,
from zmem_upair_left,
have h9 : r ∈ upair r s,
from zmem_upair_left,
have h0 : s ∈ upair r s,
from zmem_upair_right,
rw h at h1 h2,
rw ← h at h6 h7,
unfold opair at h1 h2 h6 h7,
rw zmem_upair_iff_eq_or_eq at h1 h2 h6 h7,
cases h1,
{ rw [h1, zmem_upair_iff_eq_or_eq, or_self] at h3,
subst h3,
cases h2,
{ rw [h2, zmem_upair_iff_eq_or_eq, or_self] at h5,
subst h5,
rw or_self at h7,
rw [h7, zmem_upair_iff_eq_or_eq, or_self] at h0,
subst h0,
split, refl, refl },
{ rw [h2, zmem_upair_iff_eq_or_eq] at h5,
cases h5; subst h5,
{ rw [← h2, zmem_upair_iff_eq_or_eq, or_self] at h0,
subst h0,
split, refl, refl },
{ split, refl, refl } } },
{ rw [← h1, zmem_upair_iff_eq_or_eq, or_self] at h9,
subst h9,
rw [← h1, zmem_upair_iff_eq_or_eq, or_self] at h0,
subst h0,
rw or_self at h2,
rw [h2, zmem_upair_iff_eq_or_eq, or_self] at h5,
subst h5,
split, refl, refl }
end
theorem opair.iff [has_upair α] {p q r s : α} : opair p q = opair r s ↔ p = r ∧ q = s :=
⟨opair.ext, λ ⟨hpq, hrs⟩, hpq ▸ hrs ▸ rfl⟩
variable α
class has_sUnion extends has_zmem α :=
(sUnion : α → α)
(zmem_sUnion_iff_zmem_zmem : ∀ x z, z ∈ sUnion x ↔ ∃ t, z ∈ t ∧ t ∈ x)
variable {α}
def sUnion [has_sUnion α] : α → α :=
has_sUnion.sUnion
def zmem_sUnion_iff_zmem_zmem [has_sUnion α] {x z : α} : z ∈ sUnion x ↔ ∃ t, z ∈ t ∧ t ∈ x :=
has_sUnion.zmem_sUnion_iff_zmem_zmem x z
variable α
class has_sUnion_upair extends has_sUnion α, has_upair α
instance [has_sUnion_upair α] : has_union α :=
⟨λ x y, sUnion $ upair x y⟩
instance [has_sUnion_upair α] : has_insert α α :=
⟨λ x A, upair x x ∪ A⟩
lemma union_def [has_sUnion_upair α] (x y : α) : x ∪ y = (sUnion $ upair x y) := rfl
lemma insert_def [has_sUnion_upair α] (x A : α) : has_insert.insert x A = upair x x ∪ A := rfl
variable {α}
lemma zmem_union_iff_zmem_or_zmem [has_sUnion_upair α] {x y z : α} : z ∈ x ∪ y ↔ z ∈ x ∨ z ∈ y :=
begin
rw [union_def, zmem_sUnion_iff_zmem_zmem],
split,
{ intro H,
rcases H with ⟨t, H1, H2⟩,
rw [zmem_upair_iff_eq_or_eq] at H2,
cases H2; subst H2,
{ left, assumption },
{ right, assumption } },
{ intro H,
cases H,
{ existsi x,
split, exact H, exact zmem_upair_left },
{ existsi y,
split, exact H, exact zmem_upair_right } }
end
lemma zmem_insert_iff_eq_or_zmem [has_sUnion_upair α] {x A z : α} : z ∈ has_insert.insert x A ↔ z = x ∨ z ∈ A :=
by rw [insert_def, zmem_union_iff_zmem_or_zmem, zmem_upair_iff_eq_or_eq, or_self]
theorem zmem_insert [has_sUnion_upair α] {x y : α} : x ∈ has_insert.insert x y :=
zmem_insert_iff_eq_or_zmem.2 $ or.inl rfl
theorem zmem_insert_of_zmem [has_sUnion_upair α] {x y z : α} (H : x ∈ z) : x ∈ has_insert.insert y z :=
zmem_insert_iff_eq_or_zmem.2 $ or.inr H
def succ [has_sUnion_upair α] : α → α :=
λ x, has_insert.insert x x
theorem zmem_succ_iff_eq_or_zmem [has_sUnion_upair α] {x y : α} : x ∈ succ y ↔ x = y ∨ x ∈ y :=
zmem_insert_iff_eq_or_zmem
theorem zmem_succ [has_sUnion_upair α] {x : α} : x ∈ succ x :=
zmem_succ_iff_eq_or_zmem.2 $ or.inl rfl
theorem zmem_succ_of_zmem [has_sUnion_upair α] {x y : α} (H : x ∈ y) : x ∈ succ y :=
zmem_succ_iff_eq_or_zmem.2 $ or.inr H
variable α
class has_powerset extends has_zmem α :=
(powerset : α → α)
(zmem_powerset : ∀ x z, z ∈ powerset x ↔ z ⊆ x)
class has_comprehension extends has_zmem α :=
(comprehension : α → (α → Prop) → α)
(zmem_comprehension_iff : ∀ A p x, x ∈ comprehension A p ↔ x ∈ A ∧ p x)
class has_infty :=
(infinity : α)
notation `∞` := has_infty.infinity _
class has_replacement extends has_zmem α :=
(replacement : α → (α → α → Prop) → α)
(zmem_replacement_iff : ∀ A (f : α → α → Prop) y (H : ∀ A B C, f A B → f A C → B = C), (y ∈ replacement A f ↔ ∃ x, x ∈ A ∧ f x y))
class has_infty_replacement_powerset extends has_infty α, has_replacement α, has_powerset α
class has_infty_replacement_powerset_sUnion extends has_infty_replacement_powerset α, has_sUnion α
variable {α}
instance has_infty.to_inhabited [has_infty α] : inhabited α :=
⟨∞⟩
def powerset [has_powerset α] : α → α :=
has_powerset.powerset
theorem zmem_powerset [has_powerset α] : ∀ {x z : α}, z ∈ powerset x ↔ z ⊆ x :=
has_powerset.zmem_powerset
def comprehension [has_comprehension α] : α → (α → Prop) → α :=
has_comprehension.comprehension
theorem zmem_comprehension_iff [has_comprehension α] : ∀ {A : α} {p x}, x ∈ comprehension A p ↔ x ∈ A ∧ p x :=
has_comprehension.zmem_comprehension_iff
def replacement [has_replacement α] : α → (α → α → Prop) → α :=
has_replacement.replacement
theorem zmem_replacement_iff [has_replacement α] {A} {f : α → α → Prop} {y} (H : ∀ A B C, f A B → f A C → B = C) :
(y ∈ replacement A f ↔ ∃ x, x ∈ A ∧ f x y) :=
has_replacement.zmem_replacement_iff A f y H
instance has_comprehension.to_has_zempty [s : has_comprehension α] [inhabited α] : has_zempty α :=
{ emptyc := comprehension (inhabited.default α) (λ x, false),
not_zmem_empty := λ x hx, begin
simp [∅] at hx,
rw [zmem_comprehension_iff] at hx,
exact hx.2
end,
.. s }
instance has_replacement.to_has_comprehension [s : has_replacement α] : has_comprehension α :=
{ comprehension := λ A p, replacement A (λ x y, x = y ∧ p x),
zmem_comprehension_iff := λ A p x, begin
have h1 : ∀ A B C, A = B ∧ p A → A = C ∧ p A → B = C,
{ intros A B C h1 h2,
rw [← h1.1, ← h2.1] },
rw [zmem_replacement_iff h1],
split,
{ intro H,
rcases H with ⟨w, H1, H2, H3⟩,
subst H2,
exact ⟨H1, H3⟩ },
{ intro H,
existsi x,
simpa }
end,
.. s }
instance has_infty_replacement_powerset.to_has_zempty [s : has_infty_replacement_powerset α] : has_zempty α :=
{ .. s, .. has_comprehension.to_has_zempty }
instance has_infty_replacement_powerset.to_has_upair [s : has_infty_replacement_powerset α] : has_upair α :=
{ upair := λ x y, replacement (powerset (powerset ∅)) (λ m n, m = ∅ ∧ n = x ∨ m = powerset ∅ ∧ n = y),
zmem_upair_iff_eq_or_eq := λ x y z, begin
have h1 : ∀ (A B C : α),
A = ∅ ∧ B = x ∨ A = powerset ∅ ∧ B = y →
A = ∅ ∧ C = x ∨ A = powerset ∅ ∧ C = y → B = C,
{ intros A B C h1 h2,
cases h1; cases h2;
cases h1 with h3 h4;
cases h2 with h5 h6,
{ subst h4, subst h6 },
{ exfalso,
rw h3 at h5,
have h7 : (∅:α) ∈ powerset ∅,
{ rw zmem_powerset,
exact subset.refl ∅ },
rw ← h5 at h7,
exact not_zmem_empty h7 },
{ exfalso,
rw h3 at h5,
have h7 : (∅:α) ∈ powerset ∅,
{ rw zmem_powerset,
exact subset.refl ∅ },
rw h5 at h7,
exact not_zmem_empty h7 },
{ subst h4, subst h6 } },
rw zmem_replacement_iff h1,
split,
{ intro H,
rcases H with ⟨w, H1, ⟨H2, H3⟩ | ⟨H2, H3⟩⟩,
{ left, assumption },
{ right, assumption } },
{ intro H,
cases H,
{ existsi ∅,
split,
{ rw zmem_powerset,
intros z hz,
exfalso,
exact not_zmem_empty hz },
{ left, split, refl, assumption } },
{ existsi powerset ∅,
split,
{ rw zmem_powerset,
exact subset.refl _ },
{ right, split, refl, assumption } } }
end,
.. s }
instance has_infty_replacement_powerset_sUnion.to_has_sUnion_upair [s : has_infty_replacement_powerset_sUnion α] : has_sUnion_upair α :=
{ .. s, .. has_infty_replacement_powerset.to_has_upair }
variable α
class has_zinfty extends has_infty α, has_infty_replacement_powerset_sUnion α :=
(empty_zmem_infinity : (∅:α) ∈ (∞:α))
(succ_zmem_infinity_of_zmem_infinity : ∀ x:α, x ∈ (∞:α) → succ x ∈ (∞:α))
class is_regular extends has_zmem α :=
(regular : ∀ x : α, (∃ y, y ∈ x) → (∃ y : α, y ∈ x ∧ ∀ z, z ∈ y → z ∈ x → false))
variable {α}
theorem empty_zmem_infinity [has_zinfty α] : (∅:α) ∈ (∞:α) :=
has_zinfty.empty_zmem_infinity α
theorem succ_zmem_infinity_of_zmem_infinity [has_zinfty α] : ∀ x:α, x ∈ (∞:α) → succ x ∈ (∞:α) :=
has_zinfty.succ_zmem_infinity_of_zmem_infinity
theorem regular [is_regular α] : ∀ x : α, (∃ y, y ∈ x) → (∃ y : α, y ∈ x ∧ ∀ z, z ∈ y → z ∈ x → false) :=
is_regular.regular
variable α
class zf extends has_zmem α, is_extensional α, has_sUnion α, has_powerset α, has_replacement α, has_zinfty α, is_regular α
section zf
variables {α} [zf α] {x y z : α}
theorem singleton_def : {x} = has_insert.insert x (∅:α) := rfl
theorem zmem_singleton_iff : x ∈ ({y}:α) ↔ x = y :=
begin
rw [singleton_def, zmem_insert_iff_eq_or_zmem],
apply or_iff_left_of_imp,
intro H,
exfalso,
exact not_zmem_empty H
end
theorem zmem_singleton : x ∈ ({x}:α) :=
begin
rw [singleton_def, zmem_insert_iff_eq_or_zmem],
left, refl
end
theorem not_zmem_self : x ∉ x :=
λ h, begin
rcases regular {x} ⟨x, zmem_singleton⟩ with ⟨y, h1, h2⟩,
rw zmem_singleton_iff at h1,
subst h1,
exact h2 y h zmem_singleton
end
theorem not_zmem_and_zmem : x ∈ y → y ∈ x → false :=
λ hxy hyx, begin
rcases regular {x, y} ⟨x, by simp [zmem_insert_iff_eq_or_zmem]; right; exact zmem_singleton⟩ with ⟨z, h1, h2⟩,
rw [zmem_insert_iff_eq_or_zmem, zmem_singleton_iff] at h1,
cases h1; subst h1,
{ apply h2 _ hxy,
simp [zmem_insert_iff_eq_or_zmem],
right, exact zmem_singleton },
{ apply h2 _ hyx,
simp [zmem_insert_iff_eq_or_zmem] }
end
theorem succ.ext {x y : α} (H : succ x = succ y) : x = y :=
begin
simp [succ] at H,
have H1 : x ∈ has_insert.insert x x,
{ rw zmem_insert_iff_eq_or_zmem,
left, refl },
have H2 : y ∈ has_insert.insert y y,
{ rw zmem_insert_iff_eq_or_zmem,
left, refl },
rw [H, zmem_insert_iff_eq_or_zmem] at H1,
rw [← H, zmem_insert_iff_eq_or_zmem] at H2,
cases H1,
{ assumption },
{ cases H2,
{ subst H2 },
{ exfalso,
exact not_zmem_and_zmem H1 H2 } }
end
def prod : α → α → α :=
λ X Y, comprehension (powerset $ powerset $ X ∪ Y) (λ z, ∃ x y, x ∈ X ∧ y ∈ Y ∧ z = opair x y)
theorem zmem_prod {A B : α} (hx : x ∈ A) (hy : y ∈ B) : opair x y ∈ prod A B :=
zmem_comprehension_iff.2
⟨zmem_powerset.2 $ λ z (hz : z ∈ opair x y),
or.cases_on (zmem_upair_iff_eq_or_eq.1 hz)
(λ hzx, zmem_powerset.2 $ λ w hw,
or.cases_on (zmem_upair_iff_eq_or_eq.1 $ (hzx ▸ hw : w ∈ upair x x))
(λ hwx, zmem_union_iff_zmem_or_zmem.2 $ or.inl $ hwx.symm ▸ hx)
(λ hwx, zmem_union_iff_zmem_or_zmem.2 $ or.inl $ hwx.symm ▸ hx))
(λ hzxy, zmem_powerset.2 $ λ w hw,
or.cases_on (zmem_upair_iff_eq_or_eq.1 $ (hzxy ▸ hw : w ∈ upair x y))
(λ hwx, zmem_union_iff_zmem_or_zmem.2 $ or.inl $ hwx.symm ▸ hx)
(λ hwy, zmem_union_iff_zmem_or_zmem.2 $ or.inr $ hwy.symm ▸ hy)),
x, y, hx, hy, rfl⟩
theorem zmem_left_of_zmem_prod {A B : α} (h : opair x y ∈ prod A B) : x ∈ A :=
let ⟨x1, y1, hx1, hy1, h⟩ := (zmem_comprehension_iff.1 h).2 in
(opair.ext h).1.symm ▸ hx1
theorem zmem_right_of_zmem_prod {A B : α} (h : opair x y ∈ prod A B) : y ∈ B :=
let ⟨x1, y1, hx1, hy1, h⟩ := (zmem_comprehension_iff.1 h).2 in
(opair.ext h).2.symm ▸ hy1
class is_relation (f : α) : Prop :=
(eq_opair_of_zmem : ∀ z, z ∈ f → ∃ x y, z = opair x y)
def dom (f : α) : α :=
replacement f (λ z x, ∃ y, z = opair x y)
def range (f : α) : α :=
replacement f (λ z y, ∃ x, z = opair x y)
class is_function (f : α) extends is_relation f : Prop :=
(exists_unique : ∀ x, x ∈ dom f → ∃! y, opair x y ∈ f)
class is_injective (f : α) extends is_function f : Prop :=
(injective : ∀ x y z, opair x z ∈ f → opair y z ∈ f → x = y)
theorem zmem_dom_iff {f x : α} : x ∈ dom f ↔ ∃ y, opair x y ∈ f :=
begin
have h1 : ∀ (A B C : α), (∃ (y : α), A = opair B y) → (∃ (y : α), A = opair C y) → B = C,
{ intros A B C h1 h2,
cases h1 with m h1,
cases h2 with n h2,
subst h1,
exact (opair.ext h2).1 },
rw [dom, zmem_replacement_iff h1],
split; intro H,
{ rcases H with ⟨z, h1, w, h2⟩,
subst h2, existsi w, assumption },
{ cases H with z h,
existsi opair x z,
split, assumption, existsi z, refl }
end
theorem zmem_range_iff {f y : α} : y ∈ range f ↔ ∃ x, opair x y ∈ f :=
begin
have h1 : ∀ (A B C : α), (∃ (x : α), A = opair x B) → (∃ (x : α), A = opair x C) → B = C,
{ intros A B C h1 h2,
cases h1 with m h1,
cases h2 with n h2,
subst h1,
exact (opair.ext h2).2 },
rw [range, zmem_replacement_iff h1],
split; intro H,
{ rcases H with ⟨z, h1, w, h2⟩,
subst h2, existsi w, assumption },
{ cases H with z h,
existsi opair z y,
split, assumption, existsi z, refl }
end
theorem zmem_dom_of_opair_zmem {f : α} [is_function f] {x y : α} (H : opair x y ∈ f) : x ∈ dom f :=
zmem_dom_iff.2 ⟨_, H⟩
theorem zmem_range_of_opair_zmem {f : α} [is_function f] {x y : α} (H : opair x y ∈ f) : y ∈ range f :=
zmem_range_iff.2 ⟨_, H⟩
def eval (f : α) [is_function f] (x : α) : α :=
sUnion $ comprehension (range f) (λ y, opair x y ∈ f)
theorem eval_unique {f : α} [is_function f] {x y : α} (H : x ∈ dom f) (Hxy : opair x y ∈ f) : y = eval f x :=
begin
rcases is_function.exists_unique _ H with ⟨y', H1, H2⟩,
have H3 := H2 _ Hxy, subst H3,
apply is_extensional.ext,
intro z, split; intro hz,
{ rw [eval, zmem_sUnion_iff_zmem_zmem],
existsi y,
rw [zmem_comprehension_iff, zmem_range_iff],
exact ⟨hz, ⟨x, Hxy⟩, Hxy⟩ },
{ rw [eval, zmem_sUnion_iff_zmem_zmem] at hz,
rcases hz with ⟨t, ht1, ht2⟩,
rw [zmem_comprehension_iff, zmem_range_iff] at ht2,
specialize H2 _ ht2.2,
subst H2,
exact ht1 }
end
theorem opair_eval_zmem {f : α} [is_function f] {x : α} (H : x ∈ dom f) : opair x (eval f x) ∈ f :=
begin
rcases is_function.exists_unique _ H with ⟨y, H1, H2⟩,
have H3 := eval_unique H H1,
subst H3,
exact H1
end
theorem eval_zmem_range {f : α} [is_function f] {x : α} (H : x ∈ dom f) : eval f x ∈ range f :=
zmem_range_iff.2 ⟨_, opair_eval_zmem H⟩
def inv (f : α) : α :=
replacement f (λ x y, ∃ m n, opair m n = x ∧ opair n m = y)
theorem inv.aux (A B C : α)
(H1 : ∃ (m n : α), opair m n = A ∧ opair n m = B)
(H2 : ∃ (m n : α), opair m n = A ∧ opair n m = C) :
B = C :=
begin
rcases H1 with ⟨m1, n1, H3, H4⟩,
rcases H2 with ⟨m2, n2, H5, H6⟩,
subst H3, subst H4, subst H6,
rw opair.iff at H5 ⊢,
cases H5 with H1 H2,
split; symmetry; assumption
end
theorem zmem_inv_iff {f x y : α} : opair x y ∈ inv f ↔ opair y x ∈ f :=
begin
rw [inv, zmem_replacement_iff inv.aux],
split; intro h,
{ rcases h with ⟨z, hz, m, n, h1, h2⟩,
rcases opair.ext h2 with ⟨h3, h4⟩,
subst h1, subst h3, subst h4,
exact hz },
{ exact ⟨_, h, _, _, rfl, rfl⟩ }
end
instance inv.is_relation (f : α) : is_relation (inv f) :=
{ eq_opair_of_zmem := begin
intros z hz,
rw [inv, zmem_replacement_iff inv.aux] at hz,
rcases hz with ⟨x, hxf, m, n, h1, h2⟩,
subst h2,
exact ⟨_, _, rfl⟩
end }
instance inv.is_injective (f : α) [is_injective f] : is_injective (inv f) :=
{ exists_unique := begin
intros x hx,
rw zmem_dom_iff at hx,
cases hx with y hy,
existsi y,
split,
{ exact hy },
{ intros z hz,
rw zmem_inv_iff at hy hz,
exact is_injective.injective _ _ _ hz hy }
end,
injective := begin
intros x y z hx hy,
rw zmem_inv_iff at hx hy,
have h1 : z ∈ dom f,
{ rw zmem_dom_iff,
exact ⟨_, hy⟩ },
have h2 := is_function.exists_unique z h1,
exact unique_of_exists_unique h2 hx hy
end,
.. inv.is_relation f }
theorem inv.dom {f : α} : dom (inv f) = range f :=
begin
apply is_extensional.ext,
intro z,
rw [zmem_dom_iff, zmem_range_iff],
split; intro hz,
{ cases hz with y h,
rw zmem_inv_iff at h,
exact ⟨_, h⟩ },
{ cases hz with y h,
existsi y,
rw zmem_inv_iff,
exact h }
end
theorem inv.range {f : α} : range (inv f) = dom f :=
begin
apply is_extensional.ext,
intro z,
rw [zmem_dom_iff, zmem_range_iff],
split; intro hz,
{ cases hz with y h,
rw zmem_inv_iff at h,
exact ⟨_, h⟩ },
{ cases hz with y h,
existsi y,
rw zmem_inv_iff,
exact h }
end
variable α
def omega : α :=
comprehension ∞ (λ n, ∀ A:α, ∅ ∈ A → (∀ k, k ∈ A → succ k ∈ A) → n ∈ A)
notation `ω` := omega _
variable {α}
theorem empty_zmem_omega : (∅:α) ∈ (ω:α) :=
zmem_comprehension_iff.2 ⟨empty_zmem_infinity, λ A h1 h2, h1⟩
theorem succ_zmem_omega_of_zmem (H : x ∈ (ω:α)) : succ x ∈ (ω:α) :=
zmem_comprehension_iff.2
⟨succ_zmem_infinity_of_zmem_infinity x $ (zmem_comprehension_iff.1 H).1,
λ A h1 h2, h2 x $ (zmem_comprehension_iff.1 H).2 A h1 h2⟩
theorem induction (p : α → Prop) (H1 : p ∅) (H2 : ∀ k, k ∈ omega α → p k → p (succ k)) (n : α) (Hn : n ∈ omega α) : p n :=
(zmem_comprehension_iff.1 $
(zmem_comprehension_iff.1 Hn).2 (comprehension (omega α) p)
(zmem_comprehension_iff.2 ⟨empty_zmem_omega, H1⟩)
(λ k hk, zmem_comprehension_iff.2
⟨succ_zmem_omega_of_zmem $ (zmem_comprehension_iff.1 hk).1,
H2 k (zmem_comprehension_iff.1 hk).1 (zmem_comprehension_iff.1 hk).2⟩)).2
theorem omega.structure (H : x ∈ (ω:α)) : x = ∅ ∨ ∃ y ∈ (ω:α), x = succ y :=
@induction α _ (λ z:α, z = ∅ ∨ ∃ y ∈ (ω:α), z = succ y)
(or.inl rfl)
(λ k hk1 hk2, or.inr ⟨k, hk1, rfl⟩)
x H
class is_transitive (x : α) : Prop :=
(zmem_trans : ∀ m n, m ∈ n → n ∈ x → m ∈ x)
instance omega.transitive : is_transitive (ω:α) :=
{ zmem_trans := λ m n hmn hno, @induction α _ (λ z, ∀ x, x ∈ z → x ∈ (ω:α))
(λ x hx, false.elim $ not_zmem_empty hx)
(λ k hk1 hk2 x hx, or.cases_on (zmem_succ_iff_eq_or_zmem.1 hx)
(λ hxk, hxk.symm ▸ hk1)
(hk2 x))
n hno m hmn }
variable α
def nat.to_omega : nat → α
| nat.zero := ∅
| (nat.succ n) := succ (n.to_omega)
theorem nat.to_omega.zmem_omega : ∀ n, nat.to_omega α n ∈ omega α
| nat.zero := empty_zmem_omega
| (nat.succ n) := succ_zmem_omega_of_zmem $ nat.to_omega.zmem_omega n
def nat.to_omega' : nat → {x // x ∈ omega α} :=
λ n, ⟨nat.to_omega α n, nat.to_omega.zmem_omega α n⟩
theorem nat.to_omega.injective : function.injective (nat.to_omega α) :=
begin
intros m n H,
induction m with m ihm generalizing n H;
induction n with n ihn,
{ refl },
{ exfalso,
have h1 : nat.to_omega α n ∈ nat.to_omega α (nat.succ n),
{ unfold nat.to_omega,
unfold succ,
rw zmem_insert_iff_eq_or_zmem,
left, refl },
rw ← H at h1,
exact not_zmem_empty h1 },
{ exfalso,
have h1 : nat.to_omega α m ∈ nat.to_omega α (nat.succ m),
{ unfold nat.to_omega,
unfold succ,
rw zmem_insert_iff_eq_or_zmem,
left, refl },
rw H at h1,
exact not_zmem_empty h1 },
{ unfold nat.to_omega at H,
congr,
exact ihm (succ.ext H) }
end
-- it isn't supposed to be surjective unless the model is transitive
theorem nat.to_omega.surjective_cheating : function.surjective (nat.to_omega' α) :=
begin
intros x,
cases x with x hx,
dsimp [omega] at hx,
rw zmem_comprehension_iff at hx,
cases hx with h1 h2,
let cheating := comprehension (omega α) (nat.to_omega α '' set.univ),
specialize h2 cheating,
simp [cheating, zmem_comprehension_iff] at h2,
specialize h2 empty_zmem_omega,
specialize h2 ⟨0, rfl⟩,
specialize h2 (λ k hk1 ⟨n, hk2⟩, ⟨succ_zmem_omega_of_zmem hk1, nat.succ n, by rw ← hk2; refl⟩),
rcases h2 with ⟨h2, n, h3⟩,
existsi n,
apply subtype.eq,
exact h3
end
variable {α}
section erase
def erase (x y : α) : α :=
comprehension x (λ z, z ≠ y)
theorem zmem_erase_iff : z ∈ erase x y ↔ z ∈ x ∧ z ≠ y :=
zmem_comprehension_iff
theorem zmem_of_zmem_erase (H : z ∈ erase x y) : z ∈ x :=
(zmem_erase_iff.1 H).1
theorem ne_of_zmem_erase (H : z ∈ erase x y) : z ≠ y :=
(zmem_erase_iff.1 H).2
theorem zmem_erase_of_zmem_of_ne (H1 : z ∈ x) (H2 : z ≠ y) : z ∈ erase x y :=
zmem_erase_iff.2 ⟨H1, H2⟩
end erase
section recursion
variables (f A c : α) [is_function f] (H1 : dom f = prod ω A) (H2 : range f ⊆ A) (H3 : c ∈ A)
-- {(x,y) ∈ ω × A | ∃ h : ω → A, h(∅) = c ∧ (∀ m ∈ x, h(m⁺) = f(m, h(m))) ∧ h(x) = y}
def recursion : α :=
comprehension (prod ω A)
(λ z, ∃ (h x y : α) [is_function h] (H4 : z = opair x y) (H5 : dom h = ω) (H6 : range h ⊆ A)
(H7 : opair ∅ c ∈ h) (H8: ∀ m hm hsm, m ∈ x → opair m hm ∈ h → opair (opair m hm) hsm ∈ f → opair (succ m) hsm ∈ h), z ∈ h)
include H3
theorem recursion.empty : opair ∅ c ∈ recursion f A c :=
begin
let h : α := prod ω {c},
have hf : is_function h,
{ split,
{ intros z hz,
dsimp [h] at hz,
rw [prod, zmem_comprehension_iff] at hz,
replace hz := hz.2,
rcases hz with ⟨x', y', _, _, h'⟩,
exact ⟨x', y', h'⟩ },
{ intros x' hx',
existsi c,
rw [zmem_dom_iff] at hx',
rcases hx' with ⟨y, hy⟩,
dsimp [h] at hy ⊢,
split,
{ exact zmem_prod (zmem_left_of_zmem_prod hy) zmem_singleton },
{ intros y' hy',
replace hy' := zmem_right_of_zmem_prod hy',
rwa zmem_singleton_iff at hy' } } },
have H5 : dom h = ω,
{ apply is_extensional.ext,
intro z,
rw [zmem_dom_iff],
split; intro h5,
{ cases h5 with y hy,
exact zmem_left_of_zmem_prod hy },
{ existsi c,
exact zmem_prod h5 zmem_singleton } },
have H6 : range h ⊆ A,
{ intros z hz,
rw [zmem_range_iff] at hz,
cases hz with y hy,
replace hy := zmem_right_of_zmem_prod hy,
rw zmem_singleton_iff at hy,
subst hy,
exact H3 },
have H7 : opair ∅ c ∈ h,
{ exact zmem_prod empty_zmem_omega zmem_singleton },
rw [recursion, zmem_comprehension_iff],
split,
{ exact zmem_prod empty_zmem_omega H3 },
{ exact ⟨h, _, _, hf, rfl, H5, H6, H7, (λ m _ _ hm, false.elim $ not_zmem_empty hm), H7⟩ }
end
omit H3
include H1 H2 H3
theorem recursion.succ (h1 : opair x y ∈ recursion f A c) (h2 : opair (opair x y) z ∈ f) : opair (succ x) z ∈ recursion f A c :=
begin
have h3 : opair x y ∈ prod ω A,
{ rw [← H1, zmem_dom_iff], exact ⟨z, h2⟩ },
have h5 : z ∈ A,
{ apply H2, rw [zmem_range_iff], exact ⟨_, h2⟩ },
rw [recursion, zmem_comprehension_iff] at h1,
cases h1 with h1 h3,
rcases h3 with ⟨h, x', y', hf, H4, H5, H6, H7, H8, H9⟩,
have h4 : opair x y ∈ dom f,
{ rw H1, exact h1 },
let h' : α := comprehension (prod ω A) (λ w, ∀ m n, w = opair m n → ((m = succ x ∧ n = z) ∨ (m ≠ succ x ∧ w ∈ h))),
have hf' : is_function h' :=
{ eq_opair_of_zmem := λ z hz, begin
dsimp [h'] at hz,
rw [zmem_comprehension_iff] at hz,
cases hz with hz1 hz2,
rw [prod, zmem_comprehension_iff] at hz1,
rcases hz1.2 with ⟨x'', y'', _, _, h''⟩,
exact ⟨x'', y'', h''⟩
end,
exists_unique := begin
intros x hx,
rw [zmem_dom_iff] at hx,
cases hx with y hy,
dsimp [h'] at hy,
rw [zmem_comprehension_iff] at hy,
cases hy with hy1 hy2,
specialize hy2 x y rfl,
cases hy2 with hy2 hy2;
cases hy2 with hy2 hy3,
{ existsi y,
split,
{ dsimp [h'],
rw [zmem_comprehension_iff],
split, exact hy1,
intros m n hxy,
cases opair.ext hxy with hxy1 hxy2,
subst hxy1, subst hxy2,
left, split, subst hy2, subst hy3 },
{ intros z hz,
dsimp [h'] at hz,
rw [zmem_comprehension_iff] at hz,
cases hz with hz1 hz2,
specialize hz2 _ _ rfl,
cases hz2 with hz2 hz2;
cases hz2 with hz2 hz3,
{ subst hy3, subst hz3 },
{ exfalso, exact hz2 hy2 } } },
{ existsi y,
split,
{ dsimp [h'],
rw [zmem_comprehension_iff],
split, exact hy1,
intros m n hxy,
cases opair.ext hxy with hxy1 hxy2,
subst hxy1, subst hxy2,
right, split, exact hy2, exact hy3 },
{ intros z hz,
dsimp [h'] at hz,
rw [zmem_comprehension_iff] at hz,
cases hz with hz1 hz2,
specialize hz2 _ _ rfl,
cases hz2 with hz2 hz2;
cases hz2 with hz2 hz3,
{ exfalso, exact hy2 hz2 },
{ have hf1 := hf.exists_unique,
have hf2 : x ∈ dom h,
{ rw [zmem_dom_iff], existsi y, exact hy3 },
specialize hf1 _ hf2,
exact unique_of_exists_unique hf1 hz3 hy3 } } }
end },
have H5' : dom h' = ω,
{ apply is_extensional.ext,
intro w,
rw [zmem_dom_iff],
split; intro hw,
{ cases hw with w hw,
dsimp [h'] at hw,
rw [zmem_comprehension_iff] at hw,
cases hw with hw1 hw2,
exact zmem_left_of_zmem_prod hw1 },
{ cases classical.em (w = succ x) with hzk hzk,
{ existsi z,
dsimp [h'],
rw [zmem_comprehension_iff],
split,
{ exact zmem_prod hw h5 },
{ intros m n hmn,
cases opair.ext hmn with hmn1 hmn2,
subst hmn1, subst hmn2,
left, split, exact hzk, refl } },
{ have hf1 := hf.exists_unique,
specialize hf1 w (H5.symm ▸ hw),
rcases hf1 with ⟨w', hf1, hf2⟩,
existsi w',
dsimp [h'],
rw [zmem_comprehension_iff],
split,
have hf3 : w' ∈ range h,
{ rw [zmem_range_iff], existsi w, exact hf1 },
{ exact zmem_prod hw (H6 _ hf3) },
{ intros m n hmn,
cases opair.ext hmn with hmn1 hmn2,
subst hmn1, subst hmn2,
right, split, exact hzk, exact hf1 } } } },
have H6' : range h' ⊆ A,
{ intros z hz,
rw [zmem_range_iff] at hz,
cases hz with w hw,
dsimp [h'] at hw,
rw [zmem_comprehension_iff] at hw,
cases hw with hw1 hw2,
specialize hw2 _ _ rfl,
cases hw2 with hw2 hw2;
cases hw2 with hw2 hw3,
{ subst hw3,
apply H2,
rw [zmem_range_iff],
exact ⟨_, h2⟩ },
{ have hf1 : z ∈ range h,
{ rw [zmem_range_iff], existsi w, exact hw3 },
exact H6 _ hf1 } },
have H7' : opair ∅ c ∈ h',
{ dsimp [h'],
rw [zmem_comprehension_iff],
split,
{ exact zmem_prod empty_zmem_omega H3 },
{ intros m n hmn,
cases opair.ext hmn with hmn1 hmn2,
subst hmn1, subst hmn2,
right, split,
{ intro hmn1,
have hmn2 : x ∈ succ x := zmem_succ,
rw ← hmn1 at hmn2,
exact not_zmem_empty hmn2 },
{ exact H7 } } },
have H8' : ∀ (m hm hsm : α), m ∈ succ x → opair m hm ∈ h' → opair (opair m hm) hsm ∈ f → opair (succ m) hsm ∈ h',
{ intros m hm hsm hm1 hm2 hm3,
rw zmem_succ_iff_eq_or_zmem at hm1,
cases hm1 with hm1 hm1,
{ subst hm1,
dsimp [h'],
rw [zmem_comprehension_iff],
have hm4 : hsm ∈ range f,
{ rw [zmem_range_iff], existsi _, exact hm3 },
have hm5 : m ∈ ω,
{ rw ← H5', rw [zmem_dom_iff], existsi _, exact hm2 },
split,
{ exact zmem_prod (succ_zmem_omega_of_zmem hm5) (H2 _ hm4) },
{ intros m n hmn,
cases opair.ext hmn with hmn1 hmn2,
subst hmn1, subst hmn2,
left, split, refl,
dsimp [h'] at hm2,
rw [zmem_comprehension_iff] at hm2,
cases hm2 with hm8 hm6,
specialize hm6 _ _ rfl,
cases hm6 with hm6 hm6;
cases hm6 with hm6 hm7,
{ exfalso,
have hm9 : m ∈ succ m := zmem_succ,
rw ← hm6 at hm9,
exact not_zmem_self hm9 },
{ have hf1 := hf.exists_unique,
have hf2 : m ∈ dom h,
{ rw H5, exact hm5 },
specialize hf1 _ hf2,
have hf3 := unique_of_exists_unique hf1 hm7 H9,
subst hf3,
have hf4 := is_function.exists_unique _ h4,
exact unique_of_exists_unique hf4 hm3 h2 } } },
{ cases opair.ext H4 with H41 H42,
subst H41, subst H42,
dsimp [h'],
rw [zmem_comprehension_iff],
have hm4 : hsm ∈ range f,
{ rw [zmem_range_iff], existsi _, exact hm3 },
have hm5 : m ∈ ω,
{ rw ← H5', rw [zmem_dom_iff], existsi _, exact hm2 },
split,
{ exact zmem_prod (succ_zmem_omega_of_zmem hm5) (H2 _ hm4) },
{ intros m n hmn,
cases opair.ext hmn with hmn1 hmn2,
subst hmn1, subst hmn2,
right, split,
{ intro hmk,
replace hmk := succ.ext hmk,
subst hmk,
exact not_zmem_self hm1 },
{ have hm6 : opair m hm ∈ h,
{ dsimp [h'] at hm2,
rw [zmem_comprehension_iff] at hm2,
cases hm2 with hm8 hm6,
specialize hm6 _ _ rfl,
cases hm6 with hm6 hm6;
cases hm6 with hm6 hm7,
{ exfalso,
subst hm6,
apply not_zmem_and_zmem hm1 zmem_succ },
{ exact hm7 } },
exact H8 _ _ _ hm1 hm6 hm3 } } } },
have H9' : opair (succ x) z ∈ h',
{ dsimp [h'],
rw [zmem_comprehension_iff],
split,
{ exact zmem_prod (succ_zmem_omega_of_zmem $ zmem_left_of_zmem_prod h3) h5 },
{ intros m n hmn,