-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrealcuts.v
1534 lines (1435 loc) · 42 KB
/
realcuts.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Require Import QArith.
Require Import Setoid.
Require Import basics.
Require Import preord.
Require Import categories.
Require Import sets.
Require Import finsets.
Require Import esets.
Require Import effective.
Require Import directed.
Require Import plotkin.
Require Import joinable.
Require Import approx_rels.
Require Import profinite.
Require Import cusl.
Require Import rational_intervals.
Require Import realdom.
Require Import Qabs.
Require Import Qminmax.
Section cuts.
Record cut := Cut
{ cut_upper : eset Qpreord
; cut_lower : eset Qpreord
; cut_proper : forall u l, u ∈ cut_upper -> l ∈ cut_lower -> l <= u
; cut_is_lower : forall (q1 q2:Qpreord), q1 <= q2 -> q2 ∈ cut_lower -> q1 ∈ cut_lower
; cut_is_upper : forall (q1 q2:Qpreord), q1 <= q2 -> q1 ∈ cut_upper -> q2 ∈ cut_upper
(** probably should reformulate the prereals as directed sets of
intervals where the endpoints may be -∞ or ∞.
*)
; cut_nonextended : (exists x, x ∈ cut_upper) <-> (exists x, x ∈ cut_lower)
}.
Definition cut_ord (x y:cut) :=
cut_upper x ⊆ cut_upper y /\
cut_lower x ⊆ cut_lower y.
Program Definition cut_ord_mixin : Preord.mixin_of cut :=
Preord.Mixin cut cut_ord _ _ .
Next Obligation.
intros. red; split; red; auto.
Qed.
Next Obligation.
unfold cut_ord. intuition; repeat intro; eauto.
Qed.
Definition cut_preord := Preord.Pack cut cut_ord_mixin.
Program Definition rints_to_cut
(X:eset PreRealDom)
(Hdir:directed true X)
(Hdown:forall (r r':PreRealDom), r ≤ r' -> r' ∈ X -> r ∈ X )
: cut :=
Cut (eimage' _ _ rint_end X)
(eimage' _ _ rint_start X)
_ _ _ _.
Next Obligation.
unfold eimage'.
intros.
destruct H as [n1 ?].
destruct H0 as [n2 ?].
revert H. case_eq (X n1); intros.
revert H0. case_eq (X n2); intros.
destruct H1 as [? _]. destruct H2 as [? _].
red in H1. simpl in H1.
red in H2. simpl in H2.
rewrite H2. rewrite H1.
destruct (Hdir (c::c0::nil)%list).
exists c. apply cons_elem; auto.
red; simpl; intros.
apply cons_elem in H3. destruct H3. rewrite H3.
exists n1. rewrite H. auto.
apply cons_elem in H3. destruct H3. rewrite H3.
exists n2. rewrite H0. auto.
apply nil_elem in H3. elim H3.
destruct H3.
assert (c ≤ x).
apply H3. apply cons_elem; auto.
assert (c0 ≤ x).
apply H3. apply cons_elem; right. apply cons_elem; auto.
apply Qle_trans with (rint_start x).
apply rint_ord_test in H6. intuition.
apply Qle_trans with (rint_end x).
apply rint_proper.
apply rint_ord_test in H5. intuition.
elim H2.
elim H1.
Qed.
Next Obligation.
repeat intro.
unfold eimage' in H0.
destruct H0 as [n ?].
revert H0. case_eq (X n); intros.
destruct H1 as [? _]. red in H1. simpl in H1.
assert (q1 <= rint_end c).
apply Qle_trans with q2; auto.
rewrite H1. apply rint_proper.
set (r := RatInt q1 (rint_end c) H2).
assert (r ∈ X).
apply Hdown with c.
apply rint_ord_test.
split; simpl; auto.
apply Qle_trans with q2; auto.
rewrite H1; auto.
apply Qle_refl.
apply Qle_refl.
exists n. rewrite H0. auto.
destruct H3 as [n' ?].
exists n'.
unfold eimage'.
destruct (X n').
assert (q1 == rint_start c0).
destruct H3.
assert (rint_start r == rint_start c0).
apply rint_ord_test in H3.
apply rint_ord_test in H4.
apply Qle_antisym; intuition.
simpl in H5. auto.
split; red; simpl; auto.
symmetry; auto.
auto.
elim H1.
Qed.
Next Obligation.
repeat intro.
unfold eimage' in H0.
destruct H0 as [n ?].
revert H0. case_eq (X n); intros.
destruct H1 as [? _]. red in H1. simpl in H1.
assert (rint_start c <= q2).
apply Qle_trans with q1; auto.
rewrite H1. apply rint_proper.
set (r := RatInt (rint_start c) q2 H2).
assert (r ∈ X).
apply Hdown with c.
apply rint_ord_test.
split; simpl; auto.
apply Qle_refl.
apply Qle_trans with q1; auto.
rewrite H1; auto.
apply Qle_refl.
exists n. rewrite H0. auto.
destruct H3 as [n' ?].
exists n'.
unfold eimage'.
destruct (X n').
assert (q2 == rint_end c0).
destruct H3.
assert (rint_end r == rint_end c0).
apply rint_ord_test in H3.
apply rint_ord_test in H4.
apply Qle_antisym; intuition.
simpl in H5. auto.
split; red; simpl; auto.
symmetry; auto.
auto.
elim H1.
Qed.
Next Obligation.
intros.
unfold eimage'.
split; intros [x ?].
destruct H as [n ?].
revert H. case_eq (X n); intros.
exists (rint_start c).
exists n. rewrite H. auto.
elim H0.
destruct H as [n ?].
revert H. case_eq (X n); intros.
exists (rint_end c).
exists n. rewrite H. auto.
elim H0.
Qed.
Lemma rints_to_cut_upper q X Hdir Hdown :
q ∈ cut_upper (rints_to_cut X Hdir Hdown) <->
exists r, r ∈ X /\ q == rint_end r.
Proof.
simpl; intros. unfold eimage'.
split; intros.
destruct H as [n ?].
revert H. case_eq (X n); intros.
exists c. split.
exists n. rewrite H; auto.
destruct H0; auto.
elim H0.
destruct H as [r [??]].
destruct H as [n ?]. exists n.
destruct (X n); auto.
assert (rint_end r == rint_end c).
destruct H.
apply rint_ord_test in H.
apply rint_ord_test in H1.
apply Qle_antisym; intuition.
rewrite H1 in H0.
split; red; simpl; auto.
symmetry; auto.
Qed.
Lemma rints_to_cut_lower q X Hdir Hdown :
q ∈ cut_lower (rints_to_cut X Hdir Hdown) <->
exists r, r ∈ X /\ q == rint_start r.
Proof.
simpl; intros. unfold eimage'.
split; intros.
destruct H as [n ?].
revert H. case_eq (X n); intros.
exists c. split.
exists n. rewrite H; auto.
destruct H0; auto.
elim H0.
destruct H as [r [??]].
destruct H as [n ?]. exists n.
destruct (X n); auto.
assert (rint_start r == rint_start c).
destruct H.
apply rint_ord_test in H.
apply rint_ord_test in H1.
apply Qle_antisym; intuition.
rewrite H1 in H0.
split; red; simpl; auto.
symmetry; auto.
Qed.
Opaque rints_to_cut.
Parameter A:∂PLT.
Program Definition hom_to_cut (f:A → PreRealDom) : PLT.ord A → cut_preord :=
Preord.Hom (PLT.ord A) cut_preord
(fun a => rints_to_cut (erel_image _ _ (PLT.dec A) (PLT.hom_rel f) a)
(PLT.hom_directed _ _ _ f a)
_)
_.
Next Obligation.
intros.
apply erel_image_elem in H0.
apply erel_image_elem.
revert H0. apply PLT.hom_order; auto.
Qed.
Next Obligation.
simpl; intros.
assert (erel_image _ _ (PLT.dec A) (PLT.hom_rel f) a ⊆
erel_image _ _ (PLT.dec A) (PLT.hom_rel f) b).
red; simpl; intros.
apply erel_image_elem in H0.
apply erel_image_elem.
revert H0.
apply PLT.hom_order; auto.
split; red; intros.
apply rints_to_cut_upper in H1.
apply rints_to_cut_upper.
destruct H1 as [r [??]]. exists r; split; auto.
apply rints_to_cut_lower in H1.
apply rints_to_cut_lower.
destruct H1 as [r [??]]. exists r; split; auto.
Qed.
Program Definition cut_to_hom_rel (f:PLT.ord A → cut_preord) : erel A PreRealDom :=
@esubset (prod_preord A PreRealDom)
(fun ar => rint_end (snd ar) ∈ cut_upper (f (fst ar)) /\
rint_start (snd ar) ∈ cut_lower (f (fst ar)))
_
(eff_enum _ (effective_prod (PLT.effective A) (PLT.effective PreRealDom))).
Next Obligation.
intros.
apply semidec_conj.
apply semidec_in.
constructor. apply Qeq_dec.
apply semidec_in.
constructor. apply Qeq_dec.
Qed.
Lemma cut_to_hom_rel_elem (f:PLT.ord A → cut_preord) a r :
(a,r) ∈ cut_to_hom_rel f <->
(rint_end r ∈ cut_upper (f a) /\ rint_start r ∈ cut_lower (f a)).
Proof.
unfold cut_to_hom_rel.
rewrite esubset_elem. intuition.
apply eprod_elem; split; apply eff_complete.
simpl; intros.
destruct H as [[??][??]].
intuition.
cut (rint_end (snd b) ∈ cut_upper (f (fst a0))).
destruct (Preord.axiom _ _ f (fst a0) (fst b)); auto.
revert H4. apply cut_is_upper.
apply rint_ord_test in H3. intuition.
cut (rint_start (snd b) ∈ cut_lower (f (fst a0))).
destruct (Preord.axiom _ _ f (fst a0) (fst b)); auto.
revert H5. apply cut_is_lower.
apply rint_ord_test in H3. intuition.
Qed.
Program Definition cut_to_hom (f:PLT.ord A → cut_preord) : A → PreRealDom :=
PLT.Hom true A PreRealDom (cut_to_hom_rel f) _ _.
Next Obligation.
simpl; intros.
apply cut_to_hom_rel_elem in H1.
apply cut_to_hom_rel_elem.
apply rint_ord_test in H0.
intuition.
cut (rint_end y' ∈ cut_upper (f x)).
destruct (Preord.axiom _ _ f x x'); auto.
revert H0.
apply cut_is_upper; auto.
cut (rint_start y' ∈ cut_lower(f x)).
destruct (Preord.axiom _ _ f x x'); auto.
revert H4.
apply cut_is_lower; auto.
Qed.
Next Obligation.
intros f a. apply prove_directed; auto.
intros.
apply erel_image_elem in H.
apply erel_image_elem in H0.
apply cut_to_hom_rel_elem in H.
apply cut_to_hom_rel_elem in H0.
destruct H. destruct H0.
assert (Qmax (rint_start x) (rint_start y) <= Qmin (rint_end x) (rint_end y)).
apply Q.max_case.
intros. rewrite <- H3; auto.
apply Q.min_case.
intros. rewrite <- H3; auto.
eapply cut_proper; eauto.
eapply cut_proper; eauto.
apply Q.min_case.
intros. rewrite <- H3; auto.
eapply cut_proper; eauto.
eapply cut_proper; eauto.
exists (RatInt _ _ H3).
split.
apply rint_ord_test. simpl.
split. apply Q.le_max_l. apply Q.le_min_l.
split.
apply rint_ord_test. simpl.
split. apply Q.le_max_r. apply Q.le_min_r.
apply erel_image_elem.
apply cut_to_hom_rel_elem.
simpl. split.
apply Q.min_case; simpl; auto.
intros p q ?. apply member_eq.
split; red; simpl; auto. symmetry; auto.
apply Q.max_case; simpl; auto.
intros p q ?. apply member_eq.
split; red; simpl; auto. symmetry; auto.
Qed.
Lemma cut_roundtrip1 f :
cut_to_hom (hom_to_cut f) ≈ f.
Proof.
split; hnf; simpl; intros [a r] H.
apply cut_to_hom_rel_elem in H. destruct H.
simpl in *.
rewrite rints_to_cut_upper in H.
rewrite rints_to_cut_lower in H0.
destruct H as [r1 [??]].
destruct H0 as [r2 [??]].
apply erel_image_elem in H.
apply erel_image_elem in H0.
destruct (plt_hom_directed2 _ _ _ f a r1 r2) as [r' [?[??]]]; auto.
apply PLT.hom_order with a r'; auto.
apply rint_ord_test.
apply rint_ord_test in H4.
apply rint_ord_test in H5.
split.
rewrite H2; intuition.
rewrite H1; intuition.
apply cut_to_hom_rel_elem.
split; simpl.
rewrite rints_to_cut_upper.
exists r. split; auto.
apply erel_image_elem. auto. reflexivity.
rewrite rints_to_cut_lower.
exists r. split; auto.
apply erel_image_elem. auto. reflexivity.
Qed.
Lemma cut_roundtrip2 f :
hom_to_cut (cut_to_hom f) ≈ f.
Proof.
intro a. split; split; simpl; hnf; intros.
apply rints_to_cut_upper in H.
destruct H as [r [??]].
apply erel_image_elem in H.
apply cut_to_hom_rel_elem in H. destruct H.
revert H. apply member_eq.
split; red; simpl; auto. symmetry; auto.
apply rints_to_cut_lower in H.
destruct H as [r [??]].
apply erel_image_elem in H.
apply cut_to_hom_rel_elem in H. destruct H.
revert H1. apply member_eq.
split; red; simpl; auto. symmetry; auto.
apply rints_to_cut_upper.
destruct (cut_nonextended (f a)) as [? _].
destruct H0 as [z ?]; eauto.
assert (z <= a0).
eapply cut_proper; eauto.
exists (RatInt z a0 H1).
split; simpl; auto.
apply erel_image_elem.
apply cut_to_hom_rel_elem.
simpl. split; auto. reflexivity.
apply rints_to_cut_lower.
destruct (cut_nonextended (f a)) as [_ ?].
destruct H0 as [z ?]; eauto.
assert (a0 <= z).
eapply cut_proper; eauto.
exists (RatInt a0 z H1).
split; simpl; auto.
apply erel_image_elem.
apply cut_to_hom_rel_elem.
simpl. split; auto. reflexivity.
Qed.
Definition cut_canonical (x:cut) :=
(forall u, u ∈ cut_upper x -> exists u', u' ∈ cut_upper x /\ u' < u) /\
(forall l, l ∈ cut_lower x -> exists l', l' ∈ cut_lower x /\ l < l').
Definition located (x:cut) :=
forall (ε:Q), ε > 0 ->
exists u l,
u ∈ cut_upper x /\
l ∈ cut_lower x /\
u - l <= ε.
Lemma canonical_to_hom (f:PLT.ord A → cut_preord) :
(forall a, cut_canonical (f a)) ->
canonical A (cut_to_hom f).
Proof.
repeat intro.
destruct (H a).
simpl in H0.
apply cut_to_hom_rel_elem in H0. destruct H0.
destruct (H1 (rint_end x)) as [u' [??]]; auto.
destruct (H2 (rint_start x)) as [l' [??]]; auto.
assert (l' <= u').
apply cut_proper with (f a); auto.
exists (RatInt l' u' H8).
split; simpl.
apply cut_to_hom_rel_elem; split; simpl; auto.
red; split; simpl; auto.
Qed.
Lemma canonical_to_cut (f:A → PreRealDom) :
canonical A f ->
forall a, cut_canonical (hom_to_cut f a).
Proof.
repeat intro.
split; simpl; intros.
apply rints_to_cut_upper in H0.
destruct H0 as [r [??]].
apply erel_image_elem in H0.
destruct (H a r) as [r' [??]]; auto.
exists (rint_end r').
split.
apply rints_to_cut_upper.
exists r'. split.
apply erel_image_elem. auto.
reflexivity.
rewrite H1.
destruct H3; auto.
apply rints_to_cut_lower in H0.
destruct H0 as [r [??]].
apply erel_image_elem in H0.
destruct (H a r) as [r' [??]]; auto.
exists (rint_start r').
split.
apply rints_to_cut_lower.
exists r'. split.
apply erel_image_elem. auto.
reflexivity.
rewrite H1.
destruct H3; auto.
Qed.
Lemma located_converges (f:PLT.ord A → cut_preord) :
(forall a, located (f a)) ->
realdom_converges A (cut_to_hom f).
Proof.
repeat intro.
destruct (H a ε) as [u [l [?[??]]]]; auto.
assert (l <= u).
apply cut_proper with (f a); auto.
exists (RatInt l u H4). split; simpl; auto.
apply cut_to_hom_rel_elem. split; simpl; auto.
Qed.
Lemma converges_located (f:A → PreRealDom) :
realdom_converges A f ->
forall a, located (hom_to_cut f a).
Proof.
repeat intro.
destruct (H a ε) as [r [??]]; auto.
exists (rint_end r), (rint_start r); split; simpl; auto.
apply rints_to_cut_upper.
exists r; split; auto.
apply erel_image_elem. auto. reflexivity.
split.
apply rints_to_cut_lower.
exists r; split; auto.
apply erel_image_elem. auto. reflexivity.
auto.
Qed.
Lemma hom_to_cut_mono (f g:A → PreRealDom) :
f ≤ g -> hom_to_cut f ≤ hom_to_cut g.
Proof.
repeat intro.
split; red; simpl; intros.
apply rints_to_cut_upper in H0.
apply rints_to_cut_upper.
destruct H0 as [r [??]].
exists r. split; auto.
apply erel_image_elem in H0.
apply erel_image_elem.
apply H; auto.
apply rints_to_cut_lower in H0.
apply rints_to_cut_lower.
destruct H0 as [r [??]].
exists r. split; auto.
apply erel_image_elem in H0.
apply erel_image_elem.
apply H; auto.
Qed.
Lemma cut_to_hom_mono (f g:PLT.ord A → cut_preord) :
f ≤ g -> cut_to_hom f ≤ cut_to_hom g.
Proof.
repeat intro; simpl in *.
destruct a as [a r].
apply cut_to_hom_rel_elem in H0.
apply cut_to_hom_rel_elem.
destruct H0. split.
apply (H a); auto.
apply (H a); auto.
Qed.
End cuts.
Canonical Structure cut_preord.
Definition cut_lt (x y:cut) :=
exists u l,
u ∈ cut_upper x /\
l ∈ cut_lower y /\
u < l.
Module interval_limit_cuts.
Section limit.
Variable seq_upper : N -> cut.
Variable seq_lower : N -> cut.
Hypothesis seq_proper : forall n, cut_lt (seq_lower n) (seq_upper n).
Hypothesis seq_upper_inside : forall n m, (n < m)%N -> cut_lt (seq_upper m) (seq_upper n).
Hypothesis seq_lower_inside : forall n m, (n < m)%N -> cut_lt (seq_lower n) (seq_lower m).
Definition limit_upper : eset Qpreord :=
union ( (fun n => Some (cut_upper (seq_upper n))) : eset (eset Qpreord)).
Definition limit_lower : eset Qpreord :=
union ( (fun n => Some (cut_lower (seq_lower n))) : eset (eset Qpreord)).
Program Definition interval_limit : cut :=
Cut limit_upper limit_lower _ _ _ _.
Next Obligation.
unfold limit_upper, limit_lower. intros.
apply union_axiom in H.
apply union_axiom in H0.
destruct H as [XU [??]].
destruct H0 as [XL [??]].
destruct H as [n1 ?].
destruct H0 as [n2 ?].
set (o := (1 + N.max n1 n2)%N).
destruct (seq_lower_inside n2 (1 + N.max n1 n2)) as [a [b [?[??]]]].
zify. omega.
apply Qle_trans with a.
apply cut_proper with (seq_lower n2); auto.
rewrite <- H0; auto.
apply Qle_trans with b.
intuition.
destruct (seq_proper (1 + N.max n1 n2)) as [c [d [?[??]]]].
apply Qle_trans with c.
apply cut_proper with (seq_lower (1 + N.max n1 n2)); auto.
apply Qle_trans with d.
intuition.
destruct (seq_upper_inside n1 (1 + N.max n1 n2)) as [e [f [?[??]]]].
zify. omega.
apply Qle_trans with e.
apply cut_proper with (seq_upper (1 + N.max n1 n2)); auto.
apply Qle_trans with f.
intuition.
apply cut_proper with (seq_upper n1); auto.
rewrite <- H. auto.
Qed.
Next Obligation.
unfold limit_lower; intros.
apply union_axiom in H0.
destruct H0 as [X [??]].
destruct H0 as [n ?].
apply union_axiom.
exists X. split; auto.
exists n. auto.
rewrite H0. rewrite H0 in H1.
revert H1. apply cut_is_lower. auto.
Qed.
Next Obligation.
unfold limit_upper; intros.
apply union_axiom in H0.
destruct H0 as [X [??]].
destruct H0 as [n ?].
apply union_axiom.
exists X. split; auto.
exists n. auto.
rewrite H0. rewrite H0 in H1.
revert H1. apply cut_is_upper. auto.
Qed.
Next Obligation.
unfold limit_upper, limit_lower.
destruct (seq_proper 0) as [u [l [?[??]]]].
split; intros.
destruct (cut_nonextended (seq_lower 0)).
destruct H3 as [l' ?].
exists u. auto.
exists l'.
apply union_axiom.
exists (cut_lower (seq_lower 0)).
split; auto.
exists 0%N. auto.
destruct (cut_nonextended (seq_upper 0)).
destruct H4 as [u' ?].
exists l. auto.
exists u'.
apply union_axiom.
exists (cut_upper (seq_upper 0)).
split; auto.
exists 0%N. auto.
Qed.
Lemma interval_limit_inside_upper : forall n,
cut_lt interval_limit (seq_upper n).
Proof.
repeat intro. hnf.
destruct (seq_upper_inside n (n+1)) as [u' [l' [?[??]]]].
zify. omega.
exists u'. exists l'. intuition.
unfold interval_limit. simpl.
unfold limit_upper.
apply union_axiom.
exists (cut_upper (seq_upper (n+1))).
split. exists (n+1)%N. auto.
auto.
Qed.
Lemma interval_limit_inside_lower : forall n,
cut_lt (seq_lower n) interval_limit.
Proof.
repeat intro. hnf.
destruct (seq_lower_inside n (n+1)) as [u' [l' [?[??]]]].
zify. omega.
exists u'. exists l'. intuition.
unfold interval_limit. simpl.
unfold limit_upper.
apply union_axiom.
exists (cut_lower (seq_lower (n+1))).
split. exists (n+1)%N. auto.
auto.
Qed.
Lemma interval_limit_least_defined lim :
(forall n, cut_lt lim (seq_upper n)) ->
(forall n, cut_lt (seq_lower n) lim) ->
interval_limit ≤ lim.
Proof.
repeat intro. split; hnf; simpl; intros.
unfold limit_upper in H1.
apply union_axiom in H1.
destruct H1 as [X [??]].
destruct H1 as [n ?].
destruct (H n) as [u [l [?[??]]]].
rewrite H1 in H2.
apply cut_is_upper with u; auto.
apply Qle_trans with l; intuition.
apply cut_proper with (seq_upper n); auto.
unfold limit_lower in H1.
apply union_axiom in H1.
destruct H1 as [X [??]].
destruct H1 as [n ?].
destruct (H0 n) as [u [l [?[??]]]].
rewrite H1 in H2.
apply cut_is_lower with l; auto.
apply Qle_trans with u; intuition.
apply cut_proper with (seq_lower n); auto.
Qed.
Hypothesis seq_converges : forall ε, 0 < ε ->
exists n a b,
a ∈ cut_upper (seq_upper n) /\
b ∈ cut_lower (seq_lower n) /\
a - b <= ε.
Lemma interval_limit_located : located interval_limit.
Proof.
red; intros.
destruct (seq_converges ε H) as [n [a [b [?[??]]]]].
exists a. exists b. intuition.
simpl. unfold limit_upper.
apply union_axiom. exists (cut_upper (seq_upper n)).
split; auto. exists n. auto.
apply union_axiom. exists (cut_lower (seq_lower n)).
split; auto. exists n. auto.
Qed.
End limit.
End interval_limit_cuts.
Definition pow2 (n:N) : positive :=
match n with
| N0 => 1%positive
| Npos p => shift_pos p 1
end.
Lemma pow2_commute n1 n2 :
(pow2 n1 * pow2 n2 = pow2 (n1+n2))%positive.
Proof.
unfold pow2.
destruct n1; simpl; auto.
destruct n2; simpl; auto.
apply Pos.mul_1_r.
unfold shift_pos.
rewrite Pos.iter_add.
induction p using Pos.peano_ind; simpl; auto.
rewrite Pos.iter_succ. simpl.
rewrite IHp.
rewrite Pos.iter_succ. auto.
Qed.
Lemma pow2_div_eq (a b:N) :
(a <= b)%N -> (pow2 (b - a) * pow2 a = pow2 b)%positive.
Proof.
intros.
rewrite pow2_commute.
replace (b - a + a)%N with b; auto.
assert (0 <= a)%N.
hnf. simpl. destruct a; discriminate.
symmetry. apply N.sub_add; auto.
Qed.
Definition oneOver2n (n:N) : Q := (1 # pow2 n)%Q.
Lemma oneOver2n_pos n : 0 < oneOver2n n.
Proof.
unfold oneOver2n. intuition.
Qed.
Lemma oneOver2n_commute n1 n2 :
(oneOver2n n1 * oneOver2n n2 == oneOver2n (n1+n2))%Q.
Proof.
unfold oneOver2n.
red. simpl. symmetry.
f_equal. apply pow2_commute.
Qed.
Lemma oneOver2n_div_eq a b :
(a <= b)%N -> (oneOver2n (b - a) * oneOver2n a == oneOver2n b)%Q.
Proof.
intro.
unfold oneOver2n.
red. simpl. symmetry.
f_equal. apply pow2_div_eq. auto.
Qed.
Lemma pow2_ge1 (a:N) :
(1 <= pow2 a)%positive.
Proof.
induction a using N.peano_ind.
simpl. reflexivity.
replace (N.succ a) with (1+a)%N.
2: zify; omega.
rewrite <- pow2_commute.
simpl pow2 at 1. unfold shift_pos. simpl Pos.iter.
zify. omega.
Qed.
Lemma pow2_mono (a b:N) :
(a <= b)%N -> (pow2 a <= pow2 b)%positive.
Proof.
revert b. induction a using N.peano_ind.
simpl; intros.
apply pow2_ge1.
intro b. induction b using N.peano_ind.
intros.
elimtype False. zify. omega.
intros.
replace (N.succ a) with (1+a)%N.
replace (N.succ b) with (1+b)%N.
2: zify; omega.
2: zify; omega.
rewrite <- pow2_commute.
rewrite <- pow2_commute.
cut (pow2 a <= pow2 b)%positive.
simpl. zify. omega.
apply IHa. zify. omega.
Qed.
Lemma oneOver2n_subsumes (a b c:N) :
(a < b)%N -> (a < c)%N ->
oneOver2n b + oneOver2n c <= oneOver2n a.
Proof.
intros. unfold oneOver2n.
red. simpl.
cut ((pow2 c + pow2 b) * pow2 a <= (pow2 b * pow2 c))%positive. auto.
rewrite pow2_commute.
rewrite Pos.mul_add_distr_r.
rewrite pow2_commute.
rewrite pow2_commute.
replace (b + c)%N with (1 + (b+c-1))%N by (zify; omega).
rewrite <- (pow2_commute 1).
simpl pow2 at 3. unfold shift_pos. simpl Pos.iter.
replace 2%positive with (1 + 1)%positive.
rewrite Pos.mul_add_distr_r.
simpl.
apply Pos.add_le_mono.
apply pow2_mono.
zify. omega.
apply pow2_mono.
zify. omega.
zify. omega.
Qed.
Fixpoint pos_log2 (p:positive) : N :=
match p with
| xH => 1%N
| xO p' => N.succ (pos_log2 p')
| xI p' => N.succ (pos_log2 p')
end.
Lemma pow2_succ (n:N) : (pow2 (N.succ n) = (pow2 n)~0)%positive.
Proof.
destruct n.
compute. auto.
simpl.
unfold shift_pos. simpl.
rewrite Pos.iter_succ.
auto.
Qed.
Lemma pow2_pos_log2 (p:positive) : (p < pow2 (pos_log2 p))%positive.
Proof.
red. unfold Pos.compare.
generalize Eq.
induction p.
simpl; intros.
rewrite pow2_succ.
simpl. apply IHp.
simpl; intros.
rewrite pow2_succ.
simpl. apply IHp.
simpl. auto.
Qed.
Lemma oneOver2n_small : forall ε:Q, 0 < ε -> exists n, oneOver2n n <= ε.
Proof.
intros.
exists (pos_log2 (Qden ε)).
destruct ε.
red in H. simpl in H.
ring_simplify in H.
simpl.
red; simpl.
apply Z.le_trans with (1 * 'Qden)%Z.
simpl. reflexivity.
apply Zmult_le_compat.
omega.
cut ( Qden < pow2 (pos_log2 Qden))%positive.
zify. omega.
apply pow2_pos_log2.
omega.
compute. discriminate.
Qed.
Module cauchy_limit_cuts.
Program Definition widen_cut (n:N) (x:cut) : cut :=
Cut (image (Preord.Hom _ _ (Qplus (oneOver2n n)) _) (cut_upper x))
(image (Preord.Hom _ _ (Qplus (- oneOver2n n)) _) (cut_lower x))
_ _ _ _.
Next Obligation.
intros. red in H. simpl in H.
red. simpl. rewrite H. reflexivity.
Qed.
Next Obligation.
intros. red in H. simpl in H.
red. simpl. rewrite H. reflexivity.
Qed.
Next Obligation.
simpl; intros.
apply image_axiom2 in H.
apply image_axiom2 in H0.
destruct H as [q1 [??]].
destruct H0 as [q2 [??]].
simpl in *.
destruct H1. red in H1. simpl in H1.
destruct H2. red in H2. simpl in H2.
rewrite H2. rewrite H1.
apply Qle_trans with (0 + q2)%Q.
apply Qplus_le_compat.
rewrite <- (Qplus_le_l _ _ (oneOver2n n)).
ring_simplify.
apply Qlt_le_weak.
apply oneOver2n_pos.
apply Qle_refl.
apply Qle_trans with (0 + q1)%Q.
apply Qplus_le_compat; auto.
apply Qle_refl.
apply cut_proper with x; auto.
apply Qplus_le_compat.
apply Qlt_le_weak.
apply oneOver2n_pos.
apply Qle_refl.
Qed.
Next Obligation.
intros.
apply image_axiom2 in H0.
destruct H0 as [y [??]]. simpl in *.
apply image_axiom1'.
exists (q1 + oneOver2n n)%Q.
split. simpl.
split; red; simpl; ring.
eapply cut_is_lower; eauto.
destruct H1. red in H1. simpl in H1.
rewrite <- (Qplus_le_l _ _ (-oneOver2n n)).
ring_simplify.
apply Qle_trans with q2; auto.
rewrite H1.
ring_simplify. apply Qle_refl.
Qed.
Next Obligation.
intros.
apply image_axiom2 in H0.
destruct H0 as [y [??]]. simpl in *.
apply image_axiom1'.
exists (q2 - oneOver2n n)%Q.
split. simpl.
split; red; simpl; ring.
eapply cut_is_upper; eauto.
destruct H1. red in H1. simpl in H1.
rewrite <- (Qplus_le_l _ _ (oneOver2n n)).
ring_simplify.
apply Qle_trans with q1; auto.
rewrite H1.
ring_simplify. apply Qle_refl.
Qed.
Next Obligation.
intros. split; intros [q ?].
apply image_axiom2 in H.
destruct H as [y [??]]; simpl in *.
destruct (cut_nonextended x).
destruct H1 as [z ?]; eauto.
exists (- oneOver2n n + z)%Q.
apply image_axiom1'. exists z. split; auto.
apply image_axiom2 in H.
destruct H as [y [??]]; simpl in *.
destruct (cut_nonextended x).
destruct H2 as [z ?]; eauto.
exists (oneOver2n n + z)%Q.
apply image_axiom1'. exists z. split; auto.
Qed.
Definition near ε (x y:cut) :=
(exists u l, u ∈ cut_upper x /\ l ∈ cut_lower y /\ u - l <= ε) /\
(exists u l, u ∈ cut_upper y /\ l ∈ cut_lower x /\ u - l <= ε).
Definition is_limit (seq:N -> cut) (c:cut) :=
forall ε:Q, ε > 0 ->
exists m:N, forall (n:N), (m <= n)%N -> near ε (seq n) c.
Lemma is_limit_located seq lim : is_limit seq lim -> located lim.
Proof.
red; intros.
destruct (H (ε/(2#1))); auto.
apply Qlt_shift_div_l.
compute. auto.