-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathrealfun.v
More file actions
3555 lines (3290 loc) · 150 KB
/
realfun.v
File metadata and controls
3555 lines (3290 loc) · 150 KB
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
(* mathcomp analysis (c) 2025 Inria and AIST. License: CeCILL-C. *)
From HB Require Import structures.
From mathcomp Require Import all_ssreflect finmap ssralg ssrnum ssrint.
From mathcomp Require Import archimedean interval.
From mathcomp Require Import mathcomp_extra boolp classical_sets functions.
From mathcomp Require Import cardinality contra ereal reals interval_inference.
From mathcomp Require Import topology prodnormedzmodule tvs normedtype derive.
From mathcomp Require Import sequences real_interval.
(**md**************************************************************************)
(* # Real-valued functions over reals *)
(* *)
(* This file provides properties of standard real-valued functions over real *)
(* numbers (e.g., the continuity of the inverse of a continuous function, *)
(* L'Hopital's rule). *)
(* *)
(* ``` *)
(* nondecreasing_fun f == the function f is non-decreasing *)
(* nonincreasing_fun f == the function f is non-increasing *)
(* increasing_fun f == the function f is (strictly) increasing *)
(* decreasing_fun f == the function f is (strictly) decreasing *)
(* *)
(* derivable_oo_LRcontinuous f x y == f is derivable in `]x, y[ and *)
(* continuous up to the boundary, i.e., *)
(* f @ x^'+ --> f x and f @ y^'- --> f y *)
(* derivable_oy_Rcontinuous f x == f is derivable in `]x, +oo[ and *)
(* f @ x^'+ --> f x *)
(* derivable_Nyo_Lcontinuous f x == f is derivable in `]-oo, x[ and *)
(* f @ x^'- --> f x *)
(* *)
(* itv_partition a b s == s is a partition of the interval `[a, b] *)
(* itv_partitionL s c == the left side of splitting a partition at c *)
(* itv_partitionR s c == the right side of splitting a partition at c *)
(* variation a b f s == the sum of f at all points in the partition s *)
(* variations a b f == the set of all variations of f between a and b *)
(* bounded_variation a b f == all variations of f are bounded *)
(* total_variation a b f == the sup over all variations of f from a to b *)
(* neg_tv a f x == the decreasing component of f *)
(* pos_tv a f x == the increasing component of f *)
(* ``` *)
(* *)
(* Limit superior and inferior for functions: *)
(* ``` *)
(* lime_sup f a/lime_inf f a == limit sup/inferior of the extended real- *)
(* valued function f at point a *)
(* ``` *)
(* *)
(* Discontinuities: *)
(* ``` *)
(* discontinuity f r == r is a discontinuity of function f *)
(* ``` *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import Order.TTheory GRing.Theory Num.Def Num.Theory.
Local Open Scope classical_set_scope.
Local Open Scope ring_scope.
Import numFieldNormedType.Exports.
Notation "'nondecreasing_fun' f" := ({homo f : n m / (n <= m)%O >-> (n <= m)%O})
(at level 10).
Notation "'nonincreasing_fun' f" := ({homo f : n m / (n <= m)%O >-> (n >= m)%O})
(at level 10).
Notation "'increasing_fun' f" := ({mono f : n m / (n <= m)%O >-> (n <= m)%O})
(at level 10).
Notation "'decreasing_fun' f" := ({mono f : n m / (n <= m)%O >-> (n >= m)%O})
(at level 10).
Lemma nondecreasing_funN {R : realType} a b (f : R -> R) :
{in `[a, b] &, nondecreasing_fun f} <->
{in `[a, b] &, nonincreasing_fun (\- f)}.
Proof.
split=> [h m n mab nab mn|h m n mab nab mn]; first by rewrite lerNr opprK h.
by rewrite -(opprK (f n)) -lerNr h.
Qed.
Lemma nonincreasing_funN {R : realType} a b (f : R -> R) :
{in `[a, b] &, nonincreasing_fun f} <->
{in `[a, b] &, nondecreasing_fun (\- f)}.
Proof.
apply: iff_sym; apply: (iff_trans (nondecreasing_funN a b (\- f))).
rewrite [in X in _ <-> X](_ : f = \- (\- f))//.
by apply/funext => x /=; rewrite opprK.
Qed.
Section fun_cvg.
Section fun_cvg_realFieldType.
Context {R : realFieldType}.
(* NB: see cvg_addnl in topology.v *)
Lemma cvg_addrl (M : R) : M + r @[r --> +oo] --> +oo.
Proof.
move=> P [r [rreal rP]]; exists (r - M); split.
by rewrite realB// num_real.
by move=> m; rewrite ltrBlDl => /rP.
Qed.
(* NB: see cvg_addnr in topology.v *)
Lemma cvg_addrr (M : R) : (r + M) @[r --> +oo] --> +oo.
Proof. by under [X in X @ _]funext => n do rewrite addrC; exact: cvg_addrl. Qed.
Lemma cvg_addrr_Ny (M : R) : r + M @[r --> -oo] --> -oo.
Proof.
move=> P [r [rreal rP]]; exists (r - M); split.
by rewrite realB// num_real.
by move=> m/=; rewrite ltrBrDr => /rP.
Qed.
Lemma cvg_addrl_Ny (M : R) : M + r @[r --> -oo] --> -oo.
Proof. by under eq_fun do rewrite addrC; exact: cvg_addrr_Ny. Qed.
(* NB: see cvg_centern in sequences.v *)
Lemma cvg_centerr (M : R) (T : topologicalType) (f : R -> T) (l : T) :
(f (n - M) @[n --> +oo] --> l) = (f r @[r --> +oo] --> l).
Proof.
rewrite propeqE; split; last by apply: cvg_comp; exact: cvg_addrr.
gen have cD : f l / f r @[r --> +oo] --> l -> f (n + M) @[n --> +oo] --> l.
by apply: cvg_comp; exact: cvg_addrr.
move=> /cD /=.
by under [X in X @ _ --> l]funext => n do rewrite addrK.
Qed.
(* NB: see cvg_shiftn in sequence.v *)
Lemma cvg_shiftr (M : R) (T : topologicalType) (f : R -> T) (l : T) :
(f (n + M) @[n --> +oo]--> l) = (f r @[r --> +oo] --> l).
Proof.
rewrite propeqE; split; last by apply: cvg_comp; exact: cvg_addrr.
rewrite -[X in X -> _](cvg_centerr M); apply: cvg_trans => /=.
apply: near_eq_cvg; near do rewrite subrK; exists M.
by rewrite num_real.
Unshelve. all: by end_near. Qed.
Lemma left_right_continuousP {T : topologicalType} (f : R -> T) x :
f @ x^'- --> f x /\ f @ x^'+ --> f x <-> f @ x --> f x.
Proof.
split; last by move=> cts; split; exact: cvg_within_filter.
move=> [+ +] U /= Uz => /(_ U Uz) + /(_ U Uz); near_simpl.
rewrite !near_withinE => lf rf; apply: filter_app lf; apply: filter_app rf.
near=> t => xlt xgt; have := @real_leVge R x t; rewrite !num_real.
move=> /(_ isT isT) /orP; rewrite !le_eqVlt => -[|] /predU1P[|//].
- by move=> <-; exact: nbhs_singleton.
- by move=> ->; exact: nbhs_singleton.
Unshelve. all: by end_near. Qed.
Lemma cvg_at_right_left_dnbhs (f : R -> R) (p : R) (l : R) :
f x @[x --> p^'+] --> l -> f x @[x --> p^'-] --> l ->
f x @[x --> p^'] --> l.
Proof.
move=> /cvgrPdist_le fppl /cvgrPdist_le fpnl; apply/cvgrPdist_le => e e0.
have {fppl}[a /= a0 fppl] := fppl _ e0; have {fpnl}[b /= b0 fpnl] := fpnl _ e0.
near=> t.
have : t != p by near: t; exact: nbhs_dnbhs_neq.
rewrite neq_lt => /orP[tp|pt].
- apply: fpnl => //=; near: t.
exists (b / 2) => //=; first by rewrite divr_gt0.
move=> z/= + _ => /lt_le_trans; apply.
by rewrite ler_pdivrMr// ler_pMr// ler1n.
- apply: fppl =>//=; near: t.
exists (a / 2) => //=; first by rewrite divr_gt0.
move=> z/= + _ => /lt_le_trans; apply.
by rewrite ler_pdivrMr// ler_pMr// ler1n.
Unshelve. all: by end_near. Qed.
End fun_cvg_realFieldType.
Section cvgr_fun_cvg_seq.
Context {R : realType}.
Implicit Types (f : R -> R) (p l : R).
Lemma cvg_at_rightP f p l : f x @[x --> p^'+] --> l <->
(forall u : R^nat, (forall n, u n > p) /\ (u n @[n --> \oo] --> p) ->
f (u n) @[n --> \oo] --> l).
Proof.
split=> [/cvgrPdist_le fpl u [up /cvgrPdist_lt ucvg]|pfl].
apply/cvgrPdist_le => e e0.
have [r /= r0 {}fpl] := fpl _ e0; have [s /= s0 {}ucvg] := ucvg _ r0.
near=> t; apply: fpl => //=; apply: ucvg => /=.
by near: t; exists s.
apply: contrapT => fpl; move: pfl; apply/existsNP.
suff: exists2 x : R ^nat,
(forall k, x k > p) /\ x n @[n --> \oo] --> p & ~ f (x n) @[n --> \oo] --> l.
by move=> [x_] h; exists x_; exact/not_implyP.
have [e He] : exists e : {posnum R}, forall d : {posnum R},
exists xn : R, [/\ xn > p, `|xn - p| < d%:num & `|f xn - l| >= e%:num].
apply: contrapT; apply: contra_not fpl => /forallNP h.
apply/cvgrPdist_le => e e0; have /existsNP[d] := h (PosNum e0).
move/forallNP => {}h; near=> t.
have /not_and3P[abs|abs|/negP] := h t.
- by exfalso; apply: abs; near: t; exact: nbhs_right_gt.
- exfalso; apply: abs.
by near: t; by exists d%:num => //= z/=; rewrite distrC.
- by rewrite -ltNge distrC => /ltW.
have invn n : 0 < n.+1%:R^-1 :> R by rewrite invr_gt0.
exists (fun n => sval (cid (He (PosNum (invn n))))).
split => [k|]; first by rewrite /sval/=; case: cid => x [].
apply/cvgrPdist_lt => r r0; near=> t.
rewrite /sval/=; case: cid => x [px xpt _].
rewrite distrC (lt_le_trans xpt)// -(@invrK _ r) lef_pV2 ?posrE ?invr_gt0//.
near: t; exists (truncn r^-1) => // s /= rs.
by rewrite (le_trans (ltW (truncnS_gt _)))// ler_nat.
move=> /cvgrPdist_lt/(_ e%:num (ltac:(by [])))[] n _ /(_ _ (leqnn _)).
rewrite /sval/=; case: cid => // x [px xpn].
by rewrite leNgt distrC => /negP.
Unshelve. all: by end_near. Qed.
Lemma cvg_at_leftP f p l : f x @[x --> p^'-] --> l <->
(forall u : R^nat, (forall n, u n < p) /\ u n @[n --> \oo] --> p ->
f (u n) @[n --> \oo] --> l).
Proof.
apply: (iff_trans (cvg_at_leftNP f p l)).
apply: (iff_trans (cvg_at_rightP _ _ _)).
split=> [pfl u [pu up]|pfl u [pu up]].
rewrite -(opprK u); apply: pfl.
by split; [move=> k; rewrite ltrNr opprK//|exact/cvgNP].
apply: pfl.
by split; [move=> k; rewrite ltrNl//|apply/cvgNP => /=; rewrite opprK].
Qed.
Lemma cvgr_dnbhsP f p l : f x @[x --> p^'] --> l <->
(forall u : R^nat, (forall n, u n != p) /\ (u n @[n --> \oo] --> p) ->
f (u n) @[n --> \oo] --> l).
Proof.
split=> [/cvgrPdist_le fpl u [up /cvgrPdist_lt put]|pfl].
apply/cvgrPdist_le => e /fpl [r /=] /put[n _ {}put] {}fpl.
near=> t; apply: fpl => //=; apply: put.
by near: t; exact: nbhs_infty_ge.
apply: cvg_at_right_left_dnbhs.
- by apply/cvg_at_rightP => u [pu ?]; apply: pfl; split => // n; rewrite gt_eqF.
- by apply/cvg_at_leftP => u [pu ?]; apply: pfl; split => // n; rewrite lt_eqF.
Unshelve. all: end_near. Qed.
Lemma cvg_nbhsP f p l : f x @[x --> p] --> l <->
(forall u : R^nat, (u n @[n --> \oo] --> p) -> f (u n) @[n --> \oo] --> l).
Proof.
split=> [/cvgrPdist_le /= fpl u /cvgrPdist_lt /= uyp|pfl].
apply/cvgrPdist_le => e /fpl[d d0 pdf].
by apply: filterS (uyp d d0) => t /pdf.
apply: contrapT => fpl; move: pfl; apply/existsNP.
suff: exists2 x : R ^nat,
x n @[n --> \oo] --> p & ~ f (x n) @[n --> \oo] --> l.
by move=> [x_] hp; exists x_; exact/not_implyP.
have [e He] : exists e : {posnum R}, forall d : {posnum R},
exists xn, `|xn - p| < d%:num /\ `|f xn - l| >= e%:num.
apply: contrapT; apply: contra_not fpl => /forallNP h.
apply/cvgrPdist_le => e e0; have /existsNP[d] := h (PosNum e0).
move/forallNP => {}h; near=> t.
have /not_andP[abs|/negP] := h t.
- exfalso; apply: abs.
by near: t; exists d%:num => //= z/=; rewrite distrC.
- by rewrite -ltNge distrC => /ltW.
have invn n : 0 < n.+1%:R^-1 :> R by rewrite invr_gt0.
exists (fun n => sval (cid (He (PosNum (invn n))))).
apply/cvgrPdist_lt => r r0; near=> t.
rewrite /sval/=; case: cid => x [xpt _].
rewrite distrC (lt_le_trans xpt)// -[leRHS]invrK lef_pV2 ?posrE ?invr_gt0//.
near: t; exists (truncn r^-1) => // s /= rs.
by rewrite (le_trans (ltW (truncnS_gt _)))// ler_nat.
move=> /cvgrPdist_lt/(_ e%:num (ltac:(by [])))[] n _ /(_ _ (leqnn _)).
rewrite /sval/=; case: cid => // x [px xpn].
by rewrite ltNge distrC => /negP.
Unshelve. all: end_near. Qed.
End cvgr_fun_cvg_seq.
Section heine_cantorR.
Context {R : realType}.
Let within_continuous_unif_contra a b (f : R -> R) : a < b ->
{within `[a, b], continuous f} ->
~ @unif_continuous (subspace `[a, b]) R f ->
exists2 e : R, e > 0 &
forall d : R, d > 0 -> exists x : R * R, [/\ x.1 \in `]a, b[,
x.2 \in `]a, b[, `|x.1 - x.2| < d & `|f x.1 - f x.2| >= e].
Proof.
move=> ab /continuous_within_itvP => /(_ ab)[cf fa fb].
move/unif_continuousP => /= /existsNP[e /not_implyP[e0 /forall2NP ucf]].
exists (e / 3); [by rewrite divr_gt0|move=> d d0].
have [//|{ucf}] := ucf d.
move/existsNP => -[[x y] /= /not_implyP][xdy efxfy].
wlog xy : x y xdy efxfy / x < y.
move=> wlg; have [xy|xy|xy]:= ltgtP x y.
- exact: (wlg x y).
- by apply: (wlg y x) => //; [exact/ball_sym|move/ball_sym].
- by move: efxfy; rewrite -xy /ball/= subrr normr0 e0.
have [|xab] := boolP (x \in `[a, b]%classic); last first.
move: xdy; rewrite /ball/= /subspace_ball (negPf xab) /= => yx.
by move: efxfy; rewrite yx /ball/= subrr normr0 e0.
rewrite inE/= in_itv/= => /andP[ax xb].
have [|yab] := boolP (y \in `[a, b]%classic); last first.
move: xdy; rewrite /ball/= /subspace_ball mem_setE in_itv/= ax xb/=.
by move: yab; rewrite mem_setE/= => /negbTE -> [].
rewrite inE/= in_itv/= => /andP[ay yb].
move: ax; rewrite le_eqVlt => /predU1P[xa|xa].
- move: xy xdy efxfy; rewrite -{}xa => {}ay ady efafy {xb x}.
have [r [s [ar rs sy ers]]] : exists r, exists s,
[/\ a < r, r < s, s < y & e / 3 <= `|f r - f s| ].
near a^'+ => a0; exists a0.
near y^'- => y0; exists y0; split => //.
move/negP: efafy; rewrite -leNgt [in X in X -> _](split3r e) -addrA.
rewrite -lerBrDr => /le_trans; apply; rewrite lerBlDl.
rewrite -(subrKA (f a0)) (le_trans (ler_normD _ _))// -addrA lerD//.
near: a0.
by move/cvgrPdist_le : fa => /(_ (e / 3) ltac:(by rewrite divr_gt0)).
rewrite distrC -(subrKA (f y0)) (le_trans (ler_normD _ _))// lerD//.
near: y0.
move: yb; rewrite le_eqVlt => /predU1P[->|yb].
by move/cvgrPdist_le : fb => /(_ (e / 3) ltac:(by rewrite divr_gt0)).
have : f x @[x --> (y : R)] --> f y by apply: cf; rewrite in_itv/= ay.
move/left_right_continuousP => -[fy _].
by move/cvgrPdist_le : fy => /(_ (e / 3) ltac:(by rewrite divr_gt0)).
by rewrite distrC.
exists (r, s); split => //=.
+ by rewrite in_itv/= ar/= (lt_trans rs)// (lt_le_trans sy).
+ by rewrite !in_itv/= (lt_trans ar)// (lt_le_trans sy).
+ move: ady; rewrite /ball/= /subspace_ball/= mem_setE in_itv/=.
rewrite lexx (ltW ab)/= => -[_]; apply: le_lt_trans.
do 2 rewrite ltr0_norm ?subr_lt0// opprB.
by rewrite (lerB (ltW sy))// ltW.
- have {}ay : a < y by rewrite (lt_trans xa).
have {}xb : x < b by rewrite (lt_le_trans xy).
move: yb; rewrite le_eqVlt => /predU1P[{}yb|{}yb].
+ move: xdy efxfy xy; rewrite {}yb => xdb efxfb {}xb {y ay}.
have {}yab : x \in `]a, b[ by rewrite in_itv/= xa xb.
near b^'- => b0.
exists (x, b0); split => //=.
* by rewrite in_itv/=; apply/andP; split.
* move: xdb.
rewrite /ball/= /subspace_ball/= mem_setE in_itv/= (ltW xa) (ltW xb)/=.
move=> -[_]; apply: le_lt_trans.
do 2 rewrite ltr0_norm ?subr_lt0//.
by rewrite lerN2 lerD2l lerN2.
* move: efxfb => /negP; rewrite -leNgt.
rewrite [in X in X -> _](split3r e) -addrA -lerBrDr => /le_trans; apply.
rewrite lerBlDl -{1}(subrKA (f b0)) (le_trans (ler_normD _ _))//.
rewrite addrC lerD2r -mulr2n -mulr_natl distrC.
near: b0.
move/cvgrPdist_le : fb => /(_ (2 * (e / 3)) ltac:(rewrite !mulr_gt0)).
exact.
+ exists (x, y); split => /=.
* by rewrite in_itv/= xa xb.
* by rewrite in_itv/= ay yb.
* move: xdy; rewrite /ball/= /subspace_ball/=.
by rewrite mem_setE/= in_itv/= (ltW xa) (ltW xb)/= => -[].
* move: efxfy => /negP; rewrite -leNgt; apply: le_trans.
by rewrite ler_piMr ?invf_le1 ?ler1n// ltW.
Unshelve. all: by end_near. Qed.
Lemma within_continuous_unif a b (f : R -> R) :
{within `[a, b], continuous f} -> @unif_continuous (subspace `[a, b]) R f.
Proof.
have [ab|] := ltP a b; last first.
rewrite le_eqVlt => /predU1P[-> _|ba _].
by rewrite set_itv1; exact: unif_continuous_set1.
by rewrite set_itv_ge ?bnd_simp -?ltNge//; exact: unif_continuous_set0.
move=> cf; apply: contrapT => ucf.
have [e e0 de] := within_continuous_unif_contra ab cf ucf.
move: cf => /continuous_within_itvP => /(_ ab)[cf fa fb].
rewrite {ucf}.
have n0 n : 0 < n.+1%:R^-1 :> R by rewrite invr_gt0.
pose u_ n := (sval (cid (de _ (n0 n)))).1.
pose v_ n := (sval (cid (de _ (n0 n)))).2.
have u_ab n : u_ n \in `]a, b[ by have [] := svalP (cid (de n.+1%:R^-1 (n0 n))).
have v_ab n : v_ n \in `]a, b[ by have [] := svalP (cid (de n.+1%:R^-1 (n0 n))).
have u_v n : `|u_ n - v_ n| < n.+1%:R^-1.
by have [] := svalP (cid (de n.+1%:R^-1 (n0 n))).
have /bolzano_weierstrass[g incrg /cvg_ex[/= l u_gl]] : bounded_fun u_.
apply: (@itv_bounded_fun _ _ false true a b) => n.
by rewrite /u_/=; case: cid => // -[x y] /= [].
have lab : `[a, b]%classic l.
apply: (closed_cvg _ _ _ _ u_gl); first exact: itv_closed.
by apply/nearW => n /=; apply: subset_itv_oo_cc; exact: u_ab.
have v_gl : v_ \o g @ \oo --> l.
apply/cvgrPdist_le => /= r r0.
have r20 : 0 < r / 2 by rewrite divr_gt0.
have {}invrg n : (n <= (g n).+1)%N.
elim: n => // n ih; rewrite (leq_ltn_trans ih)// ltnS.
by move/increasing_seqP : incrg; exact.
near=> n.
rewrite -(subrKA (u_ (g n))) (splitr r) (le_trans (ler_normD _ _))// lerD//.
by near: n; move/cvgrPdist_le : u_gl; exact.
rewrite ltW// (@lt_trans _ _ (g n).+1%:R^-1)// invf_plt ?posrE//.
rewrite (@lt_le_trans _ _ n%:R) ?ler_nat//.
by near: n; exact: nbhs_infty_gtr.
have e20 : 0 < e / 2 by rewrite divr_gt0.
have efufv n : e <= `|f (u_ n) - f (v_ n)|.
by have [] := svalP (cid (de n.+1%:R^-1 (n0 n))).
have [la {lab} | lb {lab} | {}lab] : [\/ l = a, l = b | `]a, b[%classic l].
move: lab; rewrite -(@setU1itv _ _ _ a) ?bnd_simp; last exact/ltW.
by rewrite -(@setUitv1 _ _ _ b) ?bnd_simp// /setU/= (orC _ (l = b)) or3E.
- rewrite {}la {l} in u_gl v_gl *.
have /cvgrPdist_lt /(_ _ e20) fu_a : (f \o u_ \o g) @ \oo --> f a.
move/cvg_at_rightP : fa; apply; split => // n.
by move/itvP : (u_ab (g n)) => ->.
have /cvgrPdist_lt /(_ _ e20) fv_a : (f \o v_ \o g) @ \oo --> f a.
move/cvg_at_rightP : fa; apply; split => // n.
by move/itvP : (v_ab (g n)) => ->.
near \oo => n.
have := efufv (g n); rewrite leNgt => /negP; apply.
rewrite (splitr e) -(subrKA (f a)) (le_lt_trans (ler_normD _ _))// ltrD//.
by rewrite distrC; near: n.
by near: n.
- rewrite {}lb {l} in u_gl v_gl *.
have /cvgrPdist_lt /(_ _ e20) fu_b : (f \o u_ \o g) @ \oo --> f b.
move/cvg_at_leftP : fb; apply; split => // n.
by move/itvP : (u_ab (g n)) => ->.
have /cvgrPdist_lt /(_ _ e20) fv_b : (f \o v_ \o g) @ \oo --> f b.
move/cvg_at_leftP : fb; apply; split => // n.
by move/itvP: (v_ab (g n)) => ->.
near \oo => n.
have := efufv (g n); rewrite leNgt => /negP; apply.
rewrite (splitr e) -(subrKA (f b)) (le_lt_trans (ler_normD _ _))// ltrD//.
by rewrite distrC; near: n.
by near: n.
- have /cvgrPdist_lt /(_ _ e20) fu_l : (f \o u_ \o g) @ \oo --> f l.
exact: (continuous_cvg _ (cf _ _)).
have /cvgrPdist_lt /(_ _ e20) fv_l : (f \o v_ \o g) @ \oo --> f l.
exact: (continuous_cvg _ (cf _ _)).
near \oo => n.
have := efufv (g n); rewrite leNgt => /negP; apply.
rewrite -(subrKA (f l)) (splitr e) (le_lt_trans (ler_normD _ _))// ltrD//.
by rewrite distrC; near: n.
by near: n.
Unshelve. all: by end_near. Qed.
End heine_cantorR.
Section cvge_fun_cvg_seq.
Context {R : realType}.
Lemma cvge_at_rightP (f : R -> \bar R) (p l : R) :
f x @[x --> p^'+] --> l%:E <->
(forall u : R^nat, (forall n, u n > p) /\ u n @[n --> \oo] --> p ->
f (u n) @[n --> \oo] --> l%:E).
Proof.
split=> [/fine_cvgP [ffin_num fpl] u [pu up]|h].
apply/fine_cvgP; split; last by move/cvg_at_rightP : fpl; exact.
have [e /= e0 {}ffin_num] := ffin_num.
move/cvgrPdist_lt : up => /(_ _ e0)[s /= s0 {}up]; near=> t.
by apply: ffin_num => //=; apply: up => /=; near: t; exists s.
suff H : \forall F \near p^'+, f F \is a fin_num.
by apply/fine_cvgP; split => //; apply/cvg_at_rightP => u /h /fine_cvgP[].
apply: contrapT => /not_near_at_rightP abs.
have invn n : 0 < n.+1%:R^-1 :> R by rewrite invr_gt0.
pose y_ n := sval (cid2 (abs (PosNum (invn n)))).
have py_ k : p < y_ k by rewrite /y_ /sval/=; case: cid2 => //= x /andP[].
have y_p : y_ n @[n --> \oo] --> p.
apply/cvgrPdist_lt => e e0; near=> t.
rewrite ltr0_norm// ?subr_lt0// opprB.
rewrite /y_ /sval/=; case: cid2 => //= x /andP[_ + _].
rewrite -ltrBlDl => /lt_le_trans; apply.
rewrite -(invrK e) lef_pV2// ?posrE ?invr_gt0//.
near: t; exists (truncn e^-1) => // s /= es.
by rewrite (le_trans (ltW (truncnS_gt _)))// ler_nat.
have /fine_cvgP[[m _ mfy_] /= _] := h _ (conj py_ y_p).
near \oo => n.
have mn : (m <= n)%N by near: n; exists m.
have {mn} := mfy_ _ mn.
by rewrite /y_ /sval; case: cid2 => /= x _.
Unshelve. all: by end_near. Qed.
Lemma cvge_at_leftP (f : R -> \bar R) (p l : R) :
f x @[x --> p^'-] --> l%:E <->
(forall u : R^nat, (forall n, u n < p) /\ u n @[n --> \oo] --> p ->
f (u n) @[n --> \oo] --> l%:E).
Proof.
apply: (iff_trans (cvg_at_leftNP f p l%:E)).
apply: (iff_trans (cvge_at_rightP _ _ l)); split=> h u [up pu].
- rewrite (_ : u = \- (\- u))%R; last by apply/funext => ?/=; rewrite opprK.
by apply: h; split; [by move=> n; rewrite ltrNl opprK|exact: cvgN].
- by apply: h; split => [n|]; [rewrite ltrNl|move/cvgN : pu; rewrite opprK].
Qed.
End cvge_fun_cvg_seq.
Section cvgr_fun_dvg_seq.
Context {R : realType}.
Lemma cvg_pinftyP (f : R -> R) (l : R) :
f x @[x --> +oo] --> l <->
forall u : R^nat, (u n @[n --> \oo] --> +oo) -> f (u n) @[n --> \oo] --> l.
Proof.
split; first by move=> ? ? /cvg_comp; exact.
apply: contraPP => noncvg_f; apply/existsNP.
under eq_exists do rewrite not_implyE; apply/exists2P.
suff [e e_sep] : exists e : {posnum R},
forall A, exists2 un, A < un & e%:num <= `|f un - l|.
exists (fun n => sval (cid2 (e_sep n%:R))).
apply/cvgryPgt => A; near=> n; case: cid2 => //= r nr _.
by rewrite (le_lt_trans _ nr)//; near: n; exact: nbhs_infty_ger.
apply/cvgrPdistC_lt => /= /(_ e%:num ltac:(by []))[N _ /(_ _ (leqnn N))].
by case: cid2 => uN/= _ /le_lt_trans /[apply]; rewrite ltxx.
move: noncvg_f => /cvgrPdistC_lt /=; rewrite -existsPNP => -[eps eps_gt0].
move=> /not_near_inftyP eps_sep; exists (PosNum eps_gt0) => A /=.
have [x x_ltA /negP fxleps] := eps_sep _ (num_real A).
by exists x => //; rewrite leNgt.
Unshelve. all: by end_near. Qed.
Lemma cvg_ninftyP (f : R -> R) (l : R) :
f x @[x --> -oo] --> l <->
forall u : R^nat, (u n @[n --> \oo] --> -oo) -> f (u n) @[n --> \oo] --> l.
Proof.
rewrite cvgNy_compNP cvg_pinftyP/= (@bij_forall R^nat _ -%R)//.
have u_opp (u : R^nat) :
((- u) n @[n --> \oo] --> +oo) = (u n @[n --> \oo] --> -oo).
by rewrite propeqE cvgNry.
by under eq_forall do
(rewrite u_opp; under (eq_cvg _ (nbhs l)) do rewrite opprK).
Qed.
End cvgr_fun_dvg_seq.
Section cvge_fun_dvg_seq.
Context {R : realType}.
(* NB: almost the same proof as cvg_pinftyP *)
Lemma cvge_pinftyP (f : R -> \bar R) (l : \bar R) :
f x @[x --> +oo] --> l <->
forall u : R^nat, (u n @[n --> \oo] --> +oo) -> f (u n) @[n --> \oo] --> l.
Proof.
split; first by move=> ? ? /cvg_comp; exact.
apply: contraPP => noncvg_f; apply/existsNP.
under eq_exists do rewrite not_implyE; apply/exists2P.
suff [e e_sep] : exists e : {posnum R}, forall A,
exists2 un, A < un & ~ ball l e%:num (f un).
exists (fun n => sval (cid2 (e_sep n%:R))).
apply/cvgryPgt=> A; near=> n; case: cid2 => //= r nr _.
by rewrite (le_lt_trans _ nr)//; near: n; exact: nbhs_infty_ger.
apply/cvg_ballP => /= /(_ e%:num ltac:(by[])) [N _ /(_ _ (leqnn N))].
by case: cid2 => uN/= _; exact.
move: noncvg_f => /cvg_ballP; rewrite -existsPNP => -[eps eps_gt0].
move /not_near_inftyP => eps_sep; exists (PosNum eps_gt0) => A /=.
by case: (eps_sep _ (num_real A)) => x ? ?; exists x.
Unshelve. all: by end_near. Qed.
(* NB: almost the same proof as cvg_ninftyP *)
Lemma cvge_ninftyP (f : R -> \bar R) (l : \bar R) :
f x @[x --> -oo] --> l <->
forall u : R^nat, (u n @[n --> \oo] --> -oo) -> f (u n) @[n --> \oo] --> l.
Proof.
rewrite cvgNy_compNP cvge_pinftyP/= (@bij_forall R^nat _ -%R)//.
have u_opp (u : R^nat) :
((- u) n @[n --> \oo] --> +oo) = (u n @[n --> \oo] --> -oo).
by rewrite propeqE cvgNry.
by under eq_forall do
(rewrite u_opp; under (eq_cvg _ (nbhs l)) do rewrite opprK).
Qed.
End cvge_fun_dvg_seq.
Section fun_cvg_realType.
Context {R : realType}.
Implicit Types f : R -> R.
(* NB: see nondecreasing_cvgn in sequences.v *)
Lemma nondecreasing_cvgr f : nondecreasing_fun f -> has_ubound (range f) ->
f r @[r --> +oo] --> sup (range f).
Proof.
move=> ndf ubf; set M := sup (range f).
have supf : has_sup (range f) by split => //; exists (f 0), 0.
apply/cvgrPdist_le => _/posnumP[e].
have [p Mefp] : exists p, M - e%:num <= f p.
have [_ -[p _] <- /ltW efp] := sup_adherent (gt0 e) supf.
by exists p; rewrite efp.
near=> n; have pn : p <= n by near: n; apply: nbhs_pinfty_ge; rewrite num_real.
rewrite ler_distlC (le_trans Mefp (ndf _ _ _))//= (@le_trans _ _ M) ?lerDl//.
by have /ubP := sup_upper_bound supf; apply; exists n.
Unshelve. all: by end_near. Qed.
(***md This covers the cases where the interval is
$]a, +\infty[$, $]a, b[$, or $]a, b]$. *)
Lemma nonincreasing_at_right_cvgr f a (b : itv_bound R) : (BRight a < b)%O ->
{in Interval (BRight a) b &, nonincreasing_fun f} ->
has_ubound (f @` [set` Interval (BRight a) b]) ->
f x @[x --> a ^'+] --> sup (f @` [set` Interval (BRight a) b]).
Proof.
move=> ab lef ubf; set M := sup _.
have supf : has_sup [set f x | x in [set` Interval (BRight a) b]].
split => //; case: b ab {lef ubf M} => [[|] t ta|[]] //=.
- exists (f ((a + t) / 2)), ((a + t) / 2) => //=.
by rewrite in_itv/= !midf_lt.
- exists (f ((a + t) / 2)), ((a + t) / 2) => //=.
by rewrite in_itv/= midf_lt// midf_le// ltW.
- by exists (f (a + 1)), (a + 1) => //=; rewrite in_itv/= ltrDl andbT.
apply/cvgrPdist_le => _/posnumP[e].
have {supf} [p [ap pb]] :
exists p, [/\ a < p, (BLeft p < b)%O & M - e%:num <= f p].
have [_ -[p apb] <- /ltW efp] := sup_adherent (gt0 e) supf.
move: apb; rewrite /= in_itv/= -[X in _ && X]/(BLeft p < b)%O => /andP[ap pb].
by exists p; split.
rewrite lerBlDr {}/M.
move: b ab pb lef ubf => [[|] b|[//|]] ab pb lef ubf; set M := sup _ => Mefp.
- near=> r; rewrite ler_distl; apply/andP; split.
+ suff: f r <= M by apply: le_trans; rewrite lerBlDr lerDl.
apply: ub_le_sup => //=; exists r => //; rewrite in_itv/=.
by apply/andP; split; near: r; [exact: nbhs_right_gt|exact: nbhs_right_lt].
+ rewrite (le_trans Mefp)// lerD2r lef//=; last 2 first.
by rewrite in_itv/= ap.
by near: r; exact: nbhs_right_le.
apply/andP; split; near: r; [exact: nbhs_right_gt|exact: nbhs_right_lt].
- near=> r; rewrite ler_distl; apply/andP; split.
+ suff: f r <= M by apply: le_trans; rewrite lerBlDr lerDl.
apply: ub_le_sup => //=; exists r => //; rewrite in_itv/=.
by apply/andP; split; near: r; [exact: nbhs_right_gt|exact: nbhs_right_le].
+ rewrite (le_trans Mefp)// lerD2r lef//=; last 2 first.
by rewrite in_itv/= ap.
by near: r; exact: nbhs_right_le.
by apply/andP; split; near: r; [exact: nbhs_right_gt|exact: nbhs_right_le].
- near=> r; rewrite ler_distl; apply/andP; split.
suff: f r <= M by apply: le_trans; rewrite lerBlDr lerDl.
apply: ub_le_sup => //=; exists r => //; rewrite in_itv/= andbT.
by near: r; apply: nbhs_right_gt.
rewrite (le_trans Mefp)// lerD2r lef//.
- by rewrite in_itv/= andbT; near: r; exact: nbhs_right_gt.
- by rewrite in_itv/= ap.
- by near: r; exact: nbhs_right_le.
Unshelve. all: by end_near. Qed.
Lemma nonincreasing_at_right_is_cvgr f a :
(\forall x \near a^'+, {in `]a, x[ &, nonincreasing_fun f}) ->
(\forall x \near a^'+, has_ubound (f @` `]a, x[)) ->
cvg (f x @[x --> a ^'+]).
Proof.
move=> nif ubf; apply/cvg_ex; near a^'+ => b.
by eexists; apply: (@nonincreasing_at_right_cvgr _ _ (BLeft b));
[rewrite bnd_simp|near: b..].
Unshelve. all: by end_near. Qed.
Lemma nondecreasing_at_right_cvgr f a (b : itv_bound R) : (BRight a < b)%O ->
{in Interval (BRight a) b &, nondecreasing_fun f} ->
has_lbound (f @` [set` Interval (BRight a) b]) ->
f x @[x --> a ^'+] --> inf (f @` [set` Interval (BRight a) b]).
Proof.
move=> ab nif hlb; set M := inf _.
have ndNf : {in Interval (BRight a) b &, nonincreasing_fun (\- f)}.
by move=> r s rab sab /nif; rewrite lerN2; exact.
have hub : has_ubound [set (\- f) x | x in [set` Interval (BRight a) b]].
apply/has_ub_lbN; rewrite image_comp/=.
rewrite [X in has_lbound X](_ : _ = f @` [set` Interval (BRight a) b])//.
by apply: eq_imagel => y _ /=; rewrite opprK.
have /cvgN := nonincreasing_at_right_cvgr ab ndNf hub.
rewrite opprK [X in _ --> X -> _](_ : _ =
inf (f @` [set` Interval (BRight a) b]))//.
by rewrite /inf; congr (- sup _); rewrite image_comp/=; exact: eq_imagel.
Qed.
Lemma nondecreasing_at_right_is_cvgr f a :
(\forall x \near a^'+, {in `]a, x[ &, nondecreasing_fun f}) ->
(\forall x \near a^'+, has_lbound (f @` `]a, x[)) ->
cvg (f x @[x --> a ^'+]).
Proof.
move=> ndf lbf; apply/cvg_ex; near a^'+ => b.
by eexists; apply: (@nondecreasing_at_right_cvgr _ _ (BLeft b));
[rewrite bnd_simp|near: b..].
Unshelve. all: by end_near. Qed.
Lemma nondecreasing_at_left_is_cvgr f a :
(\forall x \near a^'-, {in `]x, a[ &, {homo f : n m / n <= m}}) ->
(\forall x \near a^'-, has_ubound [set f y | y in `]x, a[]) ->
cvg (f x @[x --> a^'-]).
Proof.
move=> ndf ubf; suff: cvg ((f \o -%R) x @[x --> (- a)^'+]).
move=> /cvg_ex[/= l fal].
by apply/cvg_ex; exists l; exact/cvg_at_leftNP.
apply: @nonincreasing_at_right_is_cvgr.
- rewrite at_rightN near_simpl; apply: filterS ndf => x ndf y z.
by rewrite -2!oppr_itvoo => yxa zxa yz; rewrite ndf// lerNr opprK.
- rewrite at_rightN near_simpl; apply: filterS ubf => x [r ubf].
exists r => _/= [s sax <-]; rewrite ubf//=; exists (- s) => //.
by rewrite oppr_itvoo.
Qed.
Let nondecreasing_at_right_is_cvgrW f a b r : a < r -> r < b ->
{in `[a, b] &, nondecreasing_fun f} -> cvg (f x @[x --> r^'+]).
Proof.
move=> ar rb ndf H; apply: nondecreasing_at_right_is_cvgr.
- near=> s => x y xrs yrs xy; rewrite ndf//.
+ by apply: subset_itvW xrs; exact/ltW.
+ by apply: subset_itvW yrs; exact/ltW.
- near=> x; exists (f r) => _ /= [s srx <-]; rewrite ndf//.
+ by apply: subset_itv_oo_cc; rewrite in_itv/= ar.
+ by apply: subset_itvW srx; exact/ltW.
+ by move: srx; rewrite in_itv/= => /andP[/ltW].
Unshelve. all: by end_near. Qed.
Let nondecreasing_at_left_is_cvgrW f a b r : a < r -> r < b ->
{in `[a, b] &, nondecreasing_fun f} -> cvg (f x @[x --> r^'-]).
Proof.
move=> ar rb ndf H; apply: nondecreasing_at_left_is_cvgr.
- near=> s => x y xrs yrs xy; rewrite ndf//.
+ by apply: subset_itvW xrs; exact/ltW.
+ by apply: subset_itvW yrs; exact/ltW.
- near=> x; exists (f r) => _ /= [s srx <-]; rewrite ndf//.
+ by apply: subset_itvW srx; exact/ltW.
+ by apply: subset_itv_oo_cc; rewrite in_itv/= ar.
+ by move: srx; rewrite in_itv/= => /andP[_ /ltW].
Unshelve. all: by end_near. Qed.
Lemma nondecreasing_at_left_at_right f a b :
{in `[a, b] &, nondecreasing_fun f} ->
{in `]a, b[, forall r, lim (f x @[x --> r^'-]) <= lim (f x @[x --> r^'+])}.
Proof.
move=> ndf r; rewrite in_itv/= => /andP[ar rb]; apply: limr_ge.
exact: nondecreasing_at_right_is_cvgrW ndf.
near=> x; apply: limr_le; first exact: nondecreasing_at_left_is_cvgrW ndf.
near=> y; rewrite ndf// ?in_itv/=.
- apply/andP; split; first by near: y; apply: nbhs_left_ge.
exact: (le_trans _ (ltW rb)).
- by rewrite (le_trans (ltW ar))/= ltW.
- exact: (@le_trans _ _ r).
Unshelve. all: by end_near. Qed.
Lemma nonincreasing_at_left_at_right f a b :
{in `[a, b] &, nonincreasing_fun f} ->
{in `]a, b[, forall r, lim (f x @[x --> r^'-]) >= lim (f x @[x --> r^'+])}.
Proof.
move=> nif; have ndNf : {in `[a, b] &, nondecreasing_fun (-%R \o f)}.
by move=> x y xab yab xy /=; rewrite lerNl opprK nif.
move/nondecreasing_at_left_at_right : (ndNf) => H x.
rewrite in_itv/= => /andP[ax xb]; rewrite -[leLHS]opprK lerNl -!limN//.
- by apply: H; rewrite !in_itv/= ax.
- rewrite -(opprK f); apply: is_cvgN.
exact: nondecreasing_at_right_is_cvgrW ndNf.
- rewrite -(opprK f);apply: is_cvgN.
exact: nondecreasing_at_left_is_cvgrW ndNf.
Qed.
End fun_cvg_realType.
Arguments nondecreasing_at_right_cvgr {R f a} b.
Section fun_cvg_ereal.
Context {R : realType}.
Local Open Scope ereal_scope.
(* NB: see ereal_nondecreasing_cvgn in sequences.v *)
Lemma nondecreasing_cvge (f : R -> \bar R) :
nondecreasing_fun f -> f r @[r --> +oo%R] --> ereal_sup (range f).
Proof.
move=> ndf; set S := range f; set l := ereal_sup S.
have [Spoo|Spoo] := pselect (S +oo).
have [N Nf] : exists N, forall n, (n >= N)%R -> f n = +oo.
case: Spoo => N _ uNoo; exists N => n Nn.
by have := ndf _ _ Nn; rewrite uNoo leye_eq => /eqP.
have -> : l = +oo by rewrite /l /ereal_sup; exact: supremum_pinfty.
rewrite -(cvg_shiftr `|N|); apply: cvg_near_cst.
exists N; split; first by rewrite num_real.
by move=> x /ltW Nx; rewrite Nf// ler_wpDr.
have [lpoo|lpoo] := eqVneq l +oo.
rewrite lpoo; apply/cvgeyPge => M.
have /ereal_sup_gt[_ [n _] <- Mun] : M%:E < l by rewrite lpoo// ltry.
exists n; split; first by rewrite num_real.
by move=> m /= nm; rewrite (le_trans (ltW Mun))// ndf// ltW.
have [fnoo|fnoo] := pselect (f = cst -oo).
rewrite /l (_ : S = [set -oo]).
by rewrite ereal_sup1 fnoo; exact: cvg_cst.
apply/seteqP; split => [_ [n _] <- /[!fnoo]//|_ ->].
by rewrite /S fnoo; exists 0%R.
have [/ereal_sup_ninfty lnoo|lnoo] := eqVneq l -oo.
by exfalso; apply/fnoo/funext => n; rewrite (lnoo (f n))//; exists n.
have l_fin_num : l \is a fin_num by rewrite fin_numE lpoo lnoo.
set A := [set n | f n = -oo]; set B := [set n | f n != -oo].
have f_fin_num n : B n -> f n \is a fin_num.
move=> Bn; rewrite fin_numE Bn/=.
by apply: contra_notN Spoo => /eqP unpoo; exists n.
have [x Bx] : B !=set0.
apply/set0P/negP => /eqP B0; apply/fnoo/funext => n.
apply/eqP/negPn/negP => unnoo.
by move/seteqP : B0 => [+ _] => /(_ n); apply.
have xB r : (x <= r)%R -> B r.
move=> /ndf xr; apply/negP => /eqP urnoo.
by move: xr; rewrite urnoo leeNy_eq; exact/negP.
rewrite -(@fineK _ l)//; apply/fine_cvgP; split.
exists x; split; first by rewrite num_real.
by move=> r A1r; rewrite f_fin_num //; exact/xB/ltW.
set g := fun n => if (n < x)%R then fine (f x) else fine (f n).
have <- : sup (range g) = fine l.
apply: EFin_inj; rewrite -ereal_sup_EFin//; last 2 first.
- exists (fine l) => /= _ [m _ <-]; rewrite /g /=.
have [mx|xm] := ltP m x.
by rewrite fine_le// ?f_fin_num//; apply: ereal_sup_ubound; exists x.
rewrite fine_le// ?f_fin_num//; first exact/xB.
by apply: ereal_sup_ubound; exists m.
- by exists (g 0%R), 0%R.
rewrite fineK//; apply/eqP; rewrite eq_le; apply/andP; split.
apply: ereal_sup_le => _ /= [_ [m _] <-] <-.
rewrite /g; have [_|xm] := ltP m x.
by rewrite fineK// ?f_fin_num//; exists x.
by rewrite fineK// ?f_fin_num//; [exists m|exact/xB].
apply: ge_ereal_sup => /= _ [m _] <-.
have [mx|xm] := ltP m x.
rewrite (le_trans (ndf _ _ (ltW mx)))//.
apply: ereal_sup_ubound => /=; exists (fine (f x)); last first.
by rewrite fineK// f_fin_num.
by exists m => //; rewrite /g mx.
apply: ereal_sup_ubound => /=; exists (fine (f m)) => //.
by exists m => //; rewrite /g ltNge xm.
by rewrite fineK ?f_fin_num//; exact: xB.
suff: g x @[x --> +oo%R] --> sup (range g).
apply: cvg_trans; apply: near_eq_cvg; near=> n.
rewrite /g ifF//; apply/negbTE; rewrite -leNgt.
by near: n; apply: nbhs_pinfty_ge; rewrite num_real.
apply: nondecreasing_cvgr.
- move=> m n mn; rewrite /g /=; have [_|xm] := ltP m x.
+ have [nx|nx] := ltP n x; first by rewrite fine_le// f_fin_num.
by rewrite fine_le// ?f_fin_num//; [exact: xB|exact: ndf].
+ rewrite ltNge (le_trans xm mn)//= fine_le ?f_fin_num//.
* exact: xB.
* by apply: xB; rewrite (le_trans xm).
* exact/ndf.
- exists (fine l) => /= _ [m _ <-]; rewrite /g /=.
rewrite -lee_fin (fineK l_fin_num); apply: ereal_sup_ubound.
have [_|xm] := ltP m x; first by rewrite fineK// ?f_fin_num//; eexists.
by rewrite fineK// ?f_fin_num//; [exists m|exact/xB].
Unshelve. all: by end_near. Qed.
(* NB: see ereal_nondecreasing_is_cvgn in sequences.v *)
Lemma nondecreasing_is_cvge (f : R -> \bar R) :
nondecreasing_fun f -> (cvg (f r @[r --> +oo]))%R.
Proof. by move=> u_nd u_ub; apply: cvgP; exact: nondecreasing_cvge. Qed.
Lemma nondecreasing_at_right_cvge (f : R -> \bar R) a (b : itv_bound R) :
(BRight a < b)%O ->
{in Interval (BRight a) b &, nondecreasing_fun f} ->
f x @[x --> a ^'+] --> ereal_inf (f @` [set` Interval (BRight a) b]).
Proof.
move=> ab ndf; set S := (X in ereal_inf X); set l := ereal_inf S.
have [Snoo|Snoo] := pselect (S -oo).
case: (Snoo) => N/=.
rewrite in_itv/= -[X in _ && X]/(BLeft N < b)%O => /andP[aN Nb] fNpoo.
have Nf n : (a < n <= N)%R -> f n = -oo.
move=> /andP[an nN]; apply/eqP.
rewrite eq_le leNye andbT -fNpoo ndf//.
by rewrite in_itv/= -[X in _ && X]/(BLeft n < b)%O an (le_lt_trans _ Nb).
by rewrite in_itv/= -[X in _ && X]/(BLeft N < b)%O (lt_le_trans an nN).
have -> : l = -oo.
by rewrite /l /ereal_inf /ereal_sup supremum_pinfty//=; exists -oo.
apply: cvg_near_cst; exists (N - a)%R => /=; first by rewrite subr_gt0.
move=> y /= + ay; rewrite ltr0_norm ?subr_lt0// opprB => ayNa.
by rewrite Nf// ay/= -(subrK a y) -lerBrDr ltW.
have [lnoo|lnoo] := eqVneq l -oo.
rewrite lnoo; apply/cvgeNyPle => M.
have /ereal_inf_lt[x [y]]/= : M%:E > l by rewrite lnoo ltNyr.
rewrite in_itv/= -[X in _ && X]/(BLeft y < b)%O/= => /andP[ay yb] <- fyM.
exists (y - a)%R => /=; first by rewrite subr_gt0.
move=> z /= + az.
rewrite ltr0_norm ?subr_lt0// opprB ltrBlDr subrK => zy.
rewrite (le_trans _ (ltW fyM))// ndf ?ltW//.
by rewrite in_itv/= -[X in _ && X]/(BLeft z < b)%O/= az/= (lt_trans _ yb).
by rewrite in_itv/= -[X in _ && X]/(BLeft y < b)%O/= (lt_trans az zy).
have [fpoo|fpoo] := pselect {in Interval (BRight a) b, forall x, f x = +oo}.
rewrite {}/l in lnoo *; rewrite {}/S in Snoo lnoo *.
rewrite [X in ereal_inf X](_ : _ = [set +oo]).
rewrite ereal_inf1; apply/cvgeyPgey; near=> M.
move: b ab {ndf lnoo Snoo} fpoo => [[|] b|[//|]] ab fpoo.
- near=> x; rewrite fpoo ?leey// in_itv/=.
by apply/andP; split; near: x; [exact: nbhs_right_gt|exact: nbhs_right_lt].
- near=> x; rewrite fpoo ?leey// in_itv/=.
by apply/andP; split; near: x; [exact: nbhs_right_gt|exact: nbhs_right_le].
- near=> x; rewrite fpoo ?leey// in_itv/= andbT.
by near: x; exact: nbhs_right_gt.
apply/seteqP; split => [_ [n _] <- /[!fpoo]//|_ ->].
move: b ab ndf lnoo Snoo fpoo => [[|] s|[//|]] ab ndf lnoo Snoo fpoo /=.
- by exists ((a + s) / 2)%R; rewrite ?fpoo// in_itv/= !midf_lt.
- by exists ((a + s) / 2)%R; rewrite ?fpoo// in_itv/= !(midf_lt, midf_le)// ltW.
- by exists (a + 1)%R; rewrite ?fpoo// in_itv/= andbT ltrDl.
have [/ereal_inf_pinfty lpoo|lpoo] := eqVneq l +oo.
by exfalso; apply/fpoo => r rab; rewrite (lpoo (f r))//; exists r.
have l_fin_num : l \is a fin_num by rewrite fin_numE lpoo lnoo.
set A := [set r | [/\ (a < r)%R, (BLeft r < b)%O & f r != +oo]].
have f_fin_num r : r \in A -> f r \is a fin_num.
rewrite inE /A/= => -[ar rb] frnoo; rewrite fin_numE frnoo andbT.
apply: contra_notN Snoo => /eqP frpoo.
by exists r => //=; rewrite in_itv/= -[X in _ && X]/(BLeft r < b)%O ar rb.
have [x [ax xb fxpoo]] : A !=set0.
apply/set0P/negP => /eqP A0; apply/fpoo => x.
rewrite in_itv/= -[X in _ && X]/(BLeft x < b)%O => /andP[ax xb].
apply/eqP/negPn/negP => unnoo.
by move/seteqP : A0 => [+ _] => /(_ x); apply; rewrite /A/= ax.
have axA r : (a < r <= x)%R -> r \in A.
move=> /andP[ar rx]; move: (rx) => /ndf rafx; rewrite /A /= inE; split => //.
by rewrite (le_lt_trans _ xb).
apply/negP => /eqP urnoo.
move: rafx; rewrite urnoo.
rewrite in_itv/= -[X in _ && X]/(BLeft r < b)%O ar/=.
rewrite in_itv/= -[X in _ && X]/(BLeft x < b)%O ax/=.
by rewrite leye_eq (negbTE fxpoo) -falseE; apply; rewrite (le_lt_trans _ xb).
rewrite -(@fineK _ l)//; apply/fine_cvgP; split.
exists (x - a)%R => /=; first by rewrite subr_gt0.
move=> z /= + az.
rewrite ltr0_norm ?subr_lt0// opprB ltrBlDr subrK// => zx.
by rewrite f_fin_num// axA// az/= ltW.
set g := fun n => if (a < n < x)%R then fine (f n) else fine (f x).
have <- : inf [set g x | x in [set` Interval (BRight a) b]] = fine l.
apply: EFin_inj; rewrite -ereal_inf_EFin//; last 2 first.
- exists (fine l) => /= _ [m _ <-]; rewrite /g /=.
case: ifPn => [/andP[am mx]|].
rewrite fine_le// ?f_fin_num//; first by rewrite axA// am (ltW mx).
apply: ereal_inf_lbound; exists m => //=.
rewrite in_itv/= -[X in _ && X]/(BLeft m < b)%O am/=.
by rewrite (le_lt_trans _ xb) ?ltW.
rewrite negb_and -!leNgt => /orP[ma|xm].
rewrite fine_le// ?f_fin_num ?inE//.
apply: ereal_inf_lbound; exists x => //=.
by rewrite in_itv/= -[X in _ && X]/(BLeft x < b)%O ax xb.
rewrite fine_le// ?f_fin_num ?inE//.
apply: ereal_inf_lbound; exists x => //=.
by rewrite in_itv/= -[X in _ && X]/(BLeft x < b)%O ax xb.
- rewrite {}/l in lnoo lpoo l_fin_num *.
rewrite {}/S in Snoo lnoo lpoo l_fin_num *.
rewrite {}/A in f_fin_num axA *.
move: b ab {xb ndf lnoo lpoo l_fin_num f_fin_num Snoo fpoo axA} =>
[[|] s|[//|]] ab /=.
+ exists (g ((a + s) / 2))%R, ((a + s) / 2)%R => //=.
by rewrite /= in_itv/= !midf_lt.
+ exists (g ((a + s) / 2))%R, ((a + s) / 2)%R => //=.
by rewrite /= in_itv/= !(midf_lt, midf_le)// ltW.
+ exists (g (a + 1)%R), (a + 1)%R => //=.
by rewrite in_itv/= andbT ltrDl.
rewrite fineK//; apply/eqP; rewrite eq_le; apply/andP; split; last first.
apply: ereal_inf_le_tmp => _ /= [_ [m _] <-] <-.
rewrite /g; case: ifPn => [/andP[am mx]|].
rewrite fineK// ?f_fin_num//; last by rewrite axA// am ltW.
exists m => //=.
by rewrite in_itv/= -[X in _ && X]/(BLeft m < b)%O am/= (lt_trans _ xb).
rewrite negb_and -!leNgt => /orP[ma|xm].
rewrite fineK//; last by rewrite f_fin_num ?inE.
exists x => //=.
by rewrite in_itv/= -[X in _ && X]/(BLeft x < b)%O ax xb.
exists x => /=.
by rewrite in_itv/= -[X in _ && X]/(BLeft x < b)%O ax xb.
by rewrite fineK// f_fin_num ?inE.
apply: le_ereal_inf_tmp => /= y [m] /=.
rewrite in_itv/= -[X in _ && X]/(BLeft m < b)%O => /andP[am mb] <-{y}.
have [mx|xm] := ltP m x.
apply: ereal_inf_lbound => /=; exists (fine (f m)); last first.
by rewrite fineK// f_fin_num// axA// am (ltW mx).
by exists m; [rewrite in_itv/= am|rewrite /g am mx].
rewrite (@le_trans _ _ (f x))//; last first.
by apply: ndf => //; rewrite in_itv//= ?ax ?am.
apply: ereal_inf_lbound => /=; exists (fine (f x)); last first.
by rewrite fineK// f_fin_num ?inE.
by exists x; [rewrite in_itv/= ax|rewrite /g ltxx andbF].
suff: g x @[x --> a^'+] --> inf [set g x | x in [set` Interval (BRight a) b]].
apply: cvg_trans; apply: near_eq_cvg; near=> n.
rewrite /g /=; case: ifPn => [//|].
rewrite negb_and -!leNgt => /orP[na|xn].
exfalso.
move: na; rewrite leNgt => /negP; apply.
by near: n; exact: nbhs_right_gt.
suff nx : (n < x)%R by rewrite ltNge xn in nx.
near: n; exists ((x - a) / 2)%R; first by rewrite /= divr_gt0// subr_gt0.
move=> y /= /[swap] ay.
rewrite ltr0_norm// ?subr_lt0// opprB ltrBlDr => /lt_le_trans; apply.
by rewrite -lerBrDr ler_pdivrMr// ler_pMr// ?ler1n// subr_gt0.
apply: nondecreasing_at_right_cvgr => //.
- move=> m n; rewrite !in_itv/= -[X in _ && X]/(BLeft m < b)%O.
rewrite -[X in _ -> _ && X -> _]/(BLeft n < b)%O.
move=> /andP[am mb] /andP[an nb] mn.
rewrite /g /=; case: ifPn => [/andP[_ mx]|].
rewrite (lt_le_trans am mn) /=; have [nx|nn0] := ltP n x.
rewrite fine_le ?f_fin_num ?ndf//; first by rewrite axA// am (ltW mx).
by rewrite axA// (ltW nx) andbT (lt_le_trans am).
by rewrite in_itv/= am.
by rewrite in_itv/= an.
rewrite fine_le ?f_fin_num//.
+ by rewrite axA// am (ltW (lt_le_trans mx _)).
+ by rewrite inE.
+ rewrite ndf//; last exact/ltW.
by rewrite !in_itv/= am.
by rewrite !in_itv/= ax.
rewrite negb_and -!leNgt => /orP[|xm]; first by rewrite leNgt am.
by rewrite (lt_le_trans am mn)/= ltNge (le_trans xm mn).
- exists (fine l) => /= _ [m _ <-]; rewrite /g /=.
rewrite -lee_fin (fineK l_fin_num); apply: ereal_inf_lbound.
case: ifPn => [/andP[am mn0]|].
rewrite fineK//; last by rewrite f_fin_num// axA// am (ltW mn0).
exists m => //=.
by rewrite in_itv/= -[X in _ && X]/(BLeft m < b)%O am (lt_trans _ xb).
rewrite negb_and -!leNgt => /orP[ma|xm].
rewrite fineK//; first by exists x => //=; rewrite in_itv/= ax.
by rewrite f_fin_num ?inE.
by rewrite fineK// ?f_fin_num ?inE//; exists x => //=; rewrite in_itv/= ax.
Unshelve. all: by end_near. Qed.
Lemma nondecreasing_at_right_is_cvge (f : R -> \bar R) (a : R) :
(\forall x \near a^'+, {in `]a, x[ &, nondecreasing_fun f}) ->
cvg (f x @[x --> a ^'+]).
Proof.
move=> ndf; apply/cvg_ex; near a^'+ => b.
by eexists; apply: (@nondecreasing_at_right_cvge _ _ (BLeft b));
[rewrite bnd_simp|near: b..].
Unshelve. all: by end_near. Qed.
Lemma nonincreasing_cvge (f : R -> \bar R) :
nonincreasing_fun f -> f r @[r --> +oo%R] --> ereal_inf (range f).