forked from math-comp/analysis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrealfun.v
1914 lines (1727 loc) · 75.2 KB
/
realfun.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
(* mathcomp analysis (c) 2017 Inria and AIST. License: CeCILL-C. *)
From mathcomp Require Import all_ssreflect ssralg ssrint ssrnum finmap.
From mathcomp Require Import matrix interval zmodp vector fieldext falgebra.
From mathcomp Require Import mathcomp_extra boolp classical_sets functions.
From mathcomp Require Import cardinality.
Require Import ereal reals signed topology prodnormedzmodule normedtype derive.
Require Import real_interval.
From HB Require Import structures.
(******************************************************************************)
(* This file provides properties of standard real-valued functions over real *)
(* numbers (e.g., the continuity of the inverse of a continuous function). *)
(* *)
(* derivable_oo_continuous_bnd f x y == f is derivable on `]x, y[ and *)
(* continuous up to the boundary *)
(* *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import Order.TTheory GRing.Theory Num.Def Num.Theory.
Import numFieldTopology.Exports.
Local Open Scope classical_set_scope.
Local Open Scope ring_scope.
Import numFieldNormedType.Exports.
Section derivable_oo_continuous_bnd.
Context {R : numFieldType} {V : normedModType R}.
Definition derivable_oo_continuous_bnd (f : R -> V) (x y : R) :=
[/\ {in `]x, y[, forall x, derivable f x 1},
f @ x^'+ --> f x & f @ y^'- --> f y].
Lemma derivable_oo_continuous_bnd_within (f : R -> V) (x y : R) :
derivable_oo_continuous_bnd f x y -> {within `[x, y], continuous f}.
Proof.
move=> [fxy fxr fyl]; apply/subspace_continuousP => z /=.
rewrite in_itv/= => /andP[]; rewrite le_eqVlt => /predU1P[<-{z} xy|].
have := cvg_at_right_within fxr; apply: cvg_trans; apply: cvg_app.
by apply: within_subset => z/=; rewrite in_itv/= => /andP[].
move=> /[swap].
rewrite le_eqVlt => /predU1P[->{z} xy|zy xz].
have := cvg_at_left_within fyl; apply: cvg_trans; apply: cvg_app.
by apply: within_subset => z/=; rewrite in_itv/= => /andP[].
apply: cvg_within_filter.
apply/differentiable_continuous; rewrite -derivable1_diffP.
by apply: fxy; rewrite in_itv/= xz zy.
Qed.
End derivable_oo_continuous_bnd.
Section real_inverse_functions.
Variable R : realType.
Implicit Types (a b : R) (f g : R -> R).
(* This lemma should be used with caution. Generally `{within I, continuous f}`
is what one would intend. So having `{in I, continuous f}` as a condition
may indicate potential issues at the endpoints of the interval.
*)
Lemma continuous_subspace_itv (I : interval R) (f : R -> R) :
{in I, continuous f} -> {within [set` I], continuous f}.
Proof.
move=> ctsf; apply: continuous_in_subspaceT => x Ix; apply: ctsf.
by move: Ix; rewrite inE.
Qed.
Lemma itv_continuous_inj_le f (I : interval R) :
(exists x y, [/\ x \in I, y \in I, x < y & f x <= f y]) ->
{within [set` I], continuous f} -> {in I &, injective f} ->
{in I &, {mono f : x y / x <= y}}.
Proof.
gen have fxy : f / {in I &, injective f} ->
{in I &, forall x y, x < y -> f x != f y}.
move=> fI x y xI yI xLy; apply/negP => /eqP /fI => /(_ xI yI) xy.
by move: xLy; rewrite xy ltxx.
gen have main : f / forall c, {within [set` I], continuous f} ->
{in I &, injective f} ->
{in I &, forall a b, f a < f b -> a < c -> c < b -> f a < f c /\ f c < f b}.
move=> c fC fI a b aI bI faLfb aLc cLb.
have intP := interval_is_interval aI bI.
have cI : c \in I by rewrite intP// (ltW aLc) ltW.
have ctsACf : {within `[a, c], continuous f}.
apply: (continuous_subspaceW _ fC) => x; rewrite /= inE => /itvP axc.
by rewrite intP// axc/= (le_trans _ (ltW cLb))// axc.
have ctsCBf : {within `[c, b], continuous f}.
apply: (continuous_subspaceW _ fC) => x /=; rewrite inE => /itvP axc.
by rewrite intP// axc andbT (le_trans (ltW aLc)) ?axc.
have [aLb alb'] : a < b /\ a <= b by rewrite ltW (lt_trans aLc).
have [faLfc|fcLfa|/eqP faEfc] /= := ltrgtP (f a) (f c).
- split; rewrite // lt_neqAle fxy // leNgt; apply/negP => fbLfc.
have := fbLfc; suff /eqP -> : c == b by rewrite ltxx.
rewrite eq_le (ltW cLb) /=.
have [d /andP[ad dc] fdEfb] : exists2 d, a <= d <= c & f d = f b.
have aLc' : a <= c by rewrite ltW.
apply: IVT => //; last first.
by case: ltrgtP faLfc; rewrite // (ltW faLfb) // ltW.
rewrite -(fI _ _ _ _ fdEfb) //.
move: ad dc; rewrite le_eqVlt =>/predU1P[<-//| /ltW L] dc.
by rewrite intP// L (le_trans _ (ltW cLb)).
- have [fbLfc | fcLfb | fbEfc] /= := ltrgtP (f b) (f c).
+ by have := lt_trans fbLfc fcLfa; rewrite ltNge (ltW faLfb).
+ have [d /andP[cLd dLb] /eqP] : exists2 d, c <= d <= b & f d = f a.
have cLb' : c <= b by rewrite ltW.
apply: IVT => //; last by case: ltrgtP fcLfb; rewrite // !ltW.
have /(fxy f fI) : a < d by rewrite (lt_le_trans aLc).
suff dI' : d \in I by rewrite eq_sym=> /(_ aI dI') => /negbTE ->.
move: dLb; rewrite le_eqVlt => /predU1P[->//|/ltW db].
by rewrite intP// db (le_trans (ltW aLc)).
+ by move: fcLfa; rewrite -fbEfc ltNge (ltW faLfb).
by move/(fxy _ fI) : aLc=> /(_ aI cI); rewrite faEfc.
move=> [u [v [uI vI ulv +]]] fC fI; rewrite le_eqVlt => /predU1P[fufv|fuLfv].
by move/fI: fufv => /(_ uI vI) uv; move: ulv; rewrite uv ltxx.
have aux a c b : a \in I -> b \in I -> a < c -> c < b ->
(f a < f c -> f a < f b /\ f c < f b) /\
(f c < f b -> f a < f b /\ f a < f c).
move=> aI bI aLc cLb; have aLb := lt_trans aLc cLb.
have cI : c \in I by rewrite (interval_is_interval aI bI)// (ltW aLc)/= ltW.
have fanfb : f a != f b by apply: (fxy f fI).
have decr : f b < f a -> f b < f c /\ f c < f a.
have ofC : {within [set` I], continuous (-f)}.
move=> ?; apply: continuous_comp; [exact: fC | exact: continuousN].
have ofI : {in I &, injective (-f)} by move=>> ? ? /oppr_inj/fI ->.
rewrite -[X in X < _ -> _](opprK (f b)) ltr_oppl => ofaLofb.
have := main _ c ofC ofI a b aI bI ofaLofb aLc cLb.
by (do 2 rewrite ltr_oppl opprK); rewrite and_comm.
split=> [faLfc|fcLfb].
suff L : f a < f b by have [] := main f c fC fI a b aI bI L aLc cLb.
by case: ltgtP decr fanfb => // fbfa []//; case: ltgtP faLfc.
suff L : f a < f b by have [] := main f c fC fI a b aI bI L aLc cLb.
by case: ltgtP decr fanfb => // fbfa []//; case: ltgtP fcLfb.
have{main fC} whole a c b := main f c fC fI a b.
have low a c b : f a < f c -> a \in I -> b \in I ->
a < c -> c < b -> f a < f b /\ f c < f b.
by move=> L aI bI ac cb; case: (aux a c b aI bI ac cb)=> [/(_ L)].
have high a c b : f c < f b -> a \in I -> b \in I ->
a < c -> c < b -> f a < f b /\ f a < f c.
by move=> L aI bI ac cb; case: (aux a c b aI bI ac cb)=> [_ /(_ L)].
apply: le_mono_in => x y xI yI xLy.
have [uLx | xLu | xu] := ltrgtP u x.
- suff fuLfx : f u < f x by have [] := low u x y fuLfx uI yI uLx xLy.
have [xLv | vLx | -> //] := ltrgtP x v; first by case: (whole u x v).
by case: (low u v x).
- have fxLfu : f x < f u by have [] := high x u v fuLfv xI vI xLu ulv.
have [yLu | uLy | -> //] := ltrgtP y u; first by case: (whole x y u).
by case: (low x u y).
move: xLy; rewrite -xu => uLy.
have [yLv | vLy | -> //] := ltrgtP y v; first by case: (whole u y v).
by case: (low u v y).
Qed.
Lemma itv_continuous_inj_ge f (I : interval R) :
(exists x y, [/\ x \in I, y \in I, x < y & f y <= f x]) ->
{within [set` I], continuous f} -> {in I &, injective f} ->
{in I &, {mono f : x y /~ x <= y}}.
Proof.
move=> [a [b [aI bI ab fbfa]]] fC fI x y xI yI.
suff : (- f) y <= (- f) x = (y <= x) by rewrite ler_oppl opprK.
apply: itv_continuous_inj_le xI => // [|x1 x1I | x1 x2 x1I x2I].
- by exists a, b; split => //; rewrite ler_oppl opprK.
- by apply/continuousN/fC.
by move/oppr_inj; apply/fI.
Qed.
Lemma itv_continuous_inj_mono f (I : interval R) :
{within [set` I], continuous f} -> {in I &, injective f} -> monotonous I f.
Proof.
move=> fC fI.
case: (pselect (exists a b, [/\ a \in I , b \in I & a < b])); last first.
move=> N2I; left => x y xI yI; suff -> : x = y by rewrite ?lexx.
by apply: contra_notP N2I => /eqP; case: ltgtP; [exists x, y|exists y, x|].
move=> [a [b [aI bI lt_ab]]].
have /orP[faLfb|fbLfa] := le_total (f a) (f b).
by left; apply: itv_continuous_inj_le => //; exists a, b; rewrite ?faLfb.
by right; apply: itv_continuous_inj_ge => //; exists a, b; rewrite ?fbLfa.
Qed.
Lemma segment_continuous_inj_le f a b :
f a <= f b -> {within `[a, b], continuous f} -> {in `[a, b] &, injective f} ->
{in `[a, b] &, {mono f : x y / x <= y}}.
Proof.
move=> fafb fct finj; have [//|] := itv_continuous_inj_mono fct finj.
have [aLb|bLa|<-] := ltrgtP a b; first 1 last.
- by move=> _ x ?; rewrite itv_ge// -ltNge.
- by move=> _ x y /itvxxP-> /itvxxP->; rewrite !lexx.
move=> /(_ a b); rewrite !bound_itvE fafb.
by move=> /(_ (ltW aLb) (ltW aLb)); rewrite lt_geF.
Qed.
Lemma segment_continuous_inj_ge f a b :
f a >= f b -> {within `[a, b], continuous f} -> {in `[a, b] &, injective f} ->
{in `[a, b] &, {mono f : x y /~ x <= y}}.
Proof.
move=> fafb fct finj; have [|//] := itv_continuous_inj_mono fct finj.
have [aLb|bLa|<-] := ltrgtP a b; first 1 last.
- by move=> _ x ?; rewrite itv_ge// -ltNge.
- by move=> _ x y /itvxxP-> /itvxxP->; rewrite !lexx.
move=> /(_ b a); rewrite !bound_itvE fafb.
by move=> /(_ (ltW aLb) (ltW aLb)); rewrite lt_geF.
Qed.
(* The condition "f a <= f b" is unnecessary because the last *)
(* interval condition is vacuously true otherwise. *)
Lemma segment_can_le a b f g : a <= b ->
{within `[a, b], continuous f} ->
{in `[a, b], cancel f g} ->
{in `[f a, f b] &, {mono g : x y / x <= y}}.
Proof.
move=> aLb ctf fK; have [fbLfa | faLfb] := ltrP (f b) (f a).
by move=> x y; rewrite itv_ge// -ltNge.
have [aab bab] : a \in `[a, b] /\ b \in `[a, b] by rewrite !bound_itvE.
case: ltgtP faLfb => // [faLfb _|-> _ _ _ /itvxxP-> /itvxxP->]; rewrite ?lexx//.
have lt_ab : a < b by case: (ltgtP a b) aLb faLfb => // ->; rewrite ltxx.
have w : exists x y, [/\ x \in `[a, b], y \in `[a, b], x < y & f x <= f y].
by exists a, b; rewrite !bound_itvE (ltW faLfb).
have fle := itv_continuous_inj_le w ctf (can_in_inj fK).
move=> x y xin yin; have := IVT aLb ctf.
case: (ltrgtP (f a) (f b)) faLfb => // _ _ ivt.
by have [[u uin <-] [v vin <-]] := (ivt _ xin, ivt _ yin); rewrite !fK// !fle.
Qed.
Section negation_itv.
Local Definition itvN_oppr a b := @GRing.opp R.
Local Lemma itv_oppr_is_fun a b :
isFun _ _ `[- b, - a]%classic `[a, b]%classic (itvN_oppr a b).
Proof. by split=> x /=; rewrite oppr_itvcc. Qed.
HB.instance Definition _ a b := itv_oppr_is_fun a b.
End negation_itv.
(* The condition "f b <= f a" is unnecessary---see seg...increasing above *)
Lemma segment_can_ge a b f g : a <= b ->
{within `[a, b], continuous f} ->
{in `[a, b], cancel f g} ->
{in `[f b, f a] &, {mono g : x y /~ x <= y}}.
Proof.
move=> aLb fC fK x y xfbfa yfbfa; rewrite -ler_opp2.
apply: (@segment_can_le (- b) (- a) (f \o -%R) (- g));
rewrite /= ?ler_opp2 ?opprK //.
pose fun_neg : subspace `[-b,-a] -> subspace `[a,b] := itvN_oppr a b.
move=> z; apply: (@continuous_comp _ _ _ [fun of fun_neg]); last exact: fC.
exact/subspaceT_continuous/continuous_subspaceT/opp_continuous.
by move=> z zab; rewrite -[- g]/(@GRing.opp _ \o g)/= fK ?opprK// oppr_itvcc.
Qed.
Lemma segment_can_mono a b f g : a <= b ->
{within `[a, b], continuous f} -> {in `[a, b], cancel f g} ->
monotonous (f @`[a, b]) g.
Proof.
move=> le_ab fct fK; rewrite /monotonous/=; case: ltrgtP => fab; [left|right..];
do ?by [apply: segment_can_le|apply: segment_can_ge].
by move=> x y /itvxxP<- /itvxxP<-; rewrite !lexx.
Qed.
Lemma segment_continuous_surjective a b f : a <= b ->
{within `[a, b], continuous f} -> set_surj `[a, b] (f @`[a, b]) f.
Proof. by move=> ? fct y/= /IVT[]// x; exists x. Qed.
Lemma segment_continuous_le_surjective a b f : a <= b -> f a <= f b ->
{within `[a, b], continuous f} -> set_surj `[a, b] `[f a, f b] f.
Proof.
move=> le_ab f_ab /(segment_continuous_surjective le_ab).
by rewrite (min_idPl _)// (max_idPr _).
Qed.
Lemma segment_continuous_ge_surjective a b f : a <= b -> f b <= f a ->
{within `[a, b], continuous f} -> set_surj `[a, b] `[f b, f a] f.
Proof.
move=> le_ab f_ab /(segment_continuous_surjective le_ab).
by rewrite (min_idPr _)// (max_idPl _).
Qed.
Lemma continuous_inj_image_segment a b f : a <= b ->
{within `[a, b], continuous f} -> {in `[a, b] &, injective f} ->
f @` `[a, b] = f @`[a, b]%classic.
Proof.
move=> leab fct finj; apply: mono_surj_image_segment => //.
exact: itv_continuous_inj_mono.
exact: segment_continuous_surjective.
Qed.
Lemma continuous_inj_image_segmentP a b f : a <= b ->
{within `[a, b], continuous f} -> {in `[a, b] &, injective f} ->
forall y, reflect (exists2 x, x \in `[a, b] & f x = y) (y \in f @`[a, b]).
Proof.
move=> /continuous_inj_image_segment/[apply]/[apply]/predeqP + y => /(_ y) faby.
by apply/(equivP idP); symmetry.
Qed.
Lemma segment_continuous_can_sym a b f g : a <= b ->
{within `[a, b], continuous f} -> {in `[a, b], cancel f g} ->
{in f @`[a, b], cancel g f}.
Proof.
move=> aLb ctf fK; have g_mono := segment_can_mono aLb ctf fK.
have f_mono := itv_continuous_inj_mono ctf (can_in_inj fK).
have f_surj := segment_continuous_surjective aLb ctf.
have fIP := mono_surj_image_segmentP aLb f_mono f_surj.
suff: {in f @`[a, b], {on `[a, b], cancel g & f}}.
by move=> gK _ /fIP[x xab <-]; rewrite fK.
have: {in f @`[a, b] &, {on `[a, b] &, injective g}}.
by move=> _ _ /fIP [x xab <-] /fIP[y yab <-]; rewrite !fK// => _ _ ->.
by apply/ssrbool.inj_can_sym_in_on => x xab; rewrite ?fK ?mono_mem_image_segment.
Qed.
Lemma segment_continuous_le_can_sym a b f g : a <= b ->
{within `[a, b], continuous f} -> {in `[a, b], cancel f g} ->
{in `[f a, f b], cancel g f}.
Proof.
move=> aLb fct fK x xfafb; apply: (segment_continuous_can_sym aLb fct fK).
have : f a <= f b by rewrite (itvP xfafb).
by case: ltrgtP xfafb => // ->.
Qed.
Lemma segment_continuous_ge_can_sym a b f g : a <= b ->
{within `[a, b], continuous f} -> {in `[a, b], cancel f g} ->
{in `[f b, f a], cancel g f}.
Proof.
move=> aLb fct fK x xfafb; apply: (segment_continuous_can_sym aLb fct fK).
have : f a >= f b by rewrite (itvP xfafb).
by case: ltrgtP xfafb => // ->.
Qed.
Lemma segment_inc_surj_continuous a b f :
{in `[a, b] &, {mono f : x y / x <= y}} -> set_surj `[a, b] `[f a, f b] f ->
{within `[a, b], continuous f}.
Proof.
move=> fle f_surj; have [f_inj flt] := (inc_inj_in fle, leW_mono_in fle).
have [aLb|bLa|] := ltgtP a b; first last.
- by move=> ->; rewrite set_itv1; exact: continuous_subspace1.
- rewrite continuous_subspace_in => z /set_mem /=; rewrite in_itv /=.
by move=> /andP[/le_trans] /[apply]; rewrite leNgt bLa.
have le_ab : a <= b by rewrite ltW.
have [aab bab] : a \in `[a, b] /\ b \in `[a, b] by rewrite !bound_itvE ltW.
have fab : f @` `[a, b] = `[f a, f b]%classic by exact:inc_surj_image_segment.
pose g := pinv `[a, b] f; have fK : {in `[a, b], cancel f g}.
by rewrite -[mem _]mem_setE; apply: pinvKV; rewrite !mem_setE.
have gK : {in `[f a, f b], cancel g f} by move=> z zab; rewrite pinvK// fab inE.
have gle : {in `[f a, f b] &, {mono g : x y / x <= y}}.
apply: can_mono_in (fle); first by move=> *; rewrite gK.
move=> z zfab; have {zfab} : `[f a, f b]%classic z by [].
by rewrite -fab => -[x xab <-]; rewrite fK.
have glt := leW_mono_in gle.
rewrite continuous_subspace_in => x xab.
have xabcc : x \in `[a, b] by move: xab; rewrite mem_setE.
have fxab : f x \in `[f a, f b] by rewrite in_itv/= !fle.
have := xabcc; rewrite in_itv //= => /andP [ax xb].
apply/cvgrPdist_lt => _ /posnumP[e]; rewrite !near_simpl; near=> y.
rewrite (@le_lt_trans _ _ (e%:num / 2%:R))//; last first.
by rewrite ltr_pdivr_mulr// ltr_pmulr// ltr1n.
rewrite ler_distlC; near: y.
pose u := minr (f x + e%:num / 2) (f b).
pose l := maxr (f x - e%:num / 2) (f a).
have ufab : u \in `[f a, f b].
rewrite !in_itv /= le_minl ?le_minr lexx ?fle // le_ab orbT ?andbT.
by rewrite ler_paddr // fle.
have lfab : l \in `[f a, f b].
rewrite !in_itv/= le_maxl ?le_maxr lexx ?fle// le_ab orbT ?andbT.
by rewrite ler_subl_addr ler_paddr// fle // lexx.
have guab : g u \in `[a, b].
rewrite !in_itv; apply/andP; split; have := ufab; rewrite in_itv => /andP.
by case; rewrite /= -gle // ?fK // bound_itvE fle.
by case => _; rewrite /= -gle // ?fK // bound_itvE fle.
have glab : g l \in `[a, b].
rewrite !in_itv; apply/andP; split; have := lfab; rewrite in_itv /= => /andP.
by case; rewrite -gle // ?fK // bound_itvE fle.
by case => _; rewrite -gle // ?fK // bound_itvE fle.
have faltu : f a < u.
rewrite /u comparable_lt_minr ?real_comparable ?num_real// flt// aLb andbT.
by rewrite (@le_lt_trans _ _ (f x)) ?fle// ltr_addl.
have lltfb : l < f b.
rewrite /u comparable_lt_maxl ?real_comparable ?num_real// flt// aLb andbT.
by rewrite (@lt_le_trans _ _ (f x)) ?fle// ltr_subl_addr ltr_addl.
case: pselect => // _; rewrite near_withinE; near_simpl.
have Fnbhs : Filter (nbhs x) by apply: nbhs_filter.
have := ax; rewrite le_eqVlt => /orP[/eqP|] {}ax.
near=> y => /[dup] yab; rewrite /= in_itv => /andP[ay yb]; apply/andP; split.
by rewrite (@le_trans _ _ (f a)) ?fle// ler_subl_addr ax ler_paddr.
apply: ltW; suff : f y < u by rewrite lt_minr => /andP[->].
rewrite -?[f y < _]glt// ?fK//; last by rewrite in_itv /= !fle.
by near: y; near_simpl; apply: open_lt; rewrite /= -flt ?gK// -ax.
have := xb; rewrite le_eqVlt => /orP[/eqP {}xb {ax}|{}xb].
near=> y => /[dup] yab; rewrite /= in_itv /= => /andP[ay yb].
apply/andP; split; last by rewrite (@le_trans _ _ (f b)) ?fle// xb ler_paddr.
apply: ltW; suff : l < f y by rewrite lt_maxl => /andP[->].
rewrite -?[_ < f y]glt// ?fK//; last by rewrite in_itv /= !fle.
by near: y; near_simpl; apply: open_gt; rewrite /= -flt// gK// xb.
have xoab : x \in `]a, b[ by rewrite in_itv /=; apply/andP; split.
near=> y; suff: l <= f y <= u.
by rewrite le_maxl le_minr -!andbA => /and4P[-> _ ->].
have ? : y \in `[a, b] by apply: subset_itv_oo_cc; near: y; apply: near_in_itv.
have fyab : f y \in `[f a, f b] by rewrite in_itv/= !fle// ?ltW.
rewrite -[l <= _]gle -?[_ <= u]gle// ?fK //.
apply: subset_itv_oo_cc; near: y; apply: near_in_itv; rewrite in_itv /=.
rewrite -[x]fK // !glt//= lt_minr lt_maxl ?andbT ltr_subl_addr ltr_spaddr //.
by apply/and3P; split; rewrite // flt.
Unshelve. all: by end_near. Qed.
Lemma segment_dec_surj_continuous a b f :
{in `[a, b] &, {mono f : x y /~ x <= y}} ->
set_surj `[a, b] `[f b, f a] f ->
{within `[a, b], continuous f}.
Proof.
move=> fge f_surj; suff: {within `[a, b], continuous (- f)}.
move=> contNf x xab; rewrite -[f]opprK.
exact/continuous_comp/opp_continuous/contNf.
apply: segment_inc_surj_continuous.
by move=> x y xab yab; rewrite ler_opp2 fge.
by move=> y /=; rewrite -oppr_itvcc => /f_surj[x ? /(canLR opprK)<-]; exists x.
Qed.
Lemma segment_mono_surj_continuous a b f :
monotonous `[a, b] f -> set_surj `[a, b] (f @`[a, b]) f ->
{within `[a, b], continuous f}.
Proof.
rewrite continuous_subspace_in => -[fle|fge] f_surj x /set_mem /= xab.
have leab : a <= b by rewrite (itvP xab).
have fafb : f a <= f b by rewrite fle // ?bound_itvE.
by apply: segment_inc_surj_continuous => //; case: ltrP f_surj fafb.
have leab : a <= b by rewrite (itvP xab).
have fafb : f b <= f a by rewrite fge // ?bound_itvE.
by apply: segment_dec_surj_continuous => //; case: ltrP f_surj fafb.
Qed.
Lemma segment_can_le_continuous a b f g : a <= b ->
{within `[a, b], continuous f} ->
{in `[a, b], cancel f g} ->
{within `[(f a), (f b)], continuous g}.
Proof.
move=> aLb ctf; rewrite continuous_subspace_in => fK x /set_mem /= xab.
have faLfb : f a <= f b by rewrite (itvP xab).
apply: segment_inc_surj_continuous; first exact: segment_can_le.
rewrite !fK ?bound_itvE//=; apply: (@can_surj _ _ f); first by rewrite mem_setE.
exact/image_subP/mem_inc_segment/segment_continuous_inj_le/(can_in_inj fK).
Qed.
Lemma segment_can_ge_continuous a b f g : a <= b ->
{within `[a, b], continuous f} ->
{in `[a, b], cancel f g} ->
{within `[(f b), (f a)], continuous g}.
Proof.
move=> aLb ctf; rewrite continuous_subspace_in => fK x /set_mem /= xab.
have fbLfa : f b <= f a by rewrite (itvP xab).
apply: segment_dec_surj_continuous; first exact: segment_can_ge.
rewrite !fK ?bound_itvE//=; apply: (@can_surj _ _ f); first by rewrite mem_setE.
exact/image_subP/mem_dec_segment/segment_continuous_inj_ge/(can_in_inj fK).
Qed.
Lemma segment_can_continuous a b f g : a <= b ->
{within `[a, b], continuous f} ->
{in `[a, b], cancel f g} ->
{within f @`[a, b], continuous g}.
Proof.
move=> aLb crf fK x; case: lerP => // _;
by [apply: segment_can_ge_continuous|apply: segment_can_le_continuous].
Qed.
Lemma near_can_continuousAcan_sym f g (x : R) :
{near x, cancel f g} -> {near x, continuous f} ->
{near f x, continuous g} /\ {near f x, cancel g f}.
Proof.
move=> fK fct; near (0 : R)^'+ => e; have e_gt0 : 0 < e by [].
have xBeLxDe : x - e <= x + e by rewrite ler_add2l gt0_cp.
have fcte : {in `[x - e, x + e], continuous f}.
by near: e; apply/at_right_in_segment.
have fwcte : {within `[x - e, x + e], continuous f}.
apply: continuous_in_subspaceT => y yI.
by apply: fcte; move/set_mem: yI.
have fKe : {in `[x - e, x + e], cancel f g}
by near: e; apply/at_right_in_segment.
have nearfx : \forall y \near f x, y \in f @`](x - e), (x + e)[.
apply: near_in_itv; apply: mono_mem_image_itvoo; last first.
by rewrite in_itv/= -ltr_distlC subrr normr0.
apply: itv_continuous_inj_mono => //.
by apply: (@can_in_inj _ _ _ _ g); near: e; apply/at_right_in_segment.
have fxI : f x \in f @`]x - e, x + e[ by exact: (nbhs_singleton nearfx).
split; near=> y; first last.
rewrite (@segment_continuous_can_sym (x - e) (x + e))//.
by apply: subset_itv_oo_cc; near: y.
near: y; apply: (filter_app _ _ nearfx); near_simpl; near=> y => yfe.
have : {within f @`]x - e, (x + e)[, continuous g}.
apply: continuous_subspaceW; last exact: (segment_can_continuous _ fwcte _).
exact: subset_itv_oo_cc.
rewrite continuous_open_subspace; first by apply; exact: mem_set.
exact: interval_open.
Unshelve. all: by end_near. Qed.
Lemma near_can_continuous f g (x : R) :
{near x, cancel f g} -> {near x, continuous f} -> {near f x, continuous g}.
Proof. by move=> fK fct; have [] := near_can_continuousAcan_sym fK fct. Qed.
Lemma near_continuous_can_sym f g (x : R) :
{near x, continuous f} -> {near x, cancel f g} -> {near f x, cancel g f}.
Proof. by move=> fct fK; have [] := near_can_continuousAcan_sym fK fct. Qed.
End real_inverse_functions.
Section real_inverse_function_instances.
Variable R : realType.
Lemma exprn_continuous n : continuous (@GRing.exp R ^~ n).
Proof.
move=> x; elim: n=> [|n /(continuousM cvg_id) ih]; first exact: cst_continuous.
by rewrite exprS; under eq_fun do rewrite exprS; exact: ih.
Qed.
Lemma sqr_continuous : continuous (@exprz R ^~ 2).
Proof. exact: (@exprn_continuous 2%N). Qed.
Lemma sqrt_continuous : continuous (@Num.sqrt R).
Proof.
move=> x; case: (ltrgtP x 0) => [xlt0 | xgt0 | ->].
- apply: (near_cst_continuous 0).
by near do rewrite ltr0_sqrtr//; apply: (cvgr_lt x).
pose I b : set R := [set` `]0 ^+ 2, b ^+ 2[].
suff main b : 0 <= b -> {in I b, continuous (@Num.sqrt R)}.
near +oo_R => M; apply: (main M); rewrite // /I !inE/= in_itv/= expr0n xgt0.
by rewrite -ltr_sqrt ?exprn_gt0// sqrtr_sqr gtr0_norm/=.
move=> b0; rewrite -continuous_open_subspace; last exact: interval_open.
apply: continuous_subspaceW; first exact: subset_itv_oo_cc.
apply: (@segment_can_le_continuous _ _ _ (@GRing.exp _^~ _)) => //.
by apply: continuous_subspaceT; exact: exprn_continuous.
by move=> y y0b; rewrite sqrtr_sqr ger0_norm// (itvP y0b).
- rewrite sqrtr0; apply/cvgr0Pnorm_lt => _ /posnumP[e]; near=> y.
have [ylt0|yge0] := ltrP y 0; first by rewrite ltr0_sqrtr ?normr0.
rewrite ger0_norm ?sqrtr_ge0//; have: `|y| < e%:num ^+ 2 by [].
by rewrite -ltr_sqrt// ger0_norm// sqrtr_sqr ger0_norm.
Unshelve. all: by end_near. Qed.
End real_inverse_function_instances.
Section is_derive_inverse.
Variable R : realType.
(* Attempt to prove the diff of inverse *)
Lemma is_derive1_caratheodory (f : R -> R) (x a : R) :
is_derive x 1 f a <->
exists g, [/\ forall z, f z - f x = g z * (z - x),
{for x, continuous g} & g x = a].
Proof.
split => [Hd|[g [fxE Cg gxE]]].
exists (fun z => if z == x then a else (f(z) - f(x)) / (z - x)); split.
- move=> z; case: eqP => [->|/eqP]; first by rewrite !subrr mulr0.
by rewrite -subr_eq0 => /divfK->.
- apply/continuous_withinNshiftx; rewrite eqxx /=.
pose g1 h := (h^-1 *: ((f \o shift x) h%:A - f x)).
have F1 : g1 @ 0^' --> a by case: Hd => H1 <-.
apply: cvg_trans F1; apply: near_eq_cvg; rewrite /g1 !fctE.
near=> i.
rewrite ifN; first by rewrite addrK mulrC /= [_%:A]mulr1.
rewrite -subr_eq0 addrK.
by near: i; rewrite near_withinE /= near_simpl; near=> x1.
by rewrite eqxx.
suff Hf : h^-1 *: ((f \o shift x) h%:A - f x) @[h --> 0^'] --> a.
have F1 : 'D_1 f x = a by apply: cvg_lim.
rewrite -F1 in Hf.
by constructor.
have F1 : (g \o shift x) y @[y --> 0^'] --> a.
by rewrite -gxE; apply/continuous_withinNshiftx.
apply: cvg_trans F1; apply: near_eq_cvg.
near=> y.
rewrite /= fxE /= addrK [_%:A]mulr1.
suff yNZ : y != 0 by rewrite [RHS]mulrC mulfK.
by near: y; rewrite near_withinE /= near_simpl; near=> x1.
Unshelve. all: by end_near. Qed.
Lemma is_derive_0_is_cst (f : R -> R) x y :
(forall x, is_derive x 1 f 0) -> f x = f y.
Proof.
move=> Hd.
wlog xLy : x y / x <= y by move=> H; case: (leP x y) => [/H |/ltW /H].
rewrite -(subKr (f y) (f x)).
have [| _ _] := MVT_segment xLy; last by rewrite mul0r => ->; rewrite subr0.
apply/continuous_subspaceT=> r.
exact/differentiable_continuous/derivable1_diffP.
Qed.
Global Instance is_derive1_comp (f g : R -> R) (x a b : R) :
is_derive (g x) 1 f a -> is_derive x 1 g b ->
is_derive x 1 (f \o g) (a * b).
Proof.
move=> [fgxv <-{a}] [gv <-{b}]; apply: (@DeriveDef _ _ _ _ _ (f \o g)).
apply/derivable1_diffP/differentiable_comp; first exact/derivable1_diffP.
by move/derivable1_diffP in fgxv.
by rewrite -derive1E (derive1_comp gv fgxv) 2!derive1E.
Qed.
Lemma is_deriveV (f : R -> R) (x t v : R) :
f x != 0 -> is_derive x v f t ->
is_derive x v (fun y => (f y)^-1) (- (f x) ^- 2 *: t).
Proof.
move=> fxNZ Df.
constructor; first by apply: derivableV => //; case: Df.
by rewrite deriveV //; case: Df => _ ->.
Qed.
Lemma is_derive_inverse (f g : R -> R) l x :
{near x, cancel f g} ->
{near x, continuous f} ->
is_derive x 1 f l -> l != 0 -> is_derive (f x) 1 g l^-1.
Proof.
move=> fgK fC fD lNZ.
have /is_derive1_caratheodory [h [fE hC hxE]] := fD.
(* There should be something simpler *)
have gfxE : g (f x) = x by have [d Hd]:= nbhs_ex fgK; apply: Hd.
pose g1 y := if y == f x then (h (g y))^-1
else (g y - g (f x)) / (y - f x).
apply/is_derive1_caratheodory.
exists g1; split; first 2 last.
- by rewrite /g1 eqxx gfxE hxE.
- move=> z; rewrite /g1; case: eqP => [->|/eqP]; first by rewrite !subrr mulr0.
by rewrite -subr_eq0 => /divfK.
have F1 : (h (g x))^-1 @[x --> f x] --> g1 (f x).
rewrite /g1 eqxx; apply: continuousV; first by rewrite /= gfxE hxE.
apply: continuous_comp; last by rewrite gfxE.
by apply: nbhs_singleton (near_can_continuous _ _).
apply: cvg_sub0 F1.
apply/cvgrPdist_lt => eps eps_gt0 /=; rewrite !near_simpl /=.
near=> y; rewrite sub0r normrN !fctE.
have fgyE : f (g y) = y by near: y; apply: near_continuous_can_sym.
rewrite /g1; case: eqP => [_|/eqP x1Dfx]; first by rewrite subrr normr0.
have -> : y - f x = h (g y) * (g y - x) by rewrite -fE fgyE.
rewrite gfxE invfM mulrC divfK ?subrr ?normr0 // subr_eq0.
by apply: contra x1Dfx => /eqP<-; apply/eqP.
Unshelve. all: by end_near. Qed.
End is_derive_inverse.
#[global] Hint Extern 0 (is_derive _ _ (fun _ => (_ _)^-1) _) =>
(eapply is_deriveV; first by []) : typeclass_instances.
From mathcomp Require Import path.
Require Import sequences.
Notation "'nondecreasing_fun' f" := ({homo f : n m / (n <= m)%R >-> (n <= m)%R})
(at level 10).
Notation "'nonincreasing_fun' f" := ({homo f : n m / (n <= m)%R >-> (n >= m)%R})
(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 ler_oppr opprK h.
by rewrite -(opprK (f n)) -ler_oppr 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; rewrite [in X in _ <-> X](_ : f = (\- (\- f))); last first.
by apply/funext => x /=; rewrite opprK.
exact: nondecreasing_funN.
Qed.
Lemma has_ubound_ereal_sup {R : realType} T (A : set T) (f : T -> R) :
[set f x | x in A] !=set0 ->
has_ubound [set f x | x in A] -> (ereal_sup [set (f x)%:E | x in A] < +oo)%E.
Proof. by move=> A0 ubA; rewrite -image_comp ereal_sup_EFin// ltry. Qed.
Lemma sup_le {R : realType} (S : set R) x : has_ubound S ->
(exists2 y, S y & x <= y) -> x <= sup S.
Proof.
by move=> uS [y Sy] /le_trans; apply; apply: sup_ub.
Qed.
(* NB: already in master? *)
Lemma ereal_sup_le {R : realType} (S : set (\bar R)) x :
(exists2 y, S y & x <= y)%E -> (x <= ereal_sup S)%E.
Proof. by move=> [y Sy] /le_trans; apply; exact: ereal_sup_ub. Qed.
Lemma ereal_supy {R : realType} (A : set \bar R) :
A +oo%E -> ereal_sup A = +oo%E.
Proof.
by move=> Aoo; apply/eqP; rewrite eq_le leey/=; exact: ereal_sup_ub.
Qed.
Section division.
Context {R : realType}.
(* a :: t is a division of [a, b] *)
Definition division (a b : R) t := [/\ path <%R a t & last a t == b].
Lemma division_nil a b : division a b [::] -> a = b.
Proof. by move=> [_ /eqP <-]. Qed.
Lemma division1 a b : a < b -> division a b [:: b].
Proof. by rewrite /division /= => ->. Qed.
Lemma division_cons a b t : (size t > 0)%N -> division a b t -> a < b.
Proof.
elim: t a => // x [_ a _|y t ih a _]; rewrite /division /=.
by rewrite andbT => -[ax /eqP <-].
move=> [] /andP[ax /andP[xy] h /eqP tb].
by rewrite (lt_trans ax)// ih// /division /= xy/= tb.
Qed.
Lemma divisionxx a l : division a a l -> l = [::].
Proof.
case: l => //= h t [/= /andP[ah /lt_path_min/allP ht] /eqP hta].
suff : h < a by move/lt_trans => /(_ _ ah); rewrite ltxx.
apply/ht; rewrite -hta.
by have := mem_last h t; rewrite inE hta lt_eqF.
Qed.
Lemma division_le (a b : R) l : division a b l -> a <= b.
Proof.
by case: l => [/division_nil ->//|h t /division_cons - /(_ _)/ltW]; apply.
Qed.
Lemma division_tail (a b x : R) l : division a b (x :: l) -> division x b l.
Proof. by rewrite /division/= => -[/andP[]]. Qed.
Lemma division_cat a b c l1 l2:
division a b l1 -> division b c l2 -> division a c (l1 ++ l2).
Proof.
rewrite /division => -[al1 /eqP l1b] [bl2 l2c].
by rewrite cat_path// al1 /= last_cat l1b.
Qed.
Lemma division_nth_size def a b s : division a b s ->
nth def (a :: s) (size s) = b.
Proof.
by elim: s a => [a/= /division_nil//|y t ih a /= /division_tail/ih].
Qed.
Lemma division_nth_ge a b l m : (m < (size l).+1)%N -> division a b l ->
a <= nth b (a :: l) m.
Proof.
elim: m l a b => [l a b _//|n ih [//|l1 l2] a b].
rewrite ltnS => nh [/= /andP[al1 l1l2] lb].
by rewrite (le_trans (ltW al1))// ih.
Qed.
Lemma division_nth_le a b l m : (m < (size l).+1)%N -> division a b l ->
nth b (a :: l) m <= b.
Proof.
elim: m l a => [l a _|n ih]; first exact: division_le.
move=> [//|a h t /= nt] H.
by rewrite ih//; exact: division_tail H.
Qed.
Lemma nondecreasing_fun_division a b f s :
{in `[a, b] &, nondecreasing_fun f} -> division a b s ->
let F : nat -> R := f \o nth b (a :: s) in
forall k, (k < size s)%N -> F k <= F k.+1.
Proof.
move=> ndf abs F k ks.
have [_] := nondecreasing_seqP F; apply => m n mn; rewrite /F/=.
have [ms|ms] := ltnP m (size s).+1; last first.
rewrite nth_default//.
have [|ns] := ltnP n (size s).+1; last by rewrite nth_default.
by move=> /(leq_ltn_trans mn); rewrite ltnS leqNgt ms.
have [ns|ns] := ltnP n (size s).+1; last first.
rewrite [in leRHS]nth_default//=; apply/ndf/division_nth_le => //.
by rewrite in_itv/= division_nth_le// andbT division_nth_ge.
by rewrite in_itv/= lexx andbT; exact: (division_le abs).
move: abs; rewrite /division => -[] sa sab.
move: mn; rewrite leq_eqVlt => /predU1P[->//|mn].
apply/ndf/ltW/sorted_ltn_nth => //=; last exact: lt_trans.
by rewrite in_itv/= division_nth_le// andbT division_nth_ge.
by rewrite in_itv/= division_nth_le// andbT division_nth_ge.
Qed.
Lemma nonincreasing_fun_division a b f s :
{in `[a, b] &, nonincreasing_fun f} -> division a b s ->
let F : nat -> R := f \o nth b (a :: s) in
forall k, (k < size s)%N -> F k.+1 <= F k.
Proof.
move/nonincreasing_funN => ndNf abs F k ks; rewrite -(opprK (F k)) ler_oppr.
exact: (nondecreasing_fun_division ndNf abs).
Qed.
Definition variation a b (f : R -> R) (s : seq R) : R :=
let F := f \o nth b (a :: s) in
\sum_(0 <= n < size s) `|F n.+1 - F n|%R.
Lemma variationE a b f s : division a b s ->
variation a b f s = \sum_(x <- zip s (a :: s)) `|f x.1 - f x.2|.
Proof.
elim: s a b => // [a b|h t ih a b].
rewrite /division /= => -[_ /eqP <-].
by rewrite /variation/= !big_nil.
rewrite /division /variation => -[]/= /andP[ah ht] /eqP htb.
rewrite big_nat_recl//=.
rewrite big_cons/=.
congr +%R.
have /ih : division h b t by split => //; exact/eqP.
rewrite /variation => ->.
by rewrite !big_seq; apply/eq_bigr => r rt.
Qed.
Lemma variation_nil a b f : variation a b f [::] = 0.
Proof. by rewrite /variation/= big_nil. Qed.
Lemma variation_ge0 a b f s : 0 <= variation a b f s.
Proof. exact/sumr_ge0. Qed.
Lemma variationN a b f s : variation a b (\- f) s = variation a b f s.
Proof.
by rewrite /variation; apply: eq_bigr => k _ /=; rewrite -opprD normrN.
Qed.
Lemma variation_le a b (f g : R -> R) s :
variation a b (f \+ g)%R s <= variation a b f s + variation a b g s.
Proof.
rewrite [in leRHS]/variation -big_split/=.
apply: ler_sum => k _; apply: le_trans; last exact: ler_norm_add.
by rewrite /= addrACA addrA opprD addrA.
Qed.
Lemma nondecreasing_variation (a b : R) (f : R -> R) l :
{in `[a, b] &, nondecreasing_fun f} -> division a b l -> variation a b f l = f b - f a.
Proof.
move=> ndf abl; rewrite /variation; set F : nat -> R := f \o nth _ (a :: l).
transitivity (\sum_(0 <= n < size l) (F n.+1 - F n)).
rewrite !big_nat; apply: eq_bigr => k; rewrite leq0n/= => kl.
by rewrite ger0_norm// subr_ge0; apply: nondecreasing_fun_division.
by rewrite telescope_sumr// /F/= (division_nth_size _ abl).
Qed.
Lemma nonincreasing_variation (a b : R) (f : R -> R) l :
{in `[a, b] &, nonincreasing_fun f} -> division a b l -> variation a b f l = f a - f b.
Proof.
move=> /nonincreasing_funN ndNf abs; have := nondecreasing_variation ndNf abs.
by rewrite opprK addrC => <-; rewrite variationN.
Qed.
Lemma variationD a b c f s t : a <= c -> c <= b ->
division a c s -> division c b t ->
variation a c f s + variation c b f t = variation a b f (s ++ t).
Proof.
rewrite le_eqVlt => /predU1P[<-{c} cb|ac].
by move=> /divisionxx ->; rewrite variation_nil add0r.
rewrite le_eqVlt => /predU1P[<-{b}|cb].
by move=> ? /divisionxx ->; rewrite variation_nil addr0 cats0.
move=> acs cbt; rewrite /variation /= [in RHS]/index_iota subn0 size_cat.
rewrite iotaD add0n big_cat/= -[in X in _ = X + _](subn0 (size s)); congr +%R.
rewrite -/(index_iota 0 (size s)) 2!big_nat.
apply: eq_bigr => k /[!leq0n] /= ks.
rewrite nth_cat ks -cat_cons nth_cat /= ltnS (ltnW ks).
by rewrite !(set_nth_default b c)//= ltnS ltnW.
rewrite -[in RHS](addnK (size s) (size t)).
rewrite -/(index_iota (size s) (size t + size s)).
rewrite -{1}[in RHS](add0n (size s)) big_addn addnK 2!big_nat; apply: eq_bigr.
move=> k /[!leq0n]/= kt.
rewrite nth_cat {1}(addnC k) -ltn_subRL subnn ltn0 addnK.
case: k kt => [t0 /=|k kt].
rewrite add0n -cat_cons nth_cat/= ltnS leqnn -last_nth.
by case: acs => _ /eqP ->.
rewrite addSnnS (addnC k) -cat_cons nth_cat/= -ltn_subRL subnn ltn0.
by rewrite -(addnC k) addnK.
Qed.
Definition variations a b f := [set variation a b f l | l in division a b].
Lemma variations_variation a b f s : division a b s ->
variations a b f (variation a b f s).
Proof. by move=> abs; exists s. Qed.
Lemma variations_neq0 a b f : a < b -> variations a b f !=set0.
Proof.
move=> ab; exists (variation a b f [:: b]); exists [:: b] => //.
exact: division1.
Qed.
Lemma variationsN a b f : variations a b (\- f) = variations a b f.
Proof.
apply/seteqP; split => [_ [s abs] <-|r [s abs]].
by rewrite variationN; exact: variations_variation.
by rewrite -variationN => <-; exact: variations_variation.
Qed.
Lemma variationsxx a f : variations a a f = [set 0].
Proof.
apply/seteqP; split => [x [_ /divisionxx ->]|x ->].
by rewrite /variation big_nil => <-.
by exists [::] => //=; rewrite /variation /= big_nil.
Qed.
Definition bounded_variation a b f := has_ubound (variations a b f).
Notation BV := bounded_variation.
Lemma bounded_variationxx a f : BV a a f.
Proof. by exists 0 => r; rewrite variationsxx => ->. Qed.
Lemma bounded_variationD a b f g : a < b ->
BV a b f -> BV a b g -> BV a b (f \+ g).
Proof.
move=> ab [r abfr] [s abgs]; exists (r + s) => _ [l abl] <-.
apply: le_trans; first exact: variation_le.
rewrite ler_add//.
- by apply: abfr; exact: variations_variation.
- by apply: abgs; exact: variations_variation.
Qed.
Lemma bounded_variationN a b f :
bounded_variation a b f -> bounded_variation a b (\- f).
Proof. by rewrite /bounded_variation variationsN. Qed.
Lemma bounded_variationl a c b f : a <= c -> c <= b -> BV a b f -> BV a c f.
Proof.
rewrite le_eqVlt => /predU1P[<-{c} ? ?|ac]; first exact: bounded_variationxx.
rewrite le_eqVlt => /predU1P[<-{b}//|cb].
move=> [x Hx]; exists x => _ [s acs] <-.
rewrite (@le_trans _ _ (variation a b f (rcons s b)))//; last first.
apply/Hx/variations_variation; case: acs => sa /eqP asc.
by rewrite /division rcons_path last_rcons sa/= asc.
rewrite {2}/variation size_rcons -[leLHS]addr0 big_nat_recr//= ler_add//.
rewrite /variation !big_nat ler_sum// => k; rewrite leq0n /= => ks.
rewrite nth_rcons// ks -cats1 -cat_cons nth_cat /= ltnS (ltnW ks).
by rewrite //= ltnS ltnW.
Qed.
Lemma bounded_variationr a c b f : a <= c -> c <= b -> BV a b f -> BV c b f.
Proof.
rewrite le_eqVlt => /predU1P[<-{c}//|ac].
rewrite le_eqVlt => /predU1P[<-{b} ?|cb]; first exact: bounded_variationxx.
move=> [x Hx]; exists x => _ [s cbs] <-.
rewrite (@le_trans _ _ (variation a b f (c :: s)))//; last first.
apply/Hx/variations_variation; case: cbs => cs csb.
by rewrite /division/= ac/= cs.
by rewrite {2}/variation/= -[leLHS]add0r big_nat_recl//= ler_add.
Qed.
Definition total_variation a b f :=
ereal_sup [set x%:E | x in variations a b f].
Notation TV := total_variation.
Lemma total_variationxx a f : TV a a f = 0%E.
Proof. by rewrite /total_variation variationsxx image_set1 ereal_sup1. Qed.
Lemma total_variation_ge a b f : a <= b -> (`|f b - f a|%:E <= TV a b f)%E.
Proof.
rewrite le_eqVlt => /predU1P[<-{b}|ab].
by rewrite total_variationxx subrr normr0.
apply: ereal_sup_ub => /=; exists (variation a b f [:: b]).
exact/variations_variation/division1.
by rewrite /variation/= big_nat_recr//= big_nil add0r.
Qed.
Lemma total_variation_ge0 a b f : a <= b -> (0 <= TV a b f)%E.
Proof. by move=> ab; rewrite (le_trans _ (total_variation_ge _ ab)). Qed.
Lemma nondecreasing_total_variation (a b : R) (f : R -> R) : a <= b ->
{in `[a, b] &, nondecreasing_fun f} -> TV a b f = (f b - f a)%:E.
Proof.
rewrite le_eqVlt => /predU1P[<-{b} ?|ab ndf].
by rewrite total_variationxx subrr.
rewrite /total_variation [X in ereal_sup X](_ : _ = [set (f b - f a)%:E]).
by rewrite ereal_sup1.
apply/seteqP; split => [x/= [s [t abt <-{s} <-{x}]]|x/= ->{x}].
by rewrite nondecreasing_variation.
exists (variation a b f [:: b]) => //.
exact/variations_variation/division1.
by rewrite nondecreasing_variation//; exact: division1.
Qed.
Lemma bounded_variationP a b f : a <= b -> BV a b f <-> TV a b f \is a fin_num.
Proof.
rewrite le_eqVlt => /predU1P[<-{b}|ab].
by rewrite total_variationxx; split => // ?; exact: bounded_variationxx.
rewrite ge0_fin_numE; last exact/total_variation_ge0/ltW.
split => [abf|].
apply: has_ubound_ereal_sup => //.
by rewrite image_id; exact: variations_neq0.
by rewrite image_id.
rewrite /total_variation /bounded_variation.
rewrite ltey => /eqP; apply: contra_notP.
by move/hasNub_ereal_sup; apply; exact: variations_neq0.
Qed.
Lemma total_variationN a b f : TV a b (\- f) = TV a b f.
Proof. by rewrite /TV; rewrite variationsN. Qed.
Lemma total_variation_le a b f g : a <= b ->
(TV a b (f \+ g)%R <= TV a b f + TV a b g)%E.
Proof.
rewrite le_eqVlt => /predU1P[<-{b}|ab].
by rewrite !total_variationxx adde0.
have [abf|abf] := pselect (bounded_variation a b f); last first.
rewrite {2}/total_variation hasNub_ereal_sup//; last first.
exact: variations_neq0.
rewrite addye ?leey// -ltNye (@lt_le_trans _ _ 0%E)//.
exact/total_variation_ge0/ltW.
have [abg|abg] := pselect (bounded_variation a b g); last first.
rewrite {3}/total_variation hasNub_ereal_sup//; last first.
exact: variations_neq0.
rewrite addey ?leey// -ltNye (@lt_le_trans _ _ 0%E)//.
exact/total_variation_ge0/ltW.
move: abf abg => [r abfr] [s abgs].
have BVabfg : BV a b (f \+ g).
by apply: bounded_variationD => //; [exists r|exists s].
apply: ub_ereal_sup => y /= [r' [s' abs <-{r'} <-{y}]].
apply: (@le_trans _ _ (variation a b f s' + variation a b g s')%:E).