-
Notifications
You must be signed in to change notification settings - Fork 1
/
cardinal.v
1328 lines (1157 loc) · 34.8 KB
/
cardinal.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 ordinals.
Module Enumerator.
Export Ordinal. Export Function.
Export Map.
Definition chooser f a := forall x, sub x a -> nonempty x -> inc (f x) x.
Definition enumerator f a := forall o, is_ordinal o ->
nonempty (complement a (Im f o)) -> inc (f o) (complement a (Im f o)).
Section VarSec.
Variables (chooseF : E1) (a : E).
Hypothesis (chooseH : chooser chooseF a).
Definition enumerator_of := ordinal_rec (fun h =>
chooseF (complement a (Im (ev h) (domain h)))).
Lemma enum_of_enum : enumerator (enumerator_of) a.
Proof.
uhg;ir. uf enumerator_of.
rw ordinal_rec_pr;try am.
rw create_domain.
fold enumerator_of.
rw Im_ev_create. ap chooseH.
ap Z_sub. am.
Qed.
End VarSec.
Section VarSec2.
Variables (a : E) (enum : E1).
Hypothesis (Henum : enumerator enum a).
Lemma enumeration_ends : exists o, is_ordinal o & sub a (Im enum o).
Proof.
ap excluded_middle;uhg;ir.
assert (forall o, is_ordinal o -> nonempty (complement a (Im enum o))).
ir. ap excluded_middle;uhg;ir.
ap H. exists o;ee;au.
uhg;ir. ap excluded_middle;uhg;ir.
ap H1;exists a0;ap Z_inc;au.
assert (forall o, is_ordinal o -> inc (enum o) (complement a (Im enum o))).
ir. ap Henum. am. au.
assert (forall o, is_ordinal o -> forall o', inc o' o -> enum o <> enum o').
ir. uhg;ir.
assert (is_ordinal o'). apply ordinal_in_ordinal with o;am.
cp H2;cp H5. apply H1 in H6;apply H1 in H7.
apply Z_all in H6;ee.
rwi H4 H8. ap H8. ap Im_inc. am.
assert (forall o o', is_ordinal o -> is_ordinal o' -> enum o = enum o' -> o = o').
ir. destruct ordinal_inc_eq_inc with o o';au.
destruct H2 with o' o;au. nin H6. am.
destruct H2 with o o';au.
pose (r := fun x y => (is_ordinal y & x = enum y) \/ (~(exists o, is_ordinal o & x= enum o) & y=emptyset)).
assert ((forall x, ex (r x) & (unicity (r x)))).
ir;ee. apply by_cases with (exists o, is_ordinal o & x = enum o);ir.
nin H4. ee. exists x0. uf r. left. ee;au.
exists emptyset. right. ee;au.
uhg;ir. nin H4;nin H5. ee.
ap H3;au. wr H7;am.
ee. subst. nin H5. exists y;au.
ee;subst;nin H4;exists y';au.
ee;subst;tv.
pose (z := replacement r a).
apply ordinal_not_set. exists z;ir.
uf z. ap replacement_inc. uhg. am. exists (enum o);ee.
eapply Z_sub;ap H1. am.
uf r. left. ee;au.
Qed.
Definition l := Sow.sow (fun x => sub a (Im enum x)).
Lemma l_ordinal : is_ordinal l.
Proof.
ap Sow.sow_ordinal.
Qed.
Lemma l_pr : sub a (Im enum l).
Proof.
uf l. ap Sow.sow_property. ap enumeration_ends.
Qed.
Lemma l_smallest : forall o, is_ordinal o -> sub a (Im enum o) -> sub l o.
Proof.
uf l. ap Sow.sow_smallest.
Qed.
Lemma l_inc_cmp : forall o, inc o l -> inc (enum o) (complement a (Im enum o)).
Proof.
ir. ap Henum.
apply ordinal_in_ordinal with l;au. ap l_ordinal.
ap excluded_middle;uhg;ir.
cp H. cp l_ordinal;cp (ordinal_in_ordinal l_ordinal H).
rwi ordinal_inc_not_sub H1;au.
ap H1. ap l_smallest. am. uhg;ir;ap excluded_middle;uhg;ir;ap H0.
exists a0;ap Z_inc;au.
Qed.
Lemma l_Im_eq : a = Im enum l.
Proof.
ap extensionality. ap l_pr.
uhg;ir.
apply Im_ex in H. nin H;ee. subst.
eapply Z_sub. ap l_inc_cmp. am.
Qed.
Lemma l_enum_inj : Application.injects l enum.
Proof.
assert (forall x y, inc x y -> inc y l -> enum x = enum y -> x=y).
ir.
assert (inc x l). cp l_ordinal.
uh H2;ee;eapply H2;am.
cp (l_inc_cmp H0).
apply Z_pr in H3. nin H3. wr H1. ap Im_inc;am.
uhg;ir.
assert (is_ordinal x & is_ordinal y).
cp l_ordinal. ee;eapply ordinal_in_ordinal;am. ee.
destruct ordinal_inc_eq_inc with x y;au. nin H5;au.
symmetry. au.
Qed.
Lemma enum_ends_at_l : Application.bijective l a enum.
Proof.
uhg;ee. uhg;ir.
rw l_Im_eq. ap Im_inc;am.
ap l_enum_inj.
rw l_Im_eq. uhg;ir.
apply Im_ex in H. nin H;exists x;ee;au.
Qed.
Inductive enumr : E2P :=
| enumr_ir : forall x y, inc x l -> inc y l -> sub x y -> enumr (enum x) (enum y)
.
Lemma enumr_wo : is_well_order enumr a.
Proof.
uhg;ee. uhg;ee.
uhg;ee. ir.
apply enum_ends_at_l in H. nin H;ee;subst.
constructor. am. am. ap sub_refl.
uhg;ir.
inversion H1;subst;inversion H2;subst.
assert (x=y0). ap enum_ends_at_l;au.
subst. assert (y=x0).
ap enum_ends_at_l;au. subst.
ap uneq. ap extensionality;am.
uhg;ir.
inversion H1;subst;inversion H3;subst.
apply enum_ends_at_l in H7;au.
subst.
constructor;au. apply sub_trans with y0;am.
ir.
pose (z := Z l (fun x => inc (enum x) b)).
assert (nonempty z). nin H0.
cp H0. apply H in H1;apply enum_ends_at_l in H1;au. nin H1;ee.
subst. exists x0;ap Z_inc;au.
cp l_ordinal. uh H2. ee.
apply H4 in H1. nin H1.
exists (enum x). uh H1;ee.
apply Z_all in H5;ee.
clear H2;clear H3;clear H4.
uhg;ee;au. uhg;ee. au.
ir. cp H2.
apply H in H3. apply enum_ends_at_l in H3. nin H3;ee;subst.
constructor. am. am.
rw ordinal_sub_leq_of;try (apply ordinal_in_ordinal with l;try ap l_ordinal;try am).
ap H1. ap Z_inc;au. uf z. ap Z_sub.
Qed.
Lemma enum_rel_iso : is_isomorphism sub l enumr a (L l enum).
Proof.
assert (bijective l a (L l enum)).
ap map_of_bijective. ap enum_ends_at_l.
uhg;ee;au. uhg;ee;try am.
ir. rw create_ev;try am. rw create_ev;try am. constructor;am.
Qed.
End VarSec2.
Lemma all_wo : forall a, exists r, is_well_order r a.
Proof.
ir;econstructor. ap enumr_wo.
ap enum_of_enum.
uhg;ir. ap rep_inc. am.
Qed.
Section VarSec3.
Variables (r : E2P) (a : E).
Hypothesis (Hwo : is_well_order r a).
Definition chooseLeast x := unique_choose (is_min a r x).
(*note that we could use union (Z a (is_min a r x)) instead, this is just simpler*)
Lemma chooseLeast_chooses : chooser chooseLeast a.
Proof.
uhg;ir. uf chooseLeast.
cp Hwo. uh H1;ee.
cp (H2 x H H0).
apply unique_choose_pr in H3. am.
ap min_unicity. am.
Qed.
Definition enumLeast := enumerator_of chooseLeast a.
Lemma enumLeast_enum : enumerator enumLeast a.
Proof.
ap enum_of_enum. ap chooseLeast_chooses.
Qed.
Definition lLeast := l a enumLeast.
Lemma lLeast_ordinal : is_ordinal lLeast.
Proof.
ap l_ordinal.
Qed.
Lemma enumLeast_ends_at : Application.bijective lLeast a enumLeast.
Proof.
ap enum_ends_at_l. ap enumLeast_enum.
Qed.
Lemma enumLeast_pr : forall o, inc o lLeast ->
is_min a r (complement a (Im enumLeast o)) (enumLeast o).
Proof.
ir.
uf enumLeast. uf enumerator_of.
assert (is_ordinal o).
apply ordinal_in_ordinal with lLeast. ap lLeast_ordinal. am.
rw ordinal_rec_pr;try am.
rw create_domain. rw Im_ev_create.
uf chooseLeast. ap unique_choose_pr.
ap Hwo. ap Z_sub.
replace ((ordinal_rec
(fun h : E =>
unique_choose (is_min a r (complement a (Im (ev h) (domain h))))))) with
enumLeast. Focus 2. reflexivity.
exists (enumLeast o). ap l_inc_cmp.
ap enumLeast_enum. am.
ap min_unicity. am.
Qed.
Definition enumrLeast := enumr a enumLeast.
Lemma enumrLeast_eq_r : forall x y, inc x a -> inc y a -> r x y = enumrLeast x y.
Proof.
ir;ap iff_eq;ir.
cp H;cp H0. apply enumLeast_ends_at in H2. apply enumLeast_ends_at in H3.
nin H2;nin H3;ee;subst.
assert (is_ordinal x0 & is_ordinal x1). ee;apply ordinal_in_ordinal with lLeast;try am;
ap lLeast_ordinal. ee.
constructor;try am.
rw ordinal_sub_not_inc;try am.
uhg;ir.
cp (enumLeast_pr H2). cp (enumLeast_pr H3).
assert (r (enumLeast x1) (enumLeast x0)).
ap H8. ap Z_inc. am.
uhg;ir. Im_nin H9.
assert (inc x lLeast). cp lLeast_ordinal.
uh H11;ee;eapply H11;am.
apply enumLeast_ends_at in H10;au.
subst. apply ordinal_inc_inc_not with x x1;au.
assert (x1=x0). ap enumLeast_ends_at. am. am.
ap Hwo. am. am. am. am. subst.
apply lLeast_ordinal with x0. am. am.
nin H1.
fold lLeast in *.
cp (enumLeast_pr H1). cp (enumLeast_pr H2).
ap H4. ap Z_inc;au.
uhg;ir. Im_nin H6.
assert (inc x0 lLeast). cp lLeast_ordinal.
uh H8;ee. apply H8 with x. am. am.
apply enumLeast_ends_at in H7;au.
subst.
assert (is_ordinal x & is_ordinal x0).
ee;apply ordinal_in_ordinal with lLeast;try am;ap lLeast_ordinal.
ee. rwi ordinal_sub_not_inc H3;au.
Qed.
Lemma enumLeast_isomorphism : is_isomorphism sub lLeast r a (L lLeast enumLeast).
Proof.
assert (bijective lLeast a (L lLeast enumLeast)).
ap map_of_bijective. ap enumLeast_ends_at.
uhg;ee;try am. uhg;ee;try am.
ir. rw create_ev;try am;rw create_ev;try am.
rw enumrLeast_eq_r.
cp (enum_rel_iso enumLeast_enum).
uh H3;ee;uh H3;ee.
fold lLeast in *.
apply H5 in H2;try am.
clear H5.
rwi create_ev H2;try am. rwi create_ev H2;try am.
ap enumLeast_ends_at. am.
ap enumLeast_ends_at. am.
Qed.
End VarSec3.
Lemma wo_iso_ordinal : forall r a, is_well_order r a -> exists o, is_ordinal o &
are_rel_isomorphic sub o r a.
Proof.
ir. econstructor. ee. ap lLeast_ordinal.
econstructor. ap enumLeast_isomorphism. am.
Qed.
Lemma all_ordinal_equipotent : forall x, exists o, is_ordinal o & are_equipotent x o.
Proof.
ir. cp (all_wo x). nin H.
apply wo_iso_ordinal in H. nin H. ee.
exists x1;ee. am. nin H0.
ap are_equipotent_sym;exists x2. am.
Qed.
Lemma bijective_enum : forall a d f, is_ordinal d -> Application.bijective d a f ->
enumerator f a.
Proof.
ir. uhg;ee. ir.
assert (inc o d).
rw ordinal_inc_not_sub;au. uhg;ir.
nin H2. apply Z_all in H2;ee.
cp H2. apply H0 in H5.
nin H5;ee;subst.
ap H4. ap Im_inc;au.
ap Z_inc. ap H0. am.
uhg;ir. Im_nin H4.
assert (inc x d). uh H;ee;eapply H;am.
apply H0 in H5;au.
subst. eapply H1;am.
Qed.
End Enumerator.
Module Ordinal_WO.
Export Ordinal. Import Function. Export Map.
Import Enumerator.
Lemma initial_iso_image : forall r a r' b h (Ht : is_total_order r a) (Ho : is_order r' b),
is_isomorphism r a r' b h ->
forall i, is_initial_segment r a i -> is_initial_segment r' b (Im (ev h) i).
Proof.
ir. uhg;ee. uhg;ir. apply Im_ex in H1;nin H1. ee.
subst. uh H;ee;uh H;ee. eapply trans_of_map. ap H. ap H0;am.
ir. apply Im_ex in H2;nin H2;ee;subst.
apply H in H1. nin H1;ee;subst.
ap Im_show_inc. exists x1. ee.
apply H0 with x0. am. am.
eapply total_injective_leq_back. am. am. am. am.
am. ap H0;am. am. tv.
Qed.
Definition oType r a := lLeast r a.
Lemma oType_ordinal : forall r a, is_ordinal (oType r a).
Proof.
ir. uf oType. ap Sow.sow_ordinal.
Qed.
Lemma oType_wo_pr : forall r a, is_well_order r a -> are_rel_isomorphic sub (oType r a) r a.
Proof.
ir.
uf oType. econstructor. ap enumLeast_isomorphism. am.
Qed.
Lemma oType_wo_pr_sym : forall r a, is_well_order r a -> are_rel_isomorphic r a sub (oType r a).
Proof.
ir. ap are_rel_iso_sym. ap ordinal_sub_total.
ap oType_ordinal. am.
ap oType_wo_pr;am.
Qed.
Lemma oType_eq_iso : forall r a r' a', is_well_order r a -> is_well_order r' a' ->
oType r a = oType r' a' -> are_rel_isomorphic r a r' a'.
Proof.
ir. apply are_rel_iso_trans with sub (oType r a).
ap are_rel_iso_sym. ap ordinal_sub_total. ap oType_ordinal. am.
ap oType_wo_pr. am.
rw H1. ap oType_wo_pr. am.
Qed.
Lemma iso_oType_eq : forall r a r' a', is_well_order r a -> is_well_order r' a' ->
are_rel_isomorphic r a r' a' -> oType r a = oType r' a'.
Proof.
ir. ap ordinal_isomorphic_unicity.
ap oType_ordinal. ap oType_ordinal.
apply are_rel_iso_trans with r a. ap oType_wo_pr. am.
apply are_rel_iso_trans with r' a'. am.
ap oType_wo_pr_sym. am.
Qed.
Lemma oType_equipotent : forall r a, is_well_order r a -> are_equipotent a (oType r a).
Proof.
ir. apply oType_wo_pr_sym in H.
nin H. exists x. am.
Qed.
Lemma oType_eq : forall ra a, is_well_order ra a -> forall o, is_ordinal o ->
are_rel_isomorphic ra a sub o -> o = oType ra a.
Proof.
ir. eapply ordinal_isomorphic_unicity. am. ap oType_ordinal.
eapply are_rel_iso_trans. ap are_rel_iso_sym. Focus 3. am.
ap well_order_total_order. am.
ap sub_is_order.
ap oType_wo_pr_sym. am.
Qed.
Definition oIsomorphism r a := L (oType r a) (enumLeast r a).
Lemma oIso_pr : forall r a, is_well_order r a -> is_isomorphism sub (oType r a) r a (oIsomorphism r a).
Proof.
ap enumLeast_isomorphism.
Qed.
Lemma oIso_inverse_pr : forall r a, is_well_order r a -> is_isomorphism r a sub (oType r a) (inverse (oIsomorphism r a)).
Proof.
ir. ap isomorphism_inverse.
uhg;ee. ap sub_is_order. ap well_order_total.
ap ordinal_sub_wo. ap oType_ordinal.
am.
ap oIso_pr. am.
Qed.
End Ordinal_WO.
Module Cardinal.
Export Ordinal_WO. Export Function.
Import Enumerator.
Definition card x := Sow.sow (are_equipotent x).
Lemma card_uf : forall x, card x = Sow.sow (are_equipotent x).
Proof.
ir;reflexivity.
Qed.
Lemma card_ordinal : forall x, is_ordinal (card x).
Proof.
ir;uf card;ap Sow.sow_ordinal.
Qed.
Lemma card_equipotent : forall x, are_equipotent x (card x).
Proof.
ir. uf card. ap Sow.sow_property.
ap all_ordinal_equipotent.
Qed.
Lemma card_smallest : forall x y, is_ordinal y -> are_equipotent x y -> sub (card x) y.
Proof.
ir. uf card. ap Sow.sow_smallest. am. am.
Qed.
Lemma card_invariant : forall x y, are_equipotent x y -> card x = card y.
Proof.
ir.
ap extensionality; uf card; ap Sow.sow_smallest.
ap Sow.sow_ordinal.
wr card_uf.
apply are_equipotent_trans with y. am. ap card_equipotent.
ap Sow.sow_ordinal.
wr card_uf.
apply are_equipotent_trans with x. ap are_equipotent_sym. am.
ap card_equipotent.
Qed.
Lemma card_eq_iso : forall x y, card x = card y -> are_equipotent x y.
Proof.
ir. apply are_equipotent_trans with (card x).
ap card_equipotent. rw H;ap are_equipotent_sym;
ap card_equipotent.
Qed.
Lemma card_iso_rw : forall x y, are_equipotent x y = (card x = card y).
Proof.
ir;ap iff_eq. ap card_invariant. ap card_eq_iso.
Qed.
Lemma card_sub_oType : forall r a, is_well_order r a -> sub (card a) (oType r a).
Proof.
ir. ap card_smallest. ap oType_ordinal.
ap oType_equipotent. am.
Qed.
Definition is_cardinal c := A (is_ordinal c)
(forall b, inc b c -> ~ are_equipotent b c).
Lemma cardinal_equipotent_sub : forall c, is_cardinal c = (A (is_ordinal c)
(forall b, is_ordinal b -> are_equipotent b c -> sub c b)).
Proof.
ir;ap iff_eq;ir;ee.
am.
ir. rw ordinal_sub_not_inc. uhg;ir.
eapply H. am. am.
am. am.
uhg;ee. am.
ir. uhg;ir.
cp H1. rwi ordinal_inc_not_sub H3.
ap H3. ap H0.
apply ordinal_in_ordinal with c;am.
am.
apply ordinal_in_ordinal with c;am.
am.
Qed.
Lemma finite_ordinal_cardinal : forall o, finite_ordinal o -> is_cardinal o.
Proof.
ir. uhg;ee. am.
ir.
uhg;ir.
apply are_equipotent_sym in H1.
apply finite_ordinal_equipotent_eq in H1.
subst. eapply H;am.
am.
apply ordinal_in_ordinal with o;am.
Qed.
Lemma omega_cardinal : is_cardinal nNum.
Proof.
uhg;ee. ap omega_ordinal.
ir.
uhg;ir.
apply finite_ordinal_equipotent_eq in H0. subst.
apply ordinal_not_inc_self with nNum. ap omega_ordinal.
am.
ap nNum_finite_ordinals. am.
ap omega_ordinal.
Qed.
Lemma card_sub_iso_sub : forall x y, sub (card x) (card y) -> iso_sub x y.
Proof.
ir.
assert (are_equipotent x (card x)). ap card_equipotent.
cp (card_equipotent y).
apply are_equipotent_sym in H1.
nin H0;nin H1.
assert (Application.injective x y (fun a => ev x1 (ev x0 a))).
uhg;ee. uhg;ir.
eapply trans_of_map. am. eapply trans_of_map. uhg;ee;try am.
uh H0;ee;ap H0. eapply sub_trans;am.
am.
uhg;ir. apply H1 in H4;au. apply H0 in H4;au.
ap H. eapply trans_of_map;am.
ap H. eapply trans_of_map;am.
rw iso_sub_rw. exists (create x (fun a : E => ev x1 (ev x0 a))).
ap map_of_injective. am.
Qed.
Lemma iso_sub_card_sub : forall x y, iso_sub x y -> sub (card x) (card y).
Proof.
ir. destruct (ordinal_sub_sub) with (card x) (card y);try am.
ap card_ordinal. ap card_ordinal.
apply card_sub_iso_sub in H0.
assert (card x = card y). ap card_invariant.
ap cantor_bernstein. am. am.
rw H1. ap sub_refl.
Qed.
Lemma sub_card_sub : forall x y, sub x y -> sub (card x) (card y).
Proof.
ir. ap iso_sub_card_sub. ap sub_iso_sub. am.
Qed.
Lemma card_sub_rw : forall x y, (sub (card x) (card y)) = (iso_sub x y).
Proof.
ir;ap iff_eq. ap card_sub_iso_sub. ap iso_sub_card_sub.
Qed.
Lemma card_is_cardinal : forall x, is_cardinal (card x).
Proof.
ir. rw cardinal_equipotent_sub. ee.
ap card_ordinal.
ir.
ap card_smallest. am. apply are_equipotent_trans with (card x).
ap card_equipotent. ap are_equipotent_sym. am.
Qed.
Lemma card_of_cardinal : forall c, is_cardinal c -> card c = c.
Proof.
ir;ap extensionality.
ap card_smallest.
am. ap are_equipotent_refl.
rwi cardinal_equipotent_sub H. ee.
ap H0. ap card_ordinal. ap are_equipotent_sym.
ap card_equipotent.
Qed.
Lemma nNum_card : forall x, inc x nNum -> card x = x.
Proof.
ir. ap card_of_cardinal. ap finite_ordinal_cardinal.
ap nNum_finite_ordinals. am.
Qed.
Lemma card_of_card : forall x, card (card x) = card x.
Proof.
ir. ap card_of_cardinal. ap card_is_cardinal.
Qed.
Lemma cardinal_eq_card : forall x c, is_cardinal c -> are_equipotent x c ->
c = card x.
Proof.
ir. wr (card_of_cardinal H). ap card_invariant. ap are_equipotent_sym;am.
Qed.
Lemma cardinal_equipotent_eq : forall c, is_cardinal c -> forall c', is_cardinal c' ->
are_equipotent c c' -> c=c'.
Proof.
ir. etransitivity. ap cardinal_eq_card. am. ap are_equipotent_sym.
am. ap card_of_cardinal. am.
Qed.
Lemma card_nNum : forall n, inc n nNum -> card n = n.
Proof.
ir. ap card_of_cardinal.
ap finite_ordinal_cardinal. ap nNum_finite_ordinals. am.
Qed.
Lemma card_ex_gt : forall a, is_cardinal a ->
exists b, is_cardinal b & inc a b.
Proof.
ir. exists (card (powerset a)).
ee. ap card_is_cardinal.
assert (Hs : iso_sub_strict a (powerset a)).
uhg;ee. rw iso_sub_rw.
exists (L a (fun x => singleton x)).
ap map_of_injective. uhg;ee;uhg;ir.
ap powerset_inc. uhg;ir.
apply singleton_eq in H1;subst;au.
ap singleton_eq. wr H2. ap singleton_inc.
uhg;ir. eapply Application.cantor_strong.
nin H0. exists (ev x).
ap surjective_of_map. rwi bijective_rw H0. am.
assert (iso_sub_strict a (card (powerset a))).
uhg;ee.
apply iso_sub_trans with (powerset a).
am.
exists (card (powerset a)). ee.
ap card_equipotent. ap sub_refl.
uhg;ir. ap Hs.
apply are_equipotent_trans with (card (powerset a)).
am. ap are_equipotent_sym. ap card_equipotent.
wr ordinal_inc_lt_of.
uhg;ee.
apply sub_trans with (card a).
rw card_of_cardinal. ap sub_refl. am.
ap iso_sub_card_sub.
am.
uhg;ir.
ap H0.
wr H1.
ap are_equipotent_refl.
am.
ap card_ordinal.
Qed.
End Cardinal.
Module WO_rec.
Import Enumerator.
Export Cardinal.
Section VarSec.
Variables (r : E2P) (a : E).
Hypothesis (Hwo : is_well_order r a).
Variable (g : E1).
Notation iso := (oIsomorphism r a). (*iso : from oType to a*)
Definition wo_rec x := (ordinal_rec (fun h =>
let h' := compose h (inverse iso) in g h') (ev (inverse iso) x)).
Lemma wo_rec_pr : forall x, inc x a -> wo_rec x = g (L (Z a (fun y => lt_of r y x)) wo_rec).
Proof.
ir.
cp (oIso_pr Hwo).
cp (oIso_inverse_pr Hwo).
uf wo_rec. rw ordinal_rec_pr.
ap uneq.
assert (domain
(compose
(L (ev (inverse iso) x)
(ordinal_rec (fun h : E => g (compose h (inverse iso)))))
(inverse iso)) =
domain
(L (Z a (fun y : E => lt_of r y x))
(fun x0 : E =>
ordinal_rec (fun h : E => g (compose h (inverse iso)))
(ev (inverse iso) x0)))).
rw create_domain. rw compose_domain.
rw create_domain.
ap extensionality;uhg;ir.
apply Z_all in H2;ee.
assert (domain (inverse iso) = a). assert (is_map a (oType r a) (inverse iso)).
am. am.
rwi H4 H2.
assert (Application.axioms a (oType r a) (ev (inverse iso))). ap trans_of_map.
am.
cp (H5 x H). cp (H5 a0 H2).
clear H5. assert (is_ordinal (oType r a)). ap oType_ordinal.
cp (ordinal_in_ordinal H5).
wri ordinal_inc_lt_of H3;au.
nin H3.
ap Z_inc;au.
uhg;ee.
assert (is_total_order r a). uhg;ee. am. ap well_order_total;am.
rw (leq_not_lt H10);au.
uhg;ir. nin H11.
ap H9. ap extensionality;au.
ap H1;au.
uhg;ir. ap H9. ap uneq. am.
apply Z_all in H2;ee.
nin H3.
ap Z_inc. eapply eq_ind. am. symmetry.
assert (is_map a (oType r a) (inverse iso));am.
assert (Application.axioms a (oType r a) (ev (inverse iso))). ap trans_of_map.
am.
cp (H5 x H). cp (H5 a0 H2).
clear H5. assert (is_ordinal (oType r a)). ap oType_ordinal.
cp (ordinal_in_ordinal H5).
wr ordinal_inc_lt_of;au. uhg;ee.
ap H1;au. uhg;ir.
ap H4. ap H1;au.
ap function_extensionality.
ap compose_axioms. ap create_axioms.
am.
ir.
rwi create_domain H2. rwi H2 H3.
rw create_ev;au.
rw compose_ev. rw create_ev. tv.
Focus 2. rw H2. am.
clear H2;apply Z_all in H3;ee.
assert (Application.axioms a (oType r a) (ev (inverse iso))). ap trans_of_map.
am.
cp (H4 x H). cp (H4 x0 H2).
clear H4. assert (is_ordinal (oType r a)). ap oType_ordinal.
cp (ordinal_in_ordinal H4).
wr ordinal_inc_lt_of;au. uhg;ee.
ap H1;au. uhg;ir.
ap H3. ap H1;au.
apply ordinal_in_ordinal with (oType r a).
ap oType_ordinal.
eapply trans_of_map. am. am.
Qed.
End VarSec.
Lemma wo_iso_wo : forall ra a, is_well_order ra a -> forall rb b, is_order rb b ->
are_rel_isomorphic ra a rb b -> is_well_order rb b.
Proof.
ir.
nin H1.
uhg;ee. am.
ir.
assert (is_total_order ra a). uhg;ee. am.
ap well_order_total. am.
cp (isomorphism_inverse H4 H0 H1).
clear H4.
pose (z := Im (ev (inverse x)) b0). assert (nonempty z).
nin H3. econstructor;ap Im_inc;am.
apply H in H4.
nin H4.
exists (ev x x0).
uh H4;ee. Im_nin H6. subst.
uhg;ee. uhg;ee.
eapply trans_of_map;try am.
ir. assert (x0 = ev x (ev (inverse x) x0)).
symmetry. eapply bijective_inverse_ev_r. am. au.
rw H8. ap H1. am. eapply trans_of_map;try am.
au.
ap H4. ap Im_inc. am.
erewrite bijective_inverse_ev_r. am. am. au.
uhg;ir.
Im_nin H6;subst.
eapply trans_of_map;try am. au.
Qed.
(*nb : rb,b must be order otherwise rb = always true allows any bijection*)
Lemma wo_iso_ev : forall ra a, is_well_order ra a -> forall rb b, is_well_order rb b ->
forall f, is_isomorphism ra a rb b f ->
forall x, inc x a -> ev f x = chooseInf b rb (complement b (Im (ev f) (Z a (fun y => lt_of ra y x)))).
Proof.
ir.
assert (sub (complement b (Im (ev f) (Z a (fun y : E => lt_of ra y x)))) b).
ap Z_sub.
assert (nonempty (complement b (Im (ev f) (Z a (fun y : E => lt_of ra y x))))).
ap excluded_middle;uhg;ir.
assert (inc (ev f x) b). eapply trans_of_map;am.
assert (inc (ev f x) (Im (ev f) (Z a (fun y : E => lt_of ra y x)))).
ap excluded_middle;uhg;ir.
ap H4. exists (ev f x);ap Z_inc;am.
Im_nin H6.
apply Z_all in H6;ee.
ap H8.
ap H1;au.
apply H0 in H4;try ap Z_sub.
assert (is_min b rb (complement b (Im (ev f) (Z a (fun y : E => lt_of ra y x))))
(chooseInf b rb (complement b (Im (ev f) (Z a (fun y : E => lt_of ra y x)))))).
ap chooseInf_min. am. am.
eapply min_unicity. Focus 3. am.
am. clear H4;clear H5. clear H3. uhg;ee. uhg;ee.
eapply trans_of_map;am.
ir. apply Z_all in H3;ee.
cp H3. apply H1 in H5. nin H5;ee;subst.
ap H1;au.
erewrite leq_not_lt.
Focus 2. uhg;ee. am. ap well_order_total. am.
uhg;ir. ap H4. ap Im_inc. ap Z_inc.
am. am.
am. am.
ap Z_inc. eapply trans_of_map;am.
uhg;ir.
Im_nin H3.
apply Z_all in H3. ee.
ap H5. ap H1;au.
Qed.
Lemma wo_iso_ev_pr : forall ra a, is_well_order ra a -> forall rb b, is_well_order rb b ->
forall f, is_isomorphism ra a rb b f ->
forall x, inc x a -> is_min b rb (complement b (Im (ev f) (Z a (fun y => lt_of ra y x)))) (ev f x).
Proof.
ir.
rw (wo_iso_ev H H0 H1 H2).
ap chooseInf_min. am.
ap H0. ap Z_sub.
exists (ev f x).
ap Z_inc. eapply trans_of_map;am.
uhg;ir. Im_nin H3. apply Z_all in H3;ee.
ap H5. ap H1;au.
Qed.
Lemma wo_only_isomorphism : forall ra a, is_well_order ra a -> forall rb b, is_well_order rb b ->
unicity (is_isomorphism ra a rb b).
Proof.
ir.
uhg. ir.
ap function_extensionality;try am.
transitivity a. cp (and_P H1). am.
symmetry. cp (and_P H2). am.
assert (domain y = a). cp (and_P H1). am.
rw H3. clear H3.
ap (wo_ind H).
ir.
rw (wo_iso_ev H H0 H1);au. rw (wo_iso_ev H H0 H2);au.
ap uneq. ap uneq. ap Im_uneq. ir.
apply Z_all in H5;ee. au.
Qed.
Lemma wo_iso_initial : forall ra a, is_well_order ra a ->
forall rb b, is_well_order rb b -> forall a', is_initial_segment ra a a' ->
forall b', is_initial_segment rb b b' -> forall f, is_isomorphism ra a rb b f ->
forall f', is_isomorphism ra a' rb b' f' ->
sub f' f.
Proof.
ir.
nin H1. nin H2.
eapply map_sub. am. ap H1. am.
cp (sub_wellorder H H1).
ap (wo_ind H7). ir.
assert (forall y, inc y a -> lt_of ra y x -> inc y a').
ir. eapply H5. am. am. am.
assert (forall y, inc y a -> lt_of ra y x -> ev f y = ev f' y).
ir;au.
cp (wo_iso_ev_pr H H0 H3 (H1 x H8)).
cp (wo_iso_ev_pr H7 (sub_wellorder H0 H2) H4 H8).
eapply min_unicity. Focus 2. am. am.
uhg;ee. uhg;ee.
ap H2. am.
ir. apply by_cases with (inc x0 b');ir.
ap H13. ap Z_inc. am.
uhg;ir. Im_nin H16. subst.
apply Z_all in H14;ee.
apply Z_all in H16;ee.
ap H17. wr H9;au.
ap Im_inc. ap Z_inc. au. am.
assert (forall y, inc y b' -> lt_of rb y x0).
ir. apply Z_all in H14;ee.
erewrite lt_not_leq. uhg;ir. ap H15. eau.
uhg;ee. am. ap well_order_total;am. au. am.
destruct H16 with (ev f' x). am. am.
ap Z_inc. ap H2;am. uhg;ir.
Im_nin H14. apply Z_all in H14;ee.
rwi H11 H15;try am.
assert (x = x0).
ap H4. am.
eau. am. subst.
ap H16. tv.
Qed.
Lemma isomorphism_iso_initial_to_initial : forall ra a, is_total_order ra a ->
forall rb b, is_order rb b -> forall f, is_isomorphism ra a rb b f ->
forall x, is_initial_segment ra a x -> is_initial_segment rb b (Im (ev f) x).
Proof.
ir. uhg;ee. uhg;ir. Im_nin H3.
subst. eapply trans_of_map;try am. ap H2. am.
ir. Im_nin H4;subst.
cp H3. apply H1 in H6. nin H6;ee;subst.
assert (ra x2 x1).
cp (isomorphism_inverse H H0 H1).
assert (bijective a b f). am. apply bijective_inverse_of in H8.
uh H8;ee. clear H8;clear H9.
uh H10;ee.
assert (inc x1 a). ap H2. am.
wr (H8 x1 H10).
wr (H8 x2 H6).
ap H7. am. eapply trans_of_map;try am.
am.
ap Im_inc. apply H2 with x1. am. am. am.
Qed.
End WO_rec.
Module Finite.
Export Function. Export Map.
Export Ordinal. Export Cardinal.
Import WO_rec.
Inductive is_finite : EP :=
| finite_emptyset : is_finite emptyset
| finite_tack_on : forall x, is_finite x -> forall y, is_finite (tack_on x y)
.
Lemma nNum_finite : forall n, inc n nNum -> is_finite n.
Proof.
ap nNum_rect;ir.
ap finite_emptyset.
ap finite_tack_on. am.
Qed.
Lemma finite_nNum_equipotent : forall x, is_finite x -> exists n, inc n nNum & are_equipotent x n.
Proof.
ir;nin H.
exists emptyset;ee. ap emptyset_N. ap are_equipotent_refl.
destruct IHis_finite as [n H0]. ee.
apply by_cases with (inc y x);ir.
exists n. ee. am.
ap are_equipotent_sym. eapply eq_ind. ap are_equipotent_sym;am.
ap extensionality_rw;ir;rw tack_on_inc;ap iff_eq;ir;au.
nin H3;subst;au.
exists (oS n);ee. ap oS_nNum. am.
uf oS . wr tack_on_equipotent. am.
am. ap ordinal_not_inc_self;ap nNum_ordinal;am.
Qed.
Lemma finite_card_nNum : forall x, is_finite x -> inc (card x) nNum.
Proof.
ir. apply finite_nNum_equipotent in H.
nin H;ee.
assert (card x = x0).
symmetry. ap cardinal_eq_card.
wr nNum_card. ap card_is_cardinal. am.
am.
rw H1. am.
Qed.
Lemma finite_invariant : forall x, is_finite x -> forall y, are_equipotent x y -> is_finite y.
Proof.
intros x Hx. nin Hx;ir.
eapply eq_ind. ap finite_emptyset.
symmetry;ap empty_emptyset;ir.
nin H. apply H in H0. nin H0;ee;eapply emptyset_empty;am.