-
Notifications
You must be signed in to change notification settings - Fork 2
/
Cardinal.v
1562 lines (1403 loc) · 49.9 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
From Ordinal Require Import sflib Basics.
From Ordinal Require Import ClassicalOrdinal WfRel WellOrdering.
From Ordinal Require Export Ordinal ToSet.
Require Import Coq.Classes.RelationClasses.
Require Import ClassicalChoice FunctionalExtensionality PropExtensionality.
Require Import Program.
Set Implicit Arguments.
Set Primitive Projections.
Module Cardinal.
Section CARDINALITY.
Variant _cardinal_le (A B: Type): Prop :=
| _cardinal_le_intro
(f: A -> B)
(INJ: forall a0 a1 (EQ: f a0 = f a1), a0 = a1)
.
Let _cardinal_eq (A B: Type): Prop := _cardinal_le A B /\ _cardinal_le B A.
Let _cardinal_lt (A B: Type): Prop := _cardinal_le A B /\ ~ _cardinal_le B A.
Let _cardinal_total_le: forall (A B: Type), _cardinal_le A B \/ _cardinal_le B A.
Proof.
i. hexploit (set_comparable A B). i. des.
- left. econs; eauto.
- right. econs; eauto.
Qed.
Lemma _cardinal_le_power A B (LE: _cardinal_le A B):
_cardinal_le (A -> Prop) (B -> Prop).
Proof.
inv LE.
eapply _cardinal_le_intro with (f := fun s y => exists x, f x = y /\ s x).
i. extensionality x. pose proof (equal_f EQ (f x)) as EQ0.
apply propositional_extensionality.
transitivity (exists x0, f x0 = f x /\ a0 x0).
{ split; i; eauto.
des. apply INJ in H. subst. auto. }
{ rewrite EQ0. split; i; eauto.
des. apply INJ in H. subst. auto. }
Qed.
Section CARDINAL.
Variable A: Type.
Definition of_cardinal (c: Ord.t): Prop :=
ClassicOrd.is_meet (fun o =>
exists (R: A -> A -> Prop) (WF: well_founded R),
(forall a0 a1, R a0 a1 \/ a0 = a1 \/ R a1 a0) /\
Ord.eq (Ord.from_wf_set WF) o) c.
Lemma of_cardinal_exists: exists c, of_cardinal c.
Proof.
eapply ClassicOrd.meet_exists.
hexploit (@well_ordering_theorem A); eauto. i. des.
exists (Ord.from_wf_set H), R, H. splits; auto. reflexivity.
Qed.
Lemma of_cardinal_unique c0 c1 (CARD0: of_cardinal c0) (CARD1: of_cardinal c1):
Ord.eq c0 c1.
Proof.
unfold of_cardinal, ClassicOrd.is_meet in *. des. split.
- eapply CARD4; eauto.
- eapply CARD2; eauto.
Qed.
Lemma eq_of_cardinal c0 c1 (EQ: Ord.eq c0 c1) (CARD0: of_cardinal c0):
of_cardinal c1.
Proof.
unfold of_cardinal, ClassicOrd.is_meet in *. des. split.
- exists R, WF. splits; auto. transitivity c0; auto.
- i. transitivity c0; auto. eapply EQ.
Qed.
Let X: Type :=
@sig
(@sigT (A -> Prop) (fun s => sig s -> sig s-> Prop))
(fun PR =>
well_founded (projT2 PR) /\
(forall a0 a1, projT2 PR a0 a1 \/ a0 = a1 \/ projT2 PR a1 a0) /\
(forall (f: A -> sig (projT1 PR)),
exists a0 a1, f a0 = f a1 /\ a0 <> a1)).
Let Y (x: X): Ord.t :=
@Ord.from_wf_set (sig (projT1 (proj1_sig x))) _ (proj1 (proj2_sig x)).
Definition cardinal := @Ord.build X Y.
Lemma cardinal_lowerbound (R: A -> A -> Prop) (WF: well_founded R)
(TOTAL: forall a0 a1, R a0 a1 \/ a0 = a1 \/ R a1 a0):
Ord.le cardinal (Ord.from_wf_set WF).
Proof.
eapply Ord.build_supremum. i. unfold Y.
destruct a as [[P0 R0] [WF0 [TOTAL0 SMALL]]]; ss.
eapply (@Ord.le_lt_lt (Ord.from_wf_set WF0)).
{ eapply Ord.same_wf_set_le. }
destruct (ClassicOrd.total (Ord.from_wf_set WF) (Ord.from_wf_set WF0)); auto.
exfalso. hexploit from_wf_set_embed; eauto. intros MON. des.
hexploit (SMALL f); eauto. i. des.
destruct (TOTAL a0 a1) as [|[]]; ss.
{ eapply MON in H2. rewrite H0 in *.
eapply well_founded_irreflexive in H2; eauto. }
{ eapply MON in H2. rewrite H0 in *.
eapply well_founded_irreflexive in H2; eauto. }
Qed.
Lemma _cardinal_upperbound B (CARD: _cardinal_lt B A)
(R: B -> B -> Prop) (WF: well_founded R)
:
Ord.lt (Ord.from_wf_set WF) cardinal.
Proof.
inv CARD.
assert (CLT: ~ _cardinal_le A B).
{ ii. eapply H0. eauto. } inv H.
hexploit (from_wf_set_projected_rel_sig_eq WF _ INJ). i.
hexploit (well_founded_order_extendable (projected_rel_sig_well_founded WF f INJ)). i. des.
hexploit (from_wf_set_le H2 (projected_rel_sig_well_founded WF f INJ) H1). i.
eapply Ord.le_lt_lt.
{ etransitivity.
{ eapply H. }
{ eapply H4. }
}
assert ((fun (PR:(@sigT (A -> Prop) (fun s => sig s -> sig s-> Prop))) =>
well_founded (projT2 PR) /\
(forall a0 a1, projT2 PR a0 a1 \/ a0 = a1 \/ projT2 PR a1 a0) /\
(forall (f: A -> sig (projT1 PR)),
exists a0 a1, f a0 = f a1 /\ a0 <> a1)) (existT _ _ R1)).
{ ss. splits; auto. i. eapply NNPP. ii. eapply CLT.
hexploit (choice (fun (a: A) (b: B) => proj1_sig (f0 a) = f b)).
{ i. hexploit (proj2_sig (f0 x)). i. des. eauto. }
i. des. eapply _cardinal_le_intro with (f:=f1). i.
eapply NNPP. ii. eapply f_equal with (f:=f) in EQ.
rewrite <- H6 in EQ. rewrite <- H6 in EQ.
eapply H5; eauto. exists a0, a1. splits; auto.
destruct (f0 a0), (f0 a1); auto. ss. subst. f_equal. eapply proof_irrelevance.
}
hexploit (@Ord.build_upperbound
X Y
(@exist
(@sigT (A -> Prop) (fun s => sig s -> sig s-> Prop))
(fun PR =>
well_founded (projT2 PR) /\
(forall a0 a1, projT2 PR a0 a1 \/ a0 = a1 \/ projT2 PR a1 a0) /\
(forall (f: A -> sig (projT1 PR)),
exists a0 a1, f a0 = f a1 /\ a0 <> a1))
(@existT (A -> Prop) (fun s => sig s -> sig s-> Prop) _ R1)
H5)).
ss. unfold Y. ss. i.
eapply Ord.le_lt_lt; [|eapply H6].
eapply Ord.same_wf_set_le.
Qed.
Lemma _cardinal_supremum c
(UPPER: forall (B: Type) (CARD: _cardinal_lt B A)
(R: B -> B -> Prop) (WF: well_founded R),
Ord.lt (Ord.from_wf_set WF) c)
:
Ord.le cardinal c.
Proof.
eapply Ord.build_supremum. i.
destruct a as [[P0 R0] [WF0 [TOTAL SMALL]]]; ss. unfold Y. ss.
eapply (@Ord.le_lt_lt (Ord.from_wf_set WF0)).
{ eapply Ord.same_wf_set_le. }
eapply UPPER.
assert (NLE: ~ _cardinal_le A (sig P0)).
{ ii. inv H. hexploit (SMALL f); eauto. i. des.
eapply INJ in H. ss. }
destruct (_cardinal_total_le A (sig P0)); ss.
Qed.
Lemma cardinal_of_cardinal: of_cardinal cardinal.
Proof.
split.
- hexploit of_cardinal_exists. i. des.
unfold of_cardinal, ClassicOrd.is_meet in H. des.
exists R, WF. splits; auto. split.
2: { eapply cardinal_lowerbound; auto. }
hexploit (ToSet.to_total_exists cardinal); eauto. i. des.
hexploit (_cardinal_total_le A A0). i.
destruct (classic (_cardinal_le A A0)).
{ transitivity (Ord.from_wf_set WF0).
2: { eapply H2. }
transitivity c.
{ eapply H1. }
inv H5.
hexploit (projected_rel_rev_well_founded WF0 f); auto. i.
hexploit (H0 (Ord.from_wf_set H5)).
{ eexists _, H5. splits; auto.
- i. destruct (H3 (f a0) (f a1)) as [|[]]; auto.
- reflexivity. }
i. transitivity (Ord.from_wf_set H5); auto.
eapply from_wf_set_inj; eauto.
}
{ assert (CLT: _cardinal_lt A0 A).
{ des; ss. }
hexploit (_cardinal_upperbound CLT WF0). i.
exfalso. eapply Ord.lt_not_le.
{ eapply H6. }
{ eapply H2. }
}
- i. des. eapply Ord.build_supremum. i. unfold Y.
destruct a as [[P0 R0] [WF0 [TOTAL SMALL]]]; ss.
eapply (@Ord.le_lt_lt (Ord.from_wf_set WF0)).
{ eapply Ord.same_wf_set_le. }
eapply Ord.lt_eq_lt.
{ symmetry. eapply IN0. }
destruct (ClassicOrd.total (Ord.from_wf_set WF) (Ord.from_wf_set WF0)); auto.
exfalso. hexploit from_wf_set_embed; eauto. intros MON. des.
hexploit (SMALL f); eauto. i. des.
destruct (IN a0 a1) as [|[]]; ss.
{ eapply MON in H2. rewrite H0 in *.
eapply well_founded_irreflexive in H2; eauto. }
{ eapply MON in H2. rewrite H0 in *.
eapply well_founded_irreflexive in H2; eauto. }
Qed.
End CARDINAL.
Lemma _cardinal_le_iff A B:
_cardinal_le A B <-> Ord.le (cardinal A) (cardinal B).
Proof.
split. i.
- hexploit (cardinal_of_cardinal B). i. destruct H0. des.
transitivity (Ord.from_wf_set WF); auto.
2: { eapply H2. }
inv H. transitivity (Ord.from_wf_set (projected_rel_rev_well_founded WF f INJ)).
{ eapply cardinal_of_cardinal.
exists (projected_rel_rev R f), (projected_rel_rev_well_founded WF f INJ). splits; auto.
- i. destruct (H0 (f a0) (f a1)) as [|[]]; auto.
- reflexivity.
}
{ eapply from_wf_set_inj. instantiate (1:=f). i. apply LT. }
- hexploit (cardinal_of_cardinal B). i. destruct H. des.
i. eapply NNPP. ii. destruct (_cardinal_total_le A B); ss.
hexploit (_cardinal_upperbound).
{ split; eauto. }
instantiate (1:=WF). i. eapply Ord.lt_not_le; eauto.
transitivity (cardinal B); auto. apply H2.
Qed.
Lemma _cardinal_eq_iff A B:
_cardinal_eq A B <-> Ord.eq (cardinal A) (cardinal B).
Proof.
split. i.
- split.
+ apply _cardinal_le_iff; auto. apply H.
+ apply _cardinal_le_iff; auto. apply H.
- split.
+ apply _cardinal_le_iff; auto. apply H.
+ apply _cardinal_le_iff; auto. apply H.
Qed.
Lemma _cardinal_lt_iff A B:
_cardinal_lt A B <-> Ord.lt (cardinal A) (cardinal B).
Proof.
split; i.
- inv H. apply _cardinal_le_iff in H0.
eapply ClassicOrd.le_eq_or_lt in H0. des; auto.
exfalso. eapply H1. eapply _cardinal_eq_iff; eauto.
- split.
+ apply _cardinal_le_iff. eapply Ord.lt_le; eauto.
+ ii. apply _cardinal_le_iff in H0.
eapply Ord.lt_not_le; eauto.
Qed.
Lemma cardinal_size_le A B (R: B -> B -> Prop) (WF: well_founded R)
(TOTAL: forall b0 b1, R b0 b1 \/ b0 = b1 \/ R b1 b0)
(LE: Ord.le (cardinal A) (Ord.from_wf_set WF)):
Ord.le (cardinal A) (cardinal B).
Proof.
hexploit (cardinal_of_cardinal A); auto. i. inv H. des.
hexploit (@from_wf_set_embed _ _ _ _ WF0 WF); auto.
{ transitivity (cardinal A); auto. apply H2. }
i. des. apply _cardinal_le_iff.
eapply _cardinal_le_intro with (f:=f). i.
destruct (H0 a0 a1) as [|[]]; auto.
- eapply H in H3. rewrite EQ in *.
exfalso. eapply (well_founded_irreflexive WF); eauto.
- eapply H in H3. rewrite EQ in *.
exfalso. eapply (well_founded_irreflexive WF); eauto.
Qed.
Lemma cardinal_size_eq A B (R: B -> B -> Prop) (WF: well_founded R)
(TOTAL: forall b0 b1, R b0 b1 \/ b0 = b1 \/ R b1 b0)
(EQ: Ord.eq (cardinal A) (Ord.from_wf_set WF)):
Ord.eq (cardinal A) (cardinal B).
Proof.
split; i.
- eapply cardinal_size_le; eauto. eapply EQ.
- transitivity (Ord.from_wf_set WF).
+ eapply (cardinal_of_cardinal B). esplits; eauto. reflexivity.
+ eapply EQ.
Qed.
Lemma le_cardinal_le A B (RA: A -> A -> Prop) (RB: B -> B -> Prop) (WFA: well_founded RA) (WFB: well_founded RB)
(TOTAL: forall a0 a1, RA a0 a1 \/ a0 = a1 \/ RA a1 a0)
(LE: Ord.le (Ord.from_wf_set WFA) (Ord.from_wf_set WFB))
:
Ord.le (cardinal A) (cardinal B).
Proof.
hexploit (well_founded_order_extendable WFB); eauto. i. des.
hexploit (@from_wf_set_embed _ _ _ _ WFA H); eauto.
{ transitivity (Ord.from_wf_set WFB); auto.
eapply from_wf_set_le; eauto. }
i. des. apply _cardinal_le_iff.
eapply _cardinal_le_intro with (f:=f). i.
destruct (TOTAL a0 a1) as [|[]]; auto.
{ eapply H2 in H3. rewrite EQ in *.
exfalso. eapply (well_founded_irreflexive H); eauto. }
{ eapply H2 in H3. rewrite EQ in *.
exfalso. eapply (well_founded_irreflexive H); eauto. }
Qed.
Lemma to_total_le o0 o1 (LE: Ord.le o0 o1):
Ord.le (cardinal (ToSet.to_total_set o0)) (cardinal (ToSet.to_total_set o1)).
Proof.
eapply le_cardinal_le.
{ eapply ToSet.to_total_total. }
instantiate (1:=ToSet.to_total_well_founded o1).
instantiate (1:=ToSet.to_total_well_founded o0).
transitivity o0.
{ eapply ToSet.to_total_eq. }
transitivity o1; auto.
{ eapply ToSet.to_total_eq. }
Qed.
Lemma to_total_cardinal_le o:
Ord.le (cardinal (ToSet.to_total_set o)) o.
Proof.
transitivity (Ord.from_wf_set (ToSet.to_total_well_founded o)).
{ eapply cardinal_of_cardinal.
exists (ToSet.to_total_rel o), (ToSet.to_total_well_founded o). split; auto.
- eapply ToSet.to_total_total.
- reflexivity.
}
{ eapply ToSet.to_total_eq. }
Qed.
Lemma cardinal_to_total_bij1 A:
Ord.eq (cardinal A) (cardinal (ToSet.to_total_set (cardinal A))).
Proof.
eapply cardinal_size_eq.
{ eapply ToSet.to_total_total. }
eapply ToSet.to_total_eq.
Qed.
Lemma cardinal_to_total_bij2 A c (CARDINAL: of_cardinal A c):
Ord.eq c (cardinal (ToSet.to_total_set c)).
Proof.
hexploit of_cardinal_unique.
{ eapply CARDINAL. }
{ eapply cardinal_of_cardinal. }
i. transitivity (cardinal A); auto.
transitivity (cardinal (ToSet.to_total_set (cardinal A))).
{ eapply cardinal_to_total_bij1. }
split.
{ eapply to_total_le. apply H. }
{ eapply to_total_le. apply H. }
Qed.
Lemma from_wf_set_to_total A (R: A -> A -> Prop) (WF: well_founded R):
Ord.le (cardinal (ToSet.to_total_set (Ord.from_wf_set WF))) (cardinal A).
Proof.
hexploit (well_founded_order_extendable WF); eauto. i. des.
assert (Ord.le (Ord.from_wf_set (ToSet.to_total_well_founded (Ord.from_wf_set WF))) (Ord.from_wf_set H)).
{ transitivity (Ord.from_wf_set WF).
{ eapply ToSet.to_total_eq. }
{ eapply from_wf_set_le; auto. }
}
dup H2. eapply from_wf_set_embed in H2; auto. des.
hexploit (@from_wf_set_embed _ _ _ _ (ToSet.to_total_well_founded (Ord.from_wf_set WF)) H); auto.
i. des. apply _cardinal_le_iff.
eapply _cardinal_le_intro with (f:=f0).
i. destruct (ToSet.to_total_total a0 a1) as [|[]]; auto.
{ eapply H4 in H5. rewrite EQ in *. exfalso.
eapply (well_founded_irreflexive H); eauto. }
{ eapply H4 in H5. rewrite EQ in *. exfalso.
eapply (well_founded_irreflexive H); eauto. }
Qed.
Lemma total_from_wf_inj A (R: A -> A -> Prop) (WF: well_founded R)
(TOTAL: forall a0 a1, R a0 a1 \/ a0 = a1 \/ R a1 a0)
:
forall a0 a1,
a0 = a1 <-> Ord.eq (Ord.from_wf WF a0) (Ord.from_wf WF a1).
Proof.
i. split.
{ i. subst. reflexivity. }
{ i. destruct (TOTAL a0 a1) as [|[]]; auto.
{ eapply (Ord.lt_from_wf WF) in H0. exfalso.
eapply Ord.lt_not_le; eauto. eapply H. }
{ eapply (Ord.lt_from_wf WF) in H0. exfalso.
eapply Ord.lt_not_le; eauto. eapply H. }
}
Qed.
Lemma same_cardinality_bijection A B
(CARDINAL: Ord.eq (cardinal A) (cardinal B))
:
exists (f: A -> B),
(forall a0 a1 (EQ: f a0 = f a1), a0 = a1) /\
(forall b, exists a, f a = b).
Proof.
hexploit (cardinal_of_cardinal A). i. inv H. des.
hexploit (cardinal_of_cardinal B). i. inv H. des.
hexploit (choice (fun a b => Ord.eq (Ord.from_wf WF a) (Ord.from_wf WF0 b))).
{ i. hexploit (@ClassicOrd.from_wf_set_complete _ _ WF0 (Ord.from_wf WF x)).
{ eapply Ord.lt_eq_lt.
{ eapply H5. }
eapply Ord.lt_eq_lt.
{ symmetry. eapply CARDINAL. }
eapply Ord.lt_eq_lt.
{ symmetry. eapply H2. }
eapply Ord.from_wf_set_upperbound.
}
i. des. eauto.
}
i. des. exists f. splits; auto.
{ i. eapply (total_from_wf_inj WF); eauto.
etransitivity.
{ eapply H. }
etransitivity.
2: { symmetry. eapply H. }
rewrite EQ. reflexivity.
}
{ i. hexploit (@ClassicOrd.from_wf_set_complete _ _ WF (Ord.from_wf WF0 b)).
{ eapply Ord.lt_eq_lt.
{ eapply H2. }
eapply Ord.lt_eq_lt.
{ eapply CARDINAL. }
eapply Ord.lt_eq_lt.
{ symmetry. eapply H5. }
eapply Ord.from_wf_set_upperbound.
}
i. des. exists a. eapply (total_from_wf_inj WF0); auto.
etransitivity.
{ symmetry. eapply H. }
{ symmetry. eapply H6. }
}
Qed.
Lemma sum_of_smaller o:
exists (os: ToSet.to_total_set o -> Ord.t),
Ord.eq o (Ord.build os).
Proof.
hexploit (ToSet.to_total_eq o). i.
exists (fun x => Ord.from_wf (ToSet.to_total_well_founded o) x).
eapply H.
Qed.
Lemma sum_of_smaller_same_cardinal o A (EQ: Ord.eq (cardinal A) (cardinal (ToSet.to_total_set o))):
exists (os: A -> Ord.t),
Ord.eq o (Ord.build os).
Proof.
hexploit (sum_of_smaller o). i. des.
eapply same_cardinality_bijection in EQ. des.
exists (fun a => os (f a)). etransitivity.
{ eapply H. }
split.
{ eapply Ord.build_supremum. i. hexploit (EQ0 a). i. des.
subst. eapply (Ord.build_upperbound (fun a => os (f a)) a0). }
{ eapply Ord.build_supremum. i.
eapply (Ord.build_upperbound os (f a)). }
Qed.
End CARDINALITY.
Section NEXT.
Variable A: Type.
Let X: Type := @sig (A -> A -> Prop) (@well_founded _).
Let Y (x: X): Ord.t := Ord.from_wf_set (proj2_sig x).
Definition next_cardinal := Ord.hartogs.
Lemma next_cardinal_upperbound B (R: B -> B -> Prop) (WF: well_founded R)
(CARD: Ord.le (cardinal B) (cardinal A))
: Ord.lt (Ord.from_wf_set WF) (next_cardinal A).
Proof.
eapply _cardinal_le_iff in CARD. inv CARD.
eapply (@Ord.le_lt_lt (Ord.from_wf_set (embed_projected_rel_well_founded WF f INJ))).
{ eapply from_wf_set_inj. instantiate (1:=f). i. econs; eauto. }
eapply (@Ord.build_upperbound X Y (exist _ _ (embed_projected_rel_well_founded WF f INJ))).
Qed.
Lemma next_cardinal_incr
: Ord.lt (cardinal A) (next_cardinal A).
Proof.
hexploit (cardinal_of_cardinal A). i. inv H. des.
eapply Ord.eq_lt_lt.
{ symmetry. eapply H2. }
eapply next_cardinal_upperbound.
reflexivity.
Qed.
Lemma next_cardinal_supremum B (CARD: Ord.lt (cardinal A) (cardinal B)):
Ord.le (next_cardinal A) (cardinal B).
Proof.
Local Transparent Ord.hartogs.
eapply Ord.build_supremum. i. destruct a as [R WF]. unfold Y. ss.
destruct (ClassicOrd.total (cardinal B) (Ord.from_wf_set WF)); auto.
hexploit (cardinal_of_cardinal B); eauto. i. inv H0. des.
hexploit (well_founded_order_extendable WF); eauto. i. des.
hexploit (@from_wf_set_embed _ _ _ _ WF0 H3); auto.
{ transitivity (cardinal B); auto.
{ eapply H0. }
transitivity (Ord.from_wf_set WF); auto.
eapply from_wf_set_le; auto.
}
i. des. exfalso.
eapply _cardinal_lt_iff in CARD. des.
eapply CARD0.
eapply _cardinal_le_intro with (f:=f). i.
destruct (H1 a0 a1) as [|[]]; auto.
- eapply H6 in H7. rewrite EQ in *.
exfalso. eapply (well_founded_irreflexive H3); eauto.
- eapply H6 in H7. rewrite EQ in *.
exfalso. eapply (well_founded_irreflexive H3); eauto.
Qed.
Lemma next_cardinal_of_cardinal:
of_cardinal (ToSet.to_total_set (next_cardinal A)) (next_cardinal A).
Proof.
split.
{ exists (ToSet.to_total_rel (next_cardinal A)), (ToSet.to_total_well_founded (next_cardinal A)).
splits; auto.
- eapply ToSet.to_total_total.
- symmetry. apply ToSet.to_total_eq.
}
i. des. eapply Ord.build_supremum. i. destruct a as [R0 WF0]. unfold Y. ss.
destruct (ClassicOrd.total o1 (Ord.from_wf_set WF0)); auto.
assert (LE: Ord.le (Ord.from_wf_set WF) (Ord.from_wf_set WF0)).
{ transitivity o1; auto. eapply IN0. }
eapply le_cardinal_le in LE; auto. exfalso.
eapply (next_cardinal_upperbound (ToSet.to_total_well_founded (next_cardinal A))) in LE.
eapply Ord.lt_not_le.
{ eapply LE. }
{ eapply ToSet.to_total_eq. }
Qed.
Lemma next_cardinal_le_power_set:
Ord.le (next_cardinal A) (cardinal (A -> Prop)).
Proof.
eapply next_cardinal_supremum.
apply _cardinal_lt_iff.
assert (LE: _cardinal_le A (A -> Prop)).
{ eapply _cardinal_le_intro with (fun a0 a1 => a0 = a1).
i. eapply equal_f with (x:=a1) in EQ.
rewrite EQ. auto.
}
{ split; auto. ii. inv H.
hexploit (choice (fun (a: A) (P1: A -> Prop) =>
forall P0, f P0 = a -> P0 = P1)).
{ i. destruct (classic (exists P0, f P0 = x)).
{ des. exists P0. i. rewrite <- H0 in *. eauto. }
{ exists (fun _ => True). i. exfalso. eapply H; eauto. }
}
i. des. hexploit (cantor_theorem f0). i. des.
eapply (H0 (f P)). exploit H; eauto.
}
Qed.
End NEXT.
Lemma next_cardinal_le A B
(CARDINAL: Ord.le (cardinal A) (cardinal B)):
Ord.le (next_cardinal A) (next_cardinal B).
Proof.
assert (EQ: Ord.eq (next_cardinal B) (cardinal (ToSet.to_total_set (next_cardinal B)))).
{ eapply of_cardinal_unique.
{ eapply next_cardinal_of_cardinal. }
{ eapply cardinal_of_cardinal. }
}
transitivity (cardinal (ToSet.to_total_set (next_cardinal B))).
2: { apply EQ. }
eapply next_cardinal_supremum.
eapply Ord.lt_le_lt.
2: { eapply EQ. }
eapply Ord.le_lt_lt.
{ eapply CARDINAL. }
{ eapply next_cardinal_incr. }
Qed.
Lemma next_cardinal_eq A B
(CARDINAL: Ord.eq (cardinal A) (cardinal B)):
Ord.eq (next_cardinal A) (next_cardinal B).
Proof.
split.
- eapply next_cardinal_le. eapply CARDINAL.
- eapply next_cardinal_le. eapply CARDINAL.
Qed.
Lemma next_cardinal_lt A B
(CARDINAL: Ord.lt (cardinal A) (cardinal B)):
Ord.lt (next_cardinal A) (next_cardinal B).
Proof.
eapply next_cardinal_supremum in CARDINAL.
eapply Ord.le_lt_lt.
{ eapply CARDINAL. }
{ eapply next_cardinal_incr. }
Qed.
Lemma next_cardinal_le_iff A B:
Ord.le (cardinal A) (cardinal B) <-> Ord.le (next_cardinal A) (next_cardinal B).
Proof.
split; i.
{ eapply next_cardinal_le; auto. }
{ destruct (ClassicOrd.total (cardinal A) (cardinal B)); auto.
eapply next_cardinal_lt in H0. exfalso. eapply Ord.lt_not_le; eauto. }
Qed.
Lemma next_cardinal_eq_iff A B:
Ord.eq (cardinal A) (cardinal B) <-> Ord.eq (next_cardinal A) (next_cardinal B).
Proof.
split; i.
{ split.
{ eapply next_cardinal_le_iff. eapply H. }
{ eapply next_cardinal_le_iff. eapply H. }
}
{ split.
{ eapply next_cardinal_le_iff. eapply H. }
{ eapply next_cardinal_le_iff. eapply H. }
}
Qed.
Lemma next_cardinal_lt_iff A B:
Ord.lt (cardinal A) (cardinal B) <-> Ord.lt (next_cardinal A) (next_cardinal B).
Proof.
destruct (ClassicOrd.total (cardinal B) (cardinal A)).
{ split.
{ i. exfalso. eapply Ord.lt_not_le; eauto. }
{ i. eapply next_cardinal_le_iff in H.
exfalso. eapply Ord.lt_not_le; eauto. }
}
{ split; i; auto. eapply next_cardinal_lt; auto. }
Qed.
Definition is_cardinal (c: Ord.t): Prop :=
of_cardinal (ToSet.to_total_set c) c.
Lemma same_cardinal_of_cardinal A B (EQ: Ord.eq (cardinal A) (cardinal B))
c (CARDINAL: of_cardinal A c):
of_cardinal B c.
Proof.
eapply of_cardinal_unique in CARDINAL.
2: { eapply cardinal_of_cardinal. }
eapply eq_of_cardinal.
2: { eapply cardinal_of_cardinal. }
transitivity (cardinal A); auto. symmetry. auto.
Qed.
Lemma cardinal_join_upperbound X (TS: X -> Type):
of_cardinal (ToSet.to_total_set (Ord.join (fun x => cardinal (TS x)))) (Ord.join (fun x => cardinal (TS x))).
Proof.
split.
{ exists (ToSet.to_total_rel (Ord.join (fun x : X => cardinal (TS x)))), (ToSet.to_total_well_founded _). splits.
- eapply ToSet.to_total_total.
- symmetry. eapply ToSet.to_total_eq. }
{ i. des. eapply Ord.join_supremum. i. etransitivity.
2: { eapply IN0. }
etransitivity.
2: { eapply cardinal_lowerbound; auto. }
transitivity (cardinal (ToSet.to_total_set (cardinal (TS a)))).
{ eapply cardinal_to_total_bij1. }
{ eapply to_total_le. eapply (Ord.join_upperbound (fun x : X => cardinal (TS x))). }
}
Qed.
Lemma of_cardinal_join_upperbound A (os: A -> Ord.t)
(CARD: forall a, of_cardinal (ToSet.to_total_set (os a)) (os a)):
of_cardinal (ToSet.to_total_set (Ord.join os)) (Ord.join os).
Proof.
assert (Ord.eq (Ord.join (fun x : A => cardinal (ToSet.to_total_set (os x)))) (Ord.join os)).
{ split.
{ eapply Ord.join_supremum. i. transitivity (os a).
{ eapply cardinal_to_total_bij2; eauto. }
{ eapply Ord.join_upperbound. }
}
{ eapply Ord.join_supremum. i. transitivity (cardinal (ToSet.to_total_set (os a))).
{ eapply cardinal_to_total_bij2; eauto. }
{ eapply (Ord.join_upperbound (fun x : A => cardinal (ToSet.to_total_set (os x)))). }
}
}
hexploit (cardinal_join_upperbound (fun a => ToSet.to_total_set (os a))). i.
eapply same_cardinal_of_cardinal in H0.
{ eapply eq_of_cardinal.
2: { eapply H0. }
{ auto. }
}
{ split.
- eapply to_total_le; apply H.
- eapply to_total_le; apply H.
}
Qed.
Lemma of_cardinal_size A c (CARDINAL: of_cardinal A c):
of_cardinal (ToSet.to_total_set c) c.
Proof.
eapply same_cardinal_of_cardinal; eauto.
etransitivity.
{ eapply cardinal_to_total_bij1. }
eapply of_cardinal_unique in CARDINAL.
2: { eapply cardinal_of_cardinal. }
split.
{ eapply to_total_le. eapply CARDINAL. }
{ eapply to_total_le. eapply CARDINAL. }
Qed.
Lemma of_cardinal_is_cardinal A c (CARDINAL: of_cardinal A c):
is_cardinal c.
Proof.
eapply of_cardinal_size; eauto.
Qed.
Lemma eq_is_cardinal c0 c1 (EQ: Ord.eq c0 c1) (CARD0: is_cardinal c0):
is_cardinal c1.
Proof.
eapply of_cardinal_is_cardinal. eapply eq_of_cardinal; eauto.
Qed.
Section ALEPH.
Lemma le_aleph_gen o0 o1 (LE: Ord.le o0 o1):
Ord.le (next_cardinal (ToSet.to_total_set o0)) (next_cardinal (ToSet.to_total_set o1)).
Proof.
i. eapply next_cardinal_le. eapply to_total_le. apply LE.
Qed.
Lemma eq_aleph_gen o0 o1 (EQ: Ord.eq o0 o1):
Ord.eq (next_cardinal (ToSet.to_total_set o0)) (next_cardinal (ToSet.to_total_set o1)).
Proof.
split.
- eapply le_aleph_gen. apply EQ.
- eapply le_aleph_gen. apply EQ.
Qed.
Lemma aleph_gen_lt o:
Ord.lt o (next_cardinal (ToSet.to_total_set o)).
Proof.
eapply Ord.eq_lt_lt.
{ eapply ToSet.to_total_eq. }
eapply next_cardinal_upperbound.
reflexivity.
Qed.
Lemma aleph_gen_le o:
Ord.le o (next_cardinal (ToSet.to_total_set o)).
Proof.
eapply Ord.lt_le. eapply aleph_gen_lt.
Qed.
Definition aleph_gen (o: Ord.t) := next_cardinal (ToSet.to_total_set o).
Definition aleph := Ord.orec Ord.omega aleph_gen.
Lemma le_aleph o0 o1 (LE: Ord.le o0 o1):
Ord.le (aleph o0) (aleph o1).
Proof.
eapply Ord.le_orec; auto.
eapply le_aleph_gen.
Qed.
Lemma lt_aleph o0 o1 (LE: Ord.lt o0 o1):
Ord.lt (aleph o0) (aleph o1).
Proof.
eapply Ord.S_supremum in LE.
eapply Ord.lt_le_lt.
2: { eapply le_aleph; eauto. }
eapply Ord.lt_eq_lt.
{ eapply Ord.orec_S.
{ eapply aleph_gen_le. }
{ eapply le_aleph_gen. }
}
eapply aleph_gen_lt.
Qed.
Lemma aleph_le_omega o:
Ord.le Ord.omega (aleph o).
Proof.
eapply Ord.orec_le_base.
eapply le_aleph_gen.
Qed.
Lemma aleph_expand:
forall o, Ord.le o (aleph o).
Proof.
i. transitivity (Ord.orec Ord.O Ord.S o).
{ eapply Ord.orec_of_S. }
eapply (@Ord.rec_mon _ Ord.le Ord.join Ord.O Ord.S Ord.omega aleph_gen).
{ eapply Ord.O_bot. }
{ i. eapply Ord.S_supremum. eapply Ord.le_lt_lt; eauto.
eapply aleph_gen_lt.
}
{ eapply Ord.le_PreOrder. }
{ i. eapply Ord.join_upperbound. }
{ i. eapply Ord.join_supremum. auto. }
Qed.
(* Lemma aleph_is_cardinal: *)
(* forall o, is_cardinal (aleph o). *)
(* Proof. *)
(* eapply (rec_wf Ord.le join (fun o => of_cardinal (ToSet.to_total_set o) o) aleph_gen omega); eauto. *)
(* { i. reflexivity. } *)
(* { i. transitivity d1; auto. } *)
(* { i. eapply join_upperbound. } *)
(* { i. eapply join_supremum. auto. } *)
(* { i. eapply of_cardinal_join_upperbound. auto. } *)
(* { admit. } *)
(* { i. eapply next_cardinal_of_cardinal. } *)
(* { i. eapply aleph_gen_le. } *)
(* { i. eapply aleph_gen_eq; auto. } *)
(* Admitted. *)
End ALEPH.
Section BETH.
Definition beth_gen (o: Ord.t) := cardinal (ToSet.to_total_set o -> Prop).
Definition beth := Ord.orec Ord.omega beth_gen.
Lemma le_beth_gen o0 o1 (LE: Ord.le o0 o1):
Ord.le (beth_gen o0) (beth_gen o1).
Proof.
eapply to_total_le in LE.
apply _cardinal_le_iff in LE. apply _cardinal_le_iff.
eapply _cardinal_le_power. auto.
Qed.
Lemma eq_beth_gen o0 o1 (EQ: Ord.eq o0 o1):
Ord.eq (beth_gen o0) (beth_gen o1).
Proof.
split.
- eapply le_beth_gen. apply EQ.
- eapply le_beth_gen. apply EQ.
Qed.
Lemma beth_gen_lt o:
Ord.lt o (beth_gen o).
Proof.
eapply Ord.eq_lt_lt.
{ eapply ToSet.to_total_eq. }
eapply Ord.lt_le_lt.
2: { eapply next_cardinal_le_power_set. }
eapply next_cardinal_upperbound. reflexivity.
Qed.
Lemma beth_gen_le o:
Ord.le o (beth_gen o).
Proof.
eapply Ord.lt_le. eapply beth_gen_lt.
Qed.
Lemma aleph_gen_le_beth_gen o:
Ord.le (aleph_gen o) (beth_gen o).
Proof.
eapply next_cardinal_le_power_set.
Qed.
Lemma le_beth o0 o1 (LE: Ord.le o0 o1):
Ord.le (beth o0) (beth o1).
Proof.
eapply Ord.le_orec; auto.
eapply le_beth_gen.
Qed.
Lemma lt_beth o0 o1 (LE: Ord.lt o0 o1):
Ord.lt (beth o0) (beth o1).
Proof.
eapply Ord.S_supremum in LE.
eapply Ord.lt_le_lt.
2: { eapply le_beth; eauto. }
eapply Ord.lt_eq_lt.
{ eapply Ord.orec_S.
{ eapply beth_gen_le. }
{ eapply le_beth_gen. }
}
eapply beth_gen_lt.
Qed.
Lemma beth_le_omega o:
Ord.le Ord.omega (beth o).
Proof.
eapply Ord.orec_le_base.
eapply le_beth_gen.
Qed.
Lemma beth_expand:
forall o, Ord.le o (beth o).
Proof.
i. transitivity (Ord.orec Ord.O Ord.S o).
{ eapply Ord.orec_of_S. }
eapply (@Ord.rec_mon _ Ord.le Ord.join Ord.O Ord.S Ord.omega beth_gen).
{ eapply Ord.O_bot. }
{ i. eapply Ord.S_supremum. eapply Ord.le_lt_lt; eauto.
eapply beth_gen_lt.
}
{ eapply Ord.le_PreOrder. }
{ i. eapply Ord.join_upperbound. }
{ i. eapply Ord.join_supremum. auto. }
Qed.
Lemma aleph_le_beth o:
Ord.le (aleph o) (beth o).
Proof.
eapply Ord.orec_mon.
{ reflexivity. }
{ i. transitivity (aleph_gen o1).
{ eapply le_aleph_gen. auto. }
{ eapply aleph_gen_le_beth_gen. }
}
Qed.
End BETH.
Section FINITE.
Fixpoint finite (n: nat): Type :=
match n with
| 0 => False
| Datatypes.S n' => option (finite n')
end.
Fixpoint finite_lt (n: nat): finite n -> finite n -> Prop :=
match n with
| 0 => fun _ _ => False
| Datatypes.S n' =>
fun x y => match x, y with
| Some x', Some y' => finite_lt n' x' y'
| Some x', None => True
| _, _ => False
end
end.
Lemma finite_total: forall n x0 x1, finite_lt n x0 x1 \/ x0 = x1 \/ finite_lt n x1 x0.
Proof.
induction n.
{ i. ss. }
{ i. ss. destruct x0, x1; ss; eauto.
destruct (IHn f f0) as [|[]]; eauto. subst. auto.
}
Qed.
Lemma finite_lt_acc: forall n x (ACC: Acc (finite_lt n) x), Acc (finite_lt (Datatypes.S n)) (Some x).
Proof.
intros n x ACC. induction ACC. econs. i. destruct y; ss.
eapply H0. auto.
Qed.
Lemma finite_well_founded: forall n, well_founded (finite_lt n).
Proof.
induction n.
- ii. econs. i. ss.
- ii. econs. i. destruct a, y; ss.
+ eapply finite_lt_acc. eapply IHn.
+ eapply finite_lt_acc. eapply IHn.
Qed.
Lemma finite_from_acc_eq:
forall n (x: finite n)
(ACC0: Acc (finite_lt n) x) (ACC1: Acc (finite_lt (Datatypes.S n)) (Some x)),
Ord.eq (Ord.from_acc ACC0) (Ord.from_acc ACC1).
Proof.
Local Transparent Ord.from_acc.
intros n x ACC. dup ACC.
induction ACC0. i. destruct ACC, ACC1. ss. split.
{ econs. i. destruct a1. exists (exist _ (Some x0) (f)). ss. eapply H0. auto. }
{ econs. i. destruct a1. destruct x0; ss. exists (exist _ f y). ss. eapply H0. auto. }
Qed.
Lemma finite_from_wf_eq:
forall n (x: finite n),
Ord.eq (Ord.from_wf (finite_well_founded n) x) (Ord.from_wf (finite_well_founded (Datatypes.S n)) (Some x)).
Proof.
Local Transparent Ord.from_wf.
i. eapply finite_from_acc_eq.
Qed.
Lemma finite_from_wf_set_eq:
forall n,
Ord.eq (Ord.from_wf_set (finite_well_founded n)) (Ord.from_wf (finite_well_founded (Datatypes.S n)) None).
Proof.
Local Transparent Ord.from_wf_set.
i. split.
{ eapply Ord.build_supremum. i. eapply Ord.le_lt_lt.
{ eapply finite_from_wf_eq. }
{ eapply Ord.lt_from_wf. ss. }
}
{ unfold Ord.from_wf at 1. destruct (finite_well_founded (Datatypes.S n) None).
ss. econs. i. destruct a0. ss. destruct x; ss.
exists f. eapply finite_from_acc_eq.
}
Qed.
Lemma finite_S:
forall n,
Ord.eq (Ord.S (Ord.from_wf_set (finite_well_founded n))) (Ord.from_wf_set (finite_well_founded (Datatypes.S n))).
Proof.
Local Transparent Ord.from_wf_set Ord.S.
i. split.
- eapply Ord.S_supremum. eapply Ord.le_lt_lt.
{ eapply finite_from_wf_set_eq. }
{ eapply Ord.from_wf_set_upperbound. }
- econs. i. exists tt. ss. etransitivity.
2: { eapply finite_from_wf_set_eq. }