-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cantor.v
1110 lines (1056 loc) · 34 KB
/
Cantor.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
(* Proof of Cantor's Theorem *)
Require Import SetoidClass List PeanoNat Omega.
Import ListNotations.
Require Import Class Util.
Infix "!" := list_index (at level 10).
Definition ord_cons_x{X Y}`{Ord X, Ord Y}(ps : list (X * Y)) :=
forall i j, Fin_le i j -> fst (ps ! i) << fst (ps ! j).
Lemma ord_cons_x_tail{X Y}`{Ord X, Ord Y}(p : X * Y)(ps : list (X * Y)) :
ord_cons_x (p::ps) -> ord_cons_x ps.
Proof.
intros Hpps i j Hij.
exact (Hpps (inr i) (inr j) Hij).
Qed.
Definition ord_cons_y{X Y}`{Ord X, Ord Y}(ps : list (X * Y)) :=
forall i j, Fin_le i j -> snd (ps ! i) << snd (ps ! j).
Lemma ord_cons_y_tail{X Y}`{Ord X, Ord Y}(p : X * Y)(ps : list (X * Y)) :
ord_cons_y (p::ps) -> ord_cons_y ps.
Proof.
intros Hpps i j Hij.
exact (Hpps (inr i) (inr j) Hij).
Qed.
Definition below_x{X Y}`{Ord X, Ord Y}(x : X)(ps : list (X * Y)) := forall i, x << fst (ps ! i).
Definition below_y{X Y}`{Ord X, Ord Y}(y : Y)(ps : list (X * Y)) := forall i, y << snd (ps ! i).
Record Partial_Iso(X Y : Type)`{CDLOWOEP X, CDLOWOEP Y} := {
pairs : list (X * Y);
pairs_ord_cons_x : ord_cons_x pairs;
pairs_ord_cons_y : ord_cons_y pairs
}.
Definition empty_Partial_Iso{X Y}`{CDLOWOEP X, CDLOWOEP Y} : Partial_Iso X Y := {|
pairs := [];
pairs_ord_cons_x := fun i => match i with end;
pairs_ord_cons_y := fun i => match i with end
|}.
Fixpoint insert_x_aux{X Y}`{CDLOWOEP X, CDLOWOEP Y}(last : option Y)(x : X)(ps : list (X * Y)){struct ps} : list (X * Y) :=
match ps with
| [] => match last with
| None => [(x,from_nat 0)]
| Some y_r => [(x, right y_r)]
end
| (x0,y0)::qs => match lt_trich x x0 with
| inleft (Specif.left _) => match last with
| None => (x, left y0)::ps
| Some y_r => (x, mid y_r y0)::ps
end
| inleft (Specif.right _) => ps
| inright _ => (x0,y0) :: insert_x_aux (Some y0) x qs
end
end.
Fixpoint insert_y_aux{X Y}`{CDLOWOEP X, CDLOWOEP Y}(last : option X)(y : Y)(ps : list (X * Y)){struct ps} : list (X * Y) :=
match ps with
| [] => match last with
| None => [(from_nat 0,y)]
| Some x_r => [(right x_r, y)]
end
| (x0,y0)::qs => match lt_trich y y0 with
| inleft (Specif.left _) => match last with
| None => (left x0, y)::ps
| Some x_r => (mid x_r x0, y)::ps
end
| inleft (Specif.right _) => ps
| inright _ => (x0,y0) :: insert_y_aux (Some x0) y qs
end
end.
Definition insert_x{X Y}`{CDLOWOEP X, CDLOWOEP Y} : X -> list (X * Y) -> list (X * Y) := insert_x_aux None.
Definition insert_y{X Y}`{CDLOWOEP X, CDLOWOEP Y} : Y -> list (X * Y) -> list (X * Y) := insert_y_aux None.
Lemma In_insert_x_aux_In{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y))(p : X * Y)(x : X)(y : Y), setoidIn p ps -> setoidIn p (insert_x_aux (Some y) x ps).
Proof.
induction ps; intros.
- destruct H3.
- simpl.
destruct a.
destruct (lt_trich x x0) as [[|]|].
+ right; exact H3.
+ exact H3.
+ destruct H3.
* left; exact H3.
* right; apply IHps; auto.
Qed.
Lemma In_insert_x_In{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y))(p : X * Y)(x : X),
setoidIn p ps -> setoidIn p (insert_x x ps).
Proof.
intros.
destruct ps.
- destruct H3.
- unfold insert_x.
simpl.
destruct p0.
destruct (lt_trich x x0) as [[|]|].
+ right; exact H3.
+ exact H3.
+ destruct H3.
* left; exact H3.
* right; apply In_insert_x_aux_In; exact H3.
Qed.
Lemma In_insert_y_aux_In{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y))(p : X * Y)(y : Y)(x : X), setoidIn p ps -> setoidIn p (insert_y_aux (Some x) y ps).
Proof.
induction ps; intros.
- destruct H3.
- simpl.
destruct a.
destruct (lt_trich y y0) as [[|]|].
+ right; exact H3.
+ exact H3.
+ destruct H3.
* left; exact H3.
* right; apply IHps; auto.
Qed.
Lemma In_insert_y_In{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y))(p : X * Y)(y : Y),
setoidIn p ps -> setoidIn p (insert_y y ps).
Proof.
intros.
destruct ps.
- destruct H3.
- unfold insert_y.
simpl.
destruct p0.
destruct (lt_trich y y0) as [[|]|].
+ right; exact H3.
+ exact H3.
+ destruct H3.
* left; exact H3.
* right; apply In_insert_y_aux_In; exact H3.
Qed.
Lemma below_x_x_lemma{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y))(x x' : X)(y : Y), below_x x ps -> x << x' ->
below_x x (insert_x_aux (Some y) x' ps).
Proof.
induction ps; intros.
- simpl.
intros [[]|[]]; exact H4.
- simpl.
destruct a as [x0 y0].
destruct lt_trich as [[Hlt|Heq]|Hgt].
+ intros [|[|i]]; simpl.
* exact H4.
* apply (lt_trans _ x' _); auto.
* apply (H3 (inr i)).
+ exact H3.
+ intros [|i]; simpl.
* apply (H3 (inl tt)).
* apply IHps; auto.
intro j; apply (H3 (inr j)).
Qed.
Lemma below_x_y_lemma{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y))(x x' : X)(y : Y), ord_cons_x ps -> below_x x ps -> (x = x' \/ x << x') -> below_x x (insert_y_aux (Some x') y ps).
Proof.
induction ps; intros.
- simpl.
intros [[]|[]]; simpl.
destruct H5.
+ rewrite H5; apply right_lt.
+ apply (lt_trans _ x' _); auto.
apply right_lt.
- simpl.
destruct a as [x0 y0].
destruct lt_trich as [[Hlt|Heq]|Hgt].
+ intros [|[|i]]; simpl.
* pose (H4 (inl tt)) as pf; simpl in pf.
destruct (lt_trich x' x0) as [[Glt|Geq]|Ggt].
** destruct H5.
*** rewrite H5.
apply mid_lt_left; auto.
*** apply (lt_trans _ x' _); auto.
apply mid_lt_left; auto.
** apply (lt_morph x _ x' _).
*** reflexivity.
*** transitivity (mid x' x').
symmetry; apply mid_idem.
apply mid_morph; [ reflexivity | auto ].
*** apply (lt_morph x _ x0 _).
**** reflexivity.
**** symmetry; exact Geq.
**** exact pf.
** apply (lt_trans _ x0).
*** exact pf.
*** apply mid_lt_left2; auto.
* exact (H4 (inl tt)).
* exact (H4 (inr i)).
+ exact H4.
+ intros [|i]; simpl.
* exact (H4 (inl tt)).
* eapply IHps.
** eapply ord_cons_x_tail; exact H3.
** intro j.
exact (H4 (inr j)).
** right.
exact (H4 (inl tt)).
Qed.
Lemma below_y_y_lemma{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y))(y y' : Y)(x : X), below_y y ps -> y << y' ->
below_y y (insert_y_aux (Some x) y' ps).
Proof.
induction ps; intros.
- simpl.
intros [[]|[]]; exact H4.
- simpl.
destruct a as [x0 y0].
destruct lt_trich as [[Hlt|Heq]|Hgt].
+ intros [|[|i]]; simpl.
* exact H4.
* apply (lt_trans _ y' _); auto.
* apply (H3 (inr i)).
+ exact H3.
+ intros [|i]; simpl.
* apply (H3 (inl tt)).
* apply IHps; auto.
intro j; apply (H3 (inr j)).
Qed.
Lemma below_y_x_lemma{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y))(y y' : Y)(x : X), ord_cons_y ps -> below_y y ps -> (y = y' \/ y << y') -> below_y y (insert_x_aux (Some y') x ps).
Proof.
induction ps; intros.
- simpl.
intros [[]|[]]; simpl.
destruct H5.
+ rewrite H5; apply right_lt.
+ apply (lt_trans _ y' _); auto.
apply right_lt.
- simpl.
destruct a as [x0 y0].
destruct lt_trich as [[Hlt|Heq]|Hgt].
+ intros [|[|i]]; simpl.
* pose (H4 (inl tt)) as pf; simpl in pf.
destruct (lt_trich y' y0) as [[Glt|Geq]|Ggt].
** destruct H5.
*** rewrite H5.
apply mid_lt_left; auto.
*** apply (lt_trans _ y' _); auto.
apply mid_lt_left; auto.
** apply (lt_morph y _ y' _).
*** reflexivity.
*** transitivity (mid y' y').
symmetry; apply mid_idem.
apply mid_morph; [ reflexivity | auto ].
*** apply (lt_morph y _ y0 _).
**** reflexivity.
**** symmetry; exact Geq.
**** exact pf.
** apply (lt_trans _ y0).
*** exact pf.
*** apply mid_lt_left2; auto.
* exact (H4 (inl tt)).
* exact (H4 (inr i)).
+ exact H4.
+ intros [|i]; simpl.
* exact (H4 (inl tt)).
* eapply IHps.
** eapply ord_cons_y_tail; exact H3.
** intro j.
exact (H4 (inr j)).
** right.
exact (H4 (inl tt)).
Qed.
Lemma insert_x_aux_ord_cons_x{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y)) x y, ord_cons_x ps ->
ord_cons_x (insert_x_aux (Some y) x ps).
Proof.
induction ps; intros.
- simpl.
intros [[]|[]] [[]|[]] Hij.
destruct Hij.
- simpl.
destruct a as [x0 y0].
destruct lt_trich as [[Hlt|Heq]|Hgt].
+ intros [|[|i]] [|[|j]] Hij; simpl; try destruct Hij.
* exact Hlt.
* apply (lt_trans _ x0 _); auto.
apply (H3 (inl tt) (inr j)); exact I.
* apply (H3 (inl tt) (inr j)); exact I.
* apply (H3 (inr i) (inr j)); exact Hij.
+ exact H3.
+ intros [|i] [|j] Hij; simpl; try destruct Hij.
* apply below_x_x_lemma; auto.
intro i.
apply (H3 (inl tt) (inr i)); exact I.
* apply IHps.
** exact (ord_cons_x_tail (x0,y0) ps H3).
** exact Hij.
Qed.
Lemma insert_y_aux_ord_cons_x{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y)) x y, ord_cons_x ps ->
below_x x ps -> ord_cons_x (insert_y_aux (Some x) y ps).
Proof.
induction ps; intros.
- simpl.
intros [[]|[]] [[]|[]] Hij; simpl.
destruct Hij.
- simpl.
destruct a as [x0 y0].
assert (x << x0) by (apply (H4 (inl tt))).
destruct lt_trich as [[Hlt|Heq]|Hgt].
+ intros [|[|i]] [|[|j]] Hij; simpl; try destruct Hij.
* apply mid_lt_right; auto.
* apply (lt_trans _ x0 _).
** apply mid_lt_right; auto.
** apply (H3 (inl tt) (inr j)); exact I.
* apply (H3 (inl tt) (inr j)); exact I.
* apply (H3 (inr i) (inr j)); exact Hij.
+ exact H3.
+ intros [|i] [|j] Hij; simpl; try destruct Hij.
* eapply below_x_y_lemma.
** eapply ord_cons_x_tail; exact H3.
** intro i. apply (H3 (inl tt) (inr i)); exact I.
** left; reflexivity.
* apply IHps.
** exact (ord_cons_x_tail (x0,y0) ps H3).
** intro k; apply (H3 (inl tt) (inr k)); exact I.
** exact Hij.
Qed.
Lemma insert_y_aux_ord_cons_y{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y)) x y, ord_cons_y ps ->
ord_cons_y (insert_y_aux (Some x) y ps).
Proof.
induction ps; intros.
- simpl.
intros [[]|[]] [[]|[]] Hij.
destruct Hij.
- simpl.
destruct a as [x0 y0].
destruct lt_trich as [[Hlt|Heq]|Hgt].
+ intros [|[|i]] [|[|j]] Hij; simpl; try destruct Hij.
* exact Hlt.
* apply (lt_trans _ y0 _); auto.
apply (H3 (inl tt) (inr j)); exact I.
* apply (H3 (inl tt) (inr j)); exact I.
* apply (H3 (inr i) (inr j)); exact Hij.
+ exact H3.
+ intros [|i] [|j] Hij; simpl; try destruct Hij.
* apply below_y_y_lemma; auto.
intro i.
apply (H3 (inl tt) (inr i)); exact I.
* apply IHps.
exact (ord_cons_y_tail (x0,y0) ps H3).
exact Hij.
Qed.
Lemma insert_x_aux_ord_cons_y{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y)) x y, ord_cons_y ps ->
below_y y ps -> ord_cons_y (insert_x_aux (Some y) x ps).
Proof.
induction ps; intros.
- simpl.
intros [[]|[]] [[]|[]] Hij; simpl.
destruct Hij.
- simpl.
destruct a as [x0 y0].
assert (y << y0) by (apply (H4 (inl tt))).
destruct lt_trich as [[Hlt|Heq]|Hgt].
+ intros [|[|i]] [|[|j]] Hij; simpl; try destruct Hij.
* apply mid_lt_right; auto.
* apply (lt_trans _ y0 _).
** apply mid_lt_right; auto.
** apply (H3 (inl tt) (inr j)); exact I.
* apply (H3 (inl tt) (inr j)); exact I.
* apply (H3 (inr i) (inr j)); exact Hij.
+ exact H3.
+ intros [|i] [|j] Hij; simpl; try destruct Hij.
* eapply below_y_x_lemma.
** eapply ord_cons_y_tail; exact H3.
** intro i. apply (H3 (inl tt) (inr i)); exact I.
** left; reflexivity.
* apply IHps.
** exact (ord_cons_y_tail (x0,y0) ps H3).
** intro k; apply (H3 (inl tt) (inr k)); exact I.
** exact Hij.
Qed.
Lemma insert_x_ord_cons_x{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y)) x, ord_cons_x ps ->
ord_cons_x (insert_x x ps).
Proof.
intros.
unfold insert_x.
destruct ps.
- intros [[]|[]] [[]|[]] [].
- simpl.
destruct p.
destruct (lt_trich x x0) as [[Hlt|Heq]|Hgt].
+ intros [[]|i] [[]|j] Hij; simpl.
* destruct Hij.
* destruct j; simpl.
** auto.
** apply (lt_trans _ x0 _); auto.
apply (H3 (inl tt) (inr f)); exact I.
* destruct Hij.
* destruct i,j; simpl.
** destruct Hij.
** apply (H3 (inl tt) (inr f)); exact I.
** destruct Hij.
** apply (H3 (inr f) (inr f0)); exact Hij.
+ exact H3.
+ intros [[]|i] [[]|j] Hij; simpl.
* destruct Hij.
* apply below_x_x_lemma; auto.
intro i.
apply (H3 (inl tt) (inr i)); auto.
* destruct Hij.
* eapply insert_x_aux_ord_cons_x; auto.
eapply ord_cons_x_tail; exact H3.
Qed.
Lemma insert_y_ord_cons_y{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y)) y, ord_cons_y ps ->
ord_cons_y (insert_y y ps).
Proof.
intros.
unfold insert_y.
destruct ps.
- intros [[]|[]] [[]|[]] [].
- simpl.
destruct p.
destruct (lt_trich y y0) as [[Hlt|Heq]|Hgt].
+ intros [[]|i] [[]|j] Hij; simpl.
* destruct Hij.
* destruct j; simpl.
** auto.
** apply (lt_trans _ y0 _); auto.
apply (H3 (inl tt) (inr f)); exact I.
* destruct Hij.
* destruct i,j; simpl.
** destruct Hij.
** apply (H3 (inl tt) (inr f)); exact I.
** destruct Hij.
** apply (H3 (inr f) (inr f0)); exact Hij.
+ exact H3.
+ intros [[]|i] [[]|j] Hij; simpl.
* destruct Hij.
* apply below_y_y_lemma; auto.
intro i.
apply (H3 (inl tt) (inr i)); auto.
* destruct Hij.
* eapply insert_y_aux_ord_cons_y; auto.
eapply ord_cons_y_tail; exact H3.
Qed.
Lemma insert_x_ord_cons_y{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y)) x, ord_cons_y ps ->
ord_cons_y (insert_x x ps).
Proof.
intros.
unfold insert_x.
destruct ps.
- intros [[]|[]] [[]|[]] [].
- simpl.
destruct p.
destruct (lt_trich x x0) as [[Hlt|Heq]|Hgt].
+ intros [[]|i] [[]|j] Hij; simpl.
* destruct Hij.
* destruct j; simpl.
** apply left_lt.
** apply (lt_trans _ y _).
*** apply left_lt.
*** apply (H3 (inl tt) (inr f)); exact I.
* destruct Hij.
* destruct i,j; simpl.
** destruct Hij.
** apply (H3 (inl tt) (inr f)); exact I.
** destruct Hij.
** apply (H3 (inr f) (inr f0)); exact Hij.
+ exact H3.
+ intros [[]|i] [[]|j] Hij; simpl.
* destruct Hij.
* eapply below_y_x_lemma.
** eapply ord_cons_y_tail; exact H3.
** intro k; apply (H3 (inl tt) (inr k)); exact I.
** left; reflexivity.
* destruct Hij.
* eapply insert_x_aux_ord_cons_y.
eapply ord_cons_y_tail; exact H3.
** intro k; apply (H3 (inl tt) (inr k)); exact I.
** exact Hij.
Qed.
Lemma insert_y_ord_cons_x{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y)) y, ord_cons_x ps ->
ord_cons_x (insert_y y ps).
Proof.
intros.
unfold insert_y.
destruct ps.
- intros [[]|[]] [[]|[]] [].
- simpl.
destruct p.
destruct (lt_trich y y0) as [[Hlt|Heq]|Hgt].
+ intros [[]|i] [[]|j] Hij; simpl.
* destruct Hij.
* destruct j; simpl.
** apply left_lt.
** apply (lt_trans _ x _).
*** apply left_lt.
*** apply (H3 (inl tt) (inr f)); exact I.
* destruct Hij.
* destruct i,j; simpl.
** destruct Hij.
** apply (H3 (inl tt) (inr f)); exact I.
** destruct Hij.
** apply (H3 (inr f) (inr f0)); exact Hij.
+ exact H3.
+ intros [[]|i] [[]|j] Hij; simpl.
* destruct Hij.
* eapply below_x_y_lemma.
** eapply ord_cons_x_tail; exact H3.
** intro k; apply (H3 (inl tt) (inr k)); exact I.
** left; reflexivity.
* destruct Hij.
* eapply insert_y_aux_ord_cons_x.
eapply ord_cons_x_tail; exact H3.
** intro k; apply (H3 (inl tt) (inr k)); exact I.
** exact Hij.
Qed.
Lemma insert_x_aux_In{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y)) x y0,
{ y : Y & setoidIn (x,y) (insert_x_aux (Some y0) x ps) }.
Proof.
induction ps; intros.
- simpl.
exists (right y0).
left; split; reflexivity.
- simpl.
destruct a.
destruct (lt_trich x x0) as [[Hlt|Heq]|Hgt].
+ exists (mid y0 y).
left; reflexivity.
+ exists y.
left.
split; [auto|reflexivity].
+ destruct (IHps x y) as [y' Hy'].
exists y'.
right; exact Hy'.
Defined.
Lemma insert_x_In{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y)) x,
{ y : Y & setoidIn (x,y) (insert_x x ps) }.
Proof.
destruct ps.
- intro; simpl.
exists (from_nat 0).
left; split; reflexivity.
- intro; unfold insert_x; simpl.
destruct p.
destruct (lt_trich x x0) as [[Hlt|Heq]|Hgt].
+ exists (left y).
left; reflexivity.
+ exists y.
left; split; [auto|reflexivity].
+ destruct (insert_x_aux_In ps x y) as [y' Hy'].
exists y'.
right; exact Hy'.
Defined.
Lemma insert_y_aux_In{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y)) y x0,
{ x : X & setoidIn (x,y) (insert_y_aux (Some x0) y ps) }.
Proof.
induction ps; intros.
- simpl.
exists (right x0).
left; split; reflexivity.
- simpl.
destruct a.
destruct (lt_trich y y0) as [[Hlt|Heq]|Hgt].
+ exists (mid x0 x).
left; reflexivity.
+ exists x.
left.
split; [reflexivity|auto].
+ destruct (IHps y x) as [x' Hx'].
exists x'.
right; exact Hx'.
Defined.
Lemma insert_y_In{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y)) y,
{ x : X & setoidIn (x,y) (insert_y y ps) }.
Proof.
destruct ps.
- intro; simpl.
exists (from_nat 0).
left; split; reflexivity.
- intro; unfold insert_y; simpl.
destruct p.
destruct (lt_trich y y0) as [[Hlt|Heq]|Hgt].
+ exists (left x).
left; reflexivity.
+ exists x.
left; split; [reflexivity|auto].
+ destruct (insert_y_aux_In ps y x) as [x' Hx'].
exists x'.
right; exact Hx'.
Defined.
Lemma insert_x_aux_morph{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y))(p : X * Y)(x x' : X)(y : Y), x == x' -> setoidIn p (insert_x_aux (Some y) x ps) -> setoidIn p (insert_x_aux (Some y) x' ps).
Proof.
induction ps; intros; simpl.
- destruct p.
simpl in H4.
rewrite <- H3; auto.
- destruct a.
destruct (lt_trich x' x0) as [[Hlt|Heq]|Hgt].
+ simpl in H4.
destruct (lt_trich x x0) as [[Glt|Geq]|Ggt].
* destruct H4.
** left; rewrite H4; split; [auto|reflexivity].
** right; exact H4.
* elim (lt_irref x).
eapply lt_morph.
** symmetry; exact H3.
** symmetry; exact Geq.
** exact Hlt.
* elim (lt_irref x).
eapply lt_morph.
** symmetry; exact H3.
** reflexivity.
** apply (lt_trans _ x0 _); auto.
+ simpl in H4.
destruct (lt_trich x x0) as [[Glt|Geq]|Ggt].
* elim (lt_irref x).
eapply lt_morph.
** reflexivity.
** rewrite H3.
symmetry; exact Heq.
** exact Glt.
* exact H4.
* elim (lt_irref x).
eapply lt_morph.
** rewrite H3.
symmetry; exact Heq.
** reflexivity.
** exact Ggt.
+ simpl in H4.
destruct (lt_trich x x0) as [[Glt|Geq]|Ggt].
* elim (lt_irref x).
eapply lt_morph.
** reflexivity.
** symmetry; exact H3.
** apply (lt_trans _ x0 _); auto.
* elim (lt_irref x).
eapply lt_morph.
** symmetry; exact Geq.
** symmetry; exact H3.
** exact Hgt.
* destruct H4.
** left; exact H4.
** right; eapply IHps.
*** exact H3.
*** exact H4.
Qed.
Lemma insert_x_morph{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y))(p : X * Y)(x x' : X),
x == x' -> setoidIn p (insert_x x ps) -> setoidIn p (insert_x x' ps).
Proof.
destruct ps.
- simpl; intros.
destruct p.
rewrite <- H3; exact H4.
- intros; simpl.
unfold insert_x in H4.
simpl in H4.
destruct p.
unfold insert_x; simpl.
destruct (lt_trich x x0) as [[Hlt|Heq]|Hgt].
+ destruct (lt_trich x' x0) as [[Glt|Geq]|Ggt].
* destruct H4.
** destruct p0; destruct H4; left; split; auto.
rewrite H4; auto.
** right; exact H4.
* elim (lt_irref x).
eapply lt_morph.
** reflexivity.
** rewrite H3; symmetry; exact Geq.
** exact Hlt.
* elim (lt_irref x).
eapply lt_morph.
** reflexivity.
** symmetry; exact H3.
** apply (lt_trans _ x0 _); auto.
+ destruct (lt_trich x' x0) as [[Glt|Geq]|Ggt].
* elim (lt_irref x).
eapply lt_morph.
** symmetry; exact H3.
** symmetry; exact Heq.
** exact Glt.
* exact H4.
* elim (lt_irref x).
eapply lt_morph.
** symmetry; exact Heq.
** symmetry; exact H3.
** exact Ggt.
+ destruct (lt_trich x' x0) as [[Glt|Geq]|Ggt].
* elim (lt_irref x).
eapply lt_morph.
** symmetry; exact H3.
** reflexivity.
** apply (lt_trans _ x0 _); auto.
* elim (lt_irref x).
eapply lt_morph.
** rewrite H3; symmetry; exact Geq.
** reflexivity.
** exact Hgt.
* destruct H4.
** left; exact H4.
** right; eapply insert_x_aux_morph; [exact H3|exact H4].
Qed.
Lemma insert_y_aux_morph{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y))(p : X * Y)(y y' : Y)(x : X), y == y' -> setoidIn p (insert_y_aux (Some x) y ps) -> setoidIn p (insert_y_aux (Some x) y' ps).
Proof.
induction ps; intros; simpl.
- destruct p.
simpl in H4.
rewrite <- H3; auto.
- destruct a.
destruct (lt_trich y' y0) as [[Hlt|Heq]|Hgt].
+ simpl in H4.
destruct (lt_trich y y0) as [[Glt|Geq]|Ggt].
* destruct H4.
** left; rewrite H4; split; [reflexivity|auto].
** right; exact H4.
* elim (lt_irref y).
eapply lt_morph.
** symmetry; exact H3.
** symmetry; exact Geq.
** exact Hlt.
* elim (lt_irref y).
eapply lt_morph.
** symmetry; exact H3.
** reflexivity.
** apply (lt_trans _ y0 _); auto.
+ simpl in H4.
destruct (lt_trich y y0) as [[Glt|Geq]|Ggt].
* elim (lt_irref y).
eapply lt_morph.
** reflexivity.
** rewrite H3.
symmetry; exact Heq.
** exact Glt.
* exact H4.
* elim (lt_irref y).
eapply lt_morph.
** rewrite H3.
symmetry; exact Heq.
** reflexivity.
** exact Ggt.
+ simpl in H4.
destruct (lt_trich y y0) as [[Glt|Geq]|Ggt].
* elim (lt_irref y).
eapply lt_morph.
** reflexivity.
** symmetry; exact H3.
** apply (lt_trans _ y0 _); auto.
* elim (lt_irref y).
eapply lt_morph.
** symmetry; exact Geq.
** symmetry; exact H3.
** exact Hgt.
* destruct H4.
** left; exact H4.
** right; eapply IHps.
*** exact H3.
*** exact H4.
Qed.
Lemma insert_y_morph{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (ps : list (X * Y))(p : X * Y)(y y' : Y),
y == y' -> setoidIn p (insert_y y ps) -> setoidIn p (insert_y y' ps).
Proof.
destruct ps.
- simpl; intros.
destruct p.
rewrite <- H3; exact H4.
- intros; simpl.
unfold insert_y in H4.
simpl in H4.
destruct p.
unfold insert_y; simpl.
destruct (lt_trich y y0) as [[Hlt|Heq]|Hgt].
+ destruct (lt_trich y' y0) as [[Glt|Geq]|Ggt].
* destruct H4.
** destruct p0; destruct H4; left; split; auto.
rewrite H5; auto.
** right; exact H4.
* elim (lt_irref y).
eapply lt_morph.
** reflexivity.
** rewrite H3; symmetry; exact Geq.
** exact Hlt.
* elim (lt_irref y).
eapply lt_morph.
** reflexivity.
** symmetry; exact H3.
** apply (lt_trans _ y0 _); auto.
+ destruct (lt_trich y' y0) as [[Glt|Geq]|Ggt].
* elim (lt_irref y).
eapply lt_morph.
** symmetry; exact H3.
** symmetry; exact Heq.
** exact Glt.
* exact H4.
* elim (lt_irref y).
eapply lt_morph.
** symmetry; exact Heq.
** symmetry; exact H3.
** exact Ggt.
+ destruct (lt_trich y' y0) as [[Glt|Geq]|Ggt].
* elim (lt_irref y).
eapply lt_morph.
** symmetry; exact H3.
** reflexivity.
** apply (lt_trans _ y0 _); auto.
* elim (lt_irref y).
eapply lt_morph.
** rewrite H3; symmetry; exact Geq.
** reflexivity.
** exact Hgt.
* destruct H4.
** left; exact H4.
** right; eapply insert_y_aux_morph; [exact H3|exact H4].
Qed.
Fixpoint partial_map{X Y}`{CDLOWOEP X, CDLOWOEP Y}(n : nat) : list (X * Y) :=
match n with
| 0 => []
| S m => match even m with
| true => insert_x (from_nat (m/2)) (partial_map m)
| false => insert_y (from_nat (m/2)) (partial_map m)
end
end.
Lemma pm_eq{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall n, (partial_map n : list (X* Y)) =
match n with
| 0 => []
| S m => match even m with
| true => insert_x (from_nat (m/2)) (partial_map m)
| false => insert_y (from_nat (m/2)) (partial_map m)
end
end.
Proof.
intro.
destruct n; reflexivity.
Qed.
Lemma X_part_map_surj{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall x : X, {y : Y & setoidIn (x,y) (partial_map (S (2*(to_nat x))))}.
Proof.
intro.
rewrite pm_eq.
rewrite even_2k.
rewrite half_2k.
destruct (insert_x_In (partial_map (2 * to_nat x)) x) as [y Hy].
exists y.
eapply insert_x_morph.
- symmetry; apply from_to.
- exact Hy.
Defined.
Lemma Y_part_map_surj{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall y : Y, {x : X & setoidIn (x,y) (partial_map (S (S (2*(to_nat y)))))}.
Proof.
intro.
rewrite pm_eq.
rewrite odd_2k1.
rewrite half_2k1.
destruct (insert_y_In ((partial_map (S (2 * to_nat y))) : list (X * Y)) y) as [x Hx].
exists x.
eapply insert_y_morph.
- symmetry; apply from_to.
- exact Hx.
Defined.
Lemma part_map_cumulative{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall m n p, m <= n ->
setoidIn p (partial_map m : list (X * Y)) -> setoidIn p (partial_map n).
Proof.
intros.
induction H3.
- exact H4.
- rewrite pm_eq.
destruct (even m0).
+ apply In_insert_x_In; auto.
+ apply In_insert_y_In; auto.
Qed.
Lemma ord_cons_x_part_map{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall n, ord_cons_x (partial_map n : list (X * Y)).
Proof.
induction n.
- intros [].
- rewrite pm_eq.
destruct (even n).
+ apply insert_x_ord_cons_x; exact IHn.
+ apply insert_y_ord_cons_x; exact IHn.
Qed.
Lemma ord_cons_y_part_map{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall n, ord_cons_y (partial_map n : list (X * Y)).
Proof.
induction n.
- intros [].
- rewrite pm_eq.
destruct (even n).
+ apply insert_x_ord_cons_y; exact IHn.
+ apply insert_y_ord_cons_y; exact IHn.
Qed.
Lemma part_map_functional_xy{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (n : nat)(x x' : X)(y y' : Y),
x == x' -> setoidIn (x,y) (partial_map n) -> setoidIn (x',y') (partial_map n) -> y == y'.
Proof.
intros.
destruct (in_index _ _ H4) as [i Hi].
destruct (in_index _ _ H5) as [j Hj].
destruct (Fin_trich _ i j) as [[Heq|Hlt]|Hgt].
- rewrite Heq in Hi.
rewrite Hi in Hj.
destruct Hj; auto.
- destruct (partial_map n ! i) eqn:G.
destruct (partial_map n ! j) eqn:G0.
pose (ord_cons_x_part_map n i j Hlt).
rewrite G,G0 in l; simpl in l.
destruct Hi,Hj.
elim (lt_irref x).
eapply lt_morph.
+ exact H6.
+ rewrite H3; exact H8.
+ exact l.
- destruct (partial_map n ! i) eqn:G.
destruct (partial_map n ! j) eqn:G0.
pose (ord_cons_x_part_map n j i Hgt).
rewrite G,G0 in l; simpl in l.
destruct Hi,Hj.
elim (lt_irref x).
eapply lt_morph.
+ rewrite H3; exact H8.
+ exact H6.
+ exact l.
Qed.
Lemma part_map_functional_yx{X Y}`{CDLOWOEP X, CDLOWOEP Y} : forall (n : nat)(y y' : Y)(x x' : X),
y == y' -> setoidIn (x,y) (partial_map n) -> setoidIn (x',y') (partial_map n) -> x == x'.
Proof.
intros.
destruct (in_index _ _ H4) as [i Hi].
destruct (in_index _ _ H5) as [j Hj].
destruct (Fin_trich _ i j) as [[Heq|Hlt]|Hgt].
- rewrite Heq in Hi.
rewrite Hi in Hj.
destruct Hj; auto.
- destruct (partial_map n ! i) eqn:G.
destruct (partial_map n ! j) eqn:G0.
pose (ord_cons_y_part_map n i j Hlt).
rewrite G,G0 in l; simpl in l.
destruct Hi,Hj.
elim (lt_irref y).
eapply lt_morph.
+ exact H7.
+ rewrite H3; exact H9.
+ exact l.
- destruct (partial_map n ! i) eqn:G.
destruct (partial_map n ! j) eqn:G0.
pose (ord_cons_y_part_map n j i Hgt).
rewrite G,G0 in l; simpl in l.
destruct Hi,Hj.
elim (lt_irref y).
eapply lt_morph.
+ rewrite H3; exact H9.
+ exact H7.
+ exact l.
Qed.
Section Cantor.
Variable X : Type.
Variable sX : Setoid X.
Variable oX : Ord X.
Variable cX : CDLOWOEP oX.
Variable Y : Type.
Variable sY : Setoid Y.
Variable oY : Ord Y.
Variable cY : CDLOWOEP oY.
Theorem Cantor : Iso oX oY.
Proof.
exists (fun x => projT1 (X_part_map_surj x)) (fun y => projT1 (Y_part_map_surj y)).
- intros.
destruct (X_part_map_surj x); destruct (X_part_map_surj x'); simpl.
eapply (@part_map_functional_xy X Y).
+ exact H.
+ exact s.
+ rewrite <- (to_nat_morph _ _ H) in s0.
exact s0.
- intros.
destruct (Y_part_map_surj y); destruct (Y_part_map_surj y'); simpl.
eapply (@part_map_functional_yx X Y).
+ exact H.
+ exact s.