/
normedtype.v
4121 lines (3591 loc) · 167 KB
/
normedtype.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. *)
Require Reals.
From mathcomp Require Import ssreflect ssrfun ssrbool ssrnat eqtype choice.
From mathcomp Require Import seq fintype bigop order ssralg ssrint ssrnum finmap.
From mathcomp Require Import matrix interval zmodp.
Require Import boolp ereal reals Rstruct.
Require Import classical_sets posnum topology prodnormedzmodule.
(******************************************************************************)
(* This file extends the topological hierarchy with norm-related notions. *)
(* *)
(* ball_ N == balls defined by the norm/absolute value N *)
(* *)
(* * Normed Topological Abelian groups: *)
(* pseudoMetricNormedZmodType R == interface type for a normed topological *)
(* Abelian group equipped with a norm *)
(* PseudoMetricNormedZmodule.Mixin nb == builds the mixin for a normed *)
(* topological Abelian group from the *)
(* compatibility between the norm and *)
(* balls; the carrier type must have a *)
(* normed Zmodule over a numDomainType. *)
(* *)
(* * Normed modules : *)
(* normedModType K == interface type for a normed module *)
(* structure over the numDomainType K. *)
(* NormedModMixin normZ == builds the mixin for a normed module *)
(* from the property of the linearity of *)
(* the norm; the carrier type must have a *)
(* pseudoMetricNormedZmodType structure *)
(* NormedModType K T m == packs the mixin m to build a *)
(* normedModType K; T must have canonical *)
(* pseudoMetricNormedZmodType K and *)
(* pseudoMetricType structures. *)
(* [normedModType K of T for cT] == T-clone of the normedModType K structure *)
(* cT. *)
(* [normedModType K of T] == clone of a canonical normedModType K *)
(* structure on T. *)
(* `|x| == the norm of x (notation from ssrnum). *)
(* ball_norm == balls defined by the norm. *)
(* locally_norm == neighborhoods defined by the norm. *)
(* *)
(* * Domination notations: *)
(* dominated_by h k f F == `|f| <= k * `|h|, near F *)
(* bounded_on f F == f is bounded near F *)
(* [bounded f x | x in A] == f is bounded on A, ie F := globally A *)
(* [locally [bounded f x | x in A] == f is locally bounded on A *)
(* bounded_set == set of bounded sets. *)
(* := [set A | [bounded x | x in A]] *)
(* bounded_fun == set of bounded functions. *)
(* := [set f | [bounded f x | x in setT]] *)
(* lipschitz_on f F == f is lipschitz near F *)
(* [lipschitz f x | x in A] == f is lipschitz on A *)
(* [locally [lipschitz f x | x in A] == f is locally lipschitz on A *)
(* k.-lipschitz_on f F == f is k.-lipschitz near F *)
(* k.-lipschitz_A f == f is k.-lipschitz on A *)
(* [locally k.-lipschitz_A f] == f is locally k.-lipschitz on A *)
(* *)
(* * Complete normed modules : *)
(* completeNormedModType K == interface type for a complete normed *)
(* module structure over a realFieldType *)
(* K. *)
(* [completeNormedModType K of T] == clone of a canonical complete normed *)
(* module structure over K on T. *)
(* *)
(* * Filters : *)
(* at_left x, at_right x == filters on real numbers for predicates *)
(* that locally hold on the left/right of *)
(* x. *)
(* ereal_locally' x == filter on extended real numbers that *)
(* corresponds to locally' x if x is a real *)
(* number and to predicates that are *)
(* eventually true if x is +oo/-oo. *)
(* ereal_locally x == same as ereal_locally' where locally' is *)
(* replaced with locally. *)
(* ereal_loc_seq x == sequence that converges to x in the set *)
(* of extended real numbers. *)
(* *)
(* * Extended real numbers: *)
(* ereal_topologicalType R == topology for extended real numbers over *)
(* R, a realFieldType *)
(* contract == order-preserving bijective function *)
(* from extended real numbers to [-1;1] *)
(* ereal_pseudoMetricType R == pseudometric space for extended reals *)
(* over R where is a realFieldType; the *)
(* distance between x and y is defined by *)
(* `|contract x - contract y| *)
(* *)
(* --> We used these definitions to prove the intermediate value theorem and *)
(* the Heine-Borel theorem, which states that the compact sets of R^n are *)
(* the closed and bounded sets. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
(********************************)
(* Missing lemmas for mathcommp *)
(********************************)
Section MonoHomoMorphismTheory_in.
Variables (aT rT : predArgType) (aD : {pred aT}) (rD : {pred rT}).
Variables (f : aT -> rT) (g : rT -> aT) (aR : rel aT) (rR : rel rT).
Hypothesis fgK : {in rD, {on aD, cancel g & f}}.
Hypothesis mem_g : {homo g : x / x \in rD >-> x \in aD}.
Lemma homoRL_in :
{in aD &, {homo f : x y / aR x y >-> rR x y}} ->
{in rD & aD, forall x y, aR (g x) y -> rR x (f y)}.
Proof. by move=> Hf x y hx hy /Hf; rewrite fgK ?mem_g// ?inE; apply. Qed.
Lemma homoLR_in :
{in aD &, {homo f : x y / aR x y >-> rR x y}} ->
{in aD & rD, forall x y, aR x (g y) -> rR (f x) y}.
Proof. by move=> Hf x y hx hy /Hf; rewrite fgK ?mem_g// ?inE; apply. Qed.
Lemma homo_mono_in :
{in aD &, {homo f : x y / aR x y >-> rR x y}} ->
{in rD &, {homo g : x y / rR x y >-> aR x y}} ->
{in rD &, {mono g : x y / rR x y >-> aR x y}}.
Proof.
move=> mf mg x y hx hy; case: (boolP (rR _ _))=> [/mg //|]; first exact.
by apply: contraNF=> /mf; rewrite !fgK ?mem_g//; apply.
Qed.
Lemma monoLR_in :
{in aD &, {mono f : x y / aR x y >-> rR x y}} ->
{in aD & rD, forall x y, rR (f x) y = aR x (g y)}.
Proof. by move=> mf x y hx hy; rewrite -{1}[y]fgK ?mem_g// mf ?mem_g. Qed.
Lemma monoRL_in :
{in aD &, {mono f : x y / aR x y >-> rR x y}} ->
{in rD & aD, forall x y, rR x (f y) = aR (g x) y}.
Proof. by move=> mf x y hx hy; rewrite -{1}[x]fgK ?mem_g// mf ?mem_g. Qed.
Lemma can_mono_in :
{in aD &, {mono f : x y / aR x y >-> rR x y}} ->
{in rD &, {mono g : x y / rR x y >-> aR x y}}.
Proof. by move=> mf x y hx hy; rewrite -mf ?mem_g// !fgK ?mem_g. Qed.
End MonoHomoMorphismTheory_in.
Arguments homoRL_in {aT rT aD rD f g aR rR}.
Arguments homoLR_in {aT rT aD rD f g aR rR}.
Arguments homo_mono_in {aT rT aD rD f g aR rR}.
Arguments monoLR_in {aT rT aD rD f g aR rR}.
Arguments monoRL_in {aT rT aD rD f g aR rR}.
Arguments can_mono_in {aT rT aD rD f g aR rR}.
Section onW_can.
Variables (aT rT : predArgType) (aD : {pred aT}) (rD : {pred rT}).
Variables (f : aT -> rT) (g : rT -> aT).
Lemma onW_can : cancel g f -> {on aD, cancel g & f}.
Proof. by move=> fgK x xaD; apply: fgK. Qed.
Lemma onW_can_in : {in rD, cancel g f} -> {in rD, {on aD, cancel g & f}}.
Proof. by move=> fgK x xrD xaD; apply: fgK. Qed.
Lemma in_onW_can : cancel g f -> {in rD, {on aD, cancel g & f}}.
Proof. by move=> fgK x xrD xaD; apply: fgK. Qed.
Lemma onT_can : (forall x, g x \in aD) -> {on aD, cancel g & f} -> cancel g f.
Proof. by move=> mem_g fgK x; apply: fgK. Qed.
Lemma onT_can_in : {homo g : x / x \in rD >-> x \in aD} ->
{in rD, {on aD, cancel g & f}} -> {in rD, cancel g f}.
Proof. by move=> mem_g fgK x x_rD; apply/fgK/mem_g. Qed.
Lemma in_onT_can : (forall x, g x \in aD) ->
{in rT, {on aD, cancel g & f}} -> cancel g f.
Proof. by move=> mem_g fgK x; apply/fgK. Qed.
End onW_can.
Arguments onW_can {aT rT} aD {f g}.
Arguments onW_can_in {aT rT} aD {rD f g}.
Arguments in_onW_can {aT rT} aD rD {f g}.
Arguments onT_can {aT rT} aD {f g}.
Arguments onW_can_in {aT rT} aD {rD f g}.
Arguments in_onT_can {aT rT} aD {f g}.
Section inj_can_sym_in_on.
Variables (aT rT : predArgType) (aD : {pred aT}) (rD : {pred rT}).
Variables (f : aT -> rT) (g : rT -> aT).
Lemma inj_can_sym_in_on : {homo f : x / x \in aD >-> x \in rD} ->
{in aD, {on rD, cancel f & g}} ->
{in [pred x | x \in rD & g x \in aD], injective g} ->
{in rD, {on aD, cancel g & f}}.
Proof. by move=> fD fK gI x x_rD gx_aD; apply: gI; rewrite ?inE ?fK ?fD. Qed.
Lemma inj_can_sym_on : {in aD, cancel f g} ->
{in [pred x | g x \in aD], injective g} -> {on aD, cancel g & f}.
Proof. by move=> fK gI x gx_aD; apply: gI; rewrite ?inE ?fK. Qed.
Lemma inj_can_sym_in : {homo f \o g : x / x \in rD} -> {on rD, cancel f & g} ->
{in rD, injective g} -> {in rD, cancel g f}.
Proof. by move=> fgD fK gI x x_rD; apply: gI; rewrite ?fK ?fgD. Qed.
End inj_can_sym_in_on.
Arguments inj_can_sym_in_on {aT rT aD rD f g}.
Arguments inj_can_sym_on {aT rT aD f g}.
Arguments inj_can_sym_in {aT rT rD f g}.
(*************************)
(* Mathcomp analysis now *)
(*************************)
Import Order.TTheory GRing.Theory Num.Def Num.Theory.
Local Open Scope ring_scope.
Section add_to_mathcomp.
Lemma ltr_distW (R : realDomainType) (x y e : R) :
`|x - y| < e -> y - e < x.
Proof. by rewrite ltr_distl => /andP[]. Qed.
Lemma ler_distW (R : realDomainType) (x y e : R):
`|x - y| <= e -> y - e <= x.
Proof. by rewrite ler_distl => /andP[]. Qed.
End add_to_mathcomp.
Local Open Scope classical_set_scope.
Definition ball_
(R : numDomainType) (V : zmodType) (norm : V -> R) (x : V) (e : R) :=
[set y | norm (x - y) < e].
Arguments ball_ {R} {V} norm x e%R y /.
Definition pointed_of_zmodule (R : zmodType) : pointedType := PointedType R 0.
Definition filtered_of_normedZmod (K : numDomainType) (R : normedZmodType K)
: filteredType R := Filtered.Pack (Filtered.Class
(@Pointed.class (pointed_of_zmodule R)) (locally_ (ball_ (fun x => `|x|)))).
Section pseudoMetric_of_normedDomain.
Variables (K : numDomainType) (R : normedZmodType K).
Lemma ball_norm_center (x : R) (e : K) : 0 < e -> ball_ normr x e x.
Proof. by move=> ? /=; rewrite subrr normr0. Qed.
Lemma ball_norm_symmetric (x y : R) (e : K) :
ball_ normr x e y -> ball_ normr y e x.
Proof. by rewrite /= distrC. Qed.
Lemma ball_norm_triangle (x y z : R) (e1 e2 : K) :
ball_ normr x e1 y -> ball_ normr y e2 z -> ball_ normr x (e1 + e2) z.
Proof.
move=> /= ? ?; rewrite -(subr0 x) -(subrr y) opprD opprK (addrA x _ y) -addrA.
by rewrite (le_lt_trans (ler_norm_add _ _)) // ltr_add.
Qed.
Definition pseudoMetric_of_normedDomain
: PseudoMetric.mixin_of K (@locally_ K R R (ball_ (fun x => `|x|)))
:= PseudoMetricMixin ball_norm_center ball_norm_symmetric ball_norm_triangle erefl.
End pseudoMetric_of_normedDomain.
Canonical R_pointedType := [pointedType of
Rdefinitions.R for pointed_of_zmodule R_ringType].
(* NB: similar definition in topology.v *)
Canonical R_filteredType := [filteredType Rdefinitions.R of
Rdefinitions.R for filtered_of_normedZmod R_normedZmodType].
Canonical R_topologicalType : topologicalType := TopologicalType Rdefinitions.R
(topologyOfBallMixin (pseudoMetric_of_normedDomain R_normedZmodType)).
Canonical R_pseudoMetricType : pseudoMetricType R_numDomainType :=
PseudoMetricType Rdefinitions.R (pseudoMetric_of_normedDomain R_normedZmodType).
Section numFieldType_canonical.
Variable R : numFieldType.
(*Canonical topological_of_numFieldType := [numFieldType of R^o].*)
Canonical numFieldType_pointedType :=
[pointedType of R^o for pointed_of_zmodule R].
Canonical numFieldType_filteredType :=
[filteredType R of R^o for filtered_of_normedZmod R].
Canonical numFieldType_topologicalType : topologicalType := TopologicalType R^o
(topologyOfBallMixin (pseudoMetric_of_normedDomain [normedZmodType R of R])).
Canonical numFieldType_pseudoMetricType := @PseudoMetric.Pack R R^o (@PseudoMetric.Class R R
(Topological.class numFieldType_topologicalType) (@pseudoMetric_of_normedDomain R R)).
Definition numdFieldType_lalgType : lalgType R := @GRing.regular_lalgType R.
End numFieldType_canonical.
Lemma locallyN (R : numFieldType) (x : R^o) :
locally (- x) = [set [set - y | y in A] | A in locally x].
Proof.
rewrite predeqE => A; split=> [[e egt0 oppxe_A]|[B [e egt0 xe_B] <-]];
last first.
exists e => // y xe_y; exists (- y); last by rewrite opprK.
apply/xe_B.
by rewrite /ball_ opprK -normrN -mulN1r mulrDr !mulN1r.
exists [set - y | y in A]; last first.
rewrite predeqE => y; split=> [[z [t At <- <-]]|Ay]; first by rewrite opprK.
by exists (- y); [exists y|rewrite opprK].
exists e => // y xe_y; exists (- y); last by rewrite opprK.
by apply/oppxe_A; rewrite /ball_ distrC opprK addrC.
Qed.
Lemma openN (R : numFieldType) (A : set R^o) :
open A -> open [set - x | x in A].
Proof.
move=> Aop; rewrite openE => _ [x /Aop x_A <-].
by rewrite /interior locallyN; exists A.
Qed.
Lemma closedN (R : numFieldType) (A : set R^o) :
closed A -> closed [set - x | x in A].
Proof.
move=> Acl x clNAx.
suff /Acl : closure A (- x) by exists (- x)=> //; rewrite opprK.
move=> B oppx_B; have : [set - x | x in A] `&` [set - x | x in B] !=set0.
by apply: clNAx; rewrite -[x]opprK locallyN; exists B.
move=> [y [[z Az oppzey] [t Bt opptey]]]; exists (- y).
by split; [rewrite -oppzey opprK|rewrite -opptey opprK].
Qed.
Module PseudoMetricNormedZmodule.
Section ClassDef.
Variable R : numDomainType.
Record mixin_of (T : normedZmodType R) (loc : T -> set (set T))
(m : PseudoMetric.mixin_of R loc) := Mixin {
_ : PseudoMetric.ball m = ball_ (fun x => `| x |) }.
Record class_of (T : Type) := Class {
base : Num.NormedZmodule.class_of R T;
pointed_mixin : Pointed.point_of T ;
locally_mixin : Filtered.locally_of T T ;
topological_mixin : @Topological.mixin_of T locally_mixin ;
pseudoMetric_mixin : @PseudoMetric.mixin_of R T locally_mixin ;
mixin : @mixin_of (Num.NormedZmodule.Pack _ base) _ pseudoMetric_mixin
}.
Local Coercion base : class_of >-> Num.NormedZmodule.class_of.
Definition base2 T c := @PseudoMetric.Class _ _
(@Topological.Class _
(Filtered.Class
(Pointed.Class (@base T c) (pointed_mixin c))
(locally_mixin c))
(topological_mixin c))
(pseudoMetric_mixin c).
Local Coercion base2 : class_of >-> PseudoMetric.class_of.
(* TODO: base3? *)
Structure type (phR : phant R) :=
Pack { sort; _ : class_of sort }.
Local Coercion sort : type >-> Sortclass.
Variables (phR : phant R) (T : Type) (cT : type phR).
Definition class := let: Pack _ c := cT return class_of cT in c.
Definition clone c of phant_id class c := @Pack phR T c.
Let xT := let: Pack T _ := cT in T.
Notation xclass := (class : class_of xT).
Definition pack (b0 : Num.NormedZmodule.class_of R T) lm0 um0
(m0 : @mixin_of (@Num.NormedZmodule.Pack R (Phant R) T b0) lm0 um0) :=
fun bT (b : Num.NormedZmodule.class_of R T)
& phant_id (@Num.NormedZmodule.class R (Phant R) bT) b =>
fun uT (u : PseudoMetric.class_of R T) & phant_id (@PseudoMetric.class R uT) u =>
fun (m : @mixin_of (Num.NormedZmodule.Pack _ b) _ u) & phant_id m m0 =>
@Pack phR T (@Class T b u u u u m).
Definition eqType := @Equality.Pack cT xclass.
Definition choiceType := @Choice.Pack cT xclass.
Definition zmodType := @GRing.Zmodule.Pack cT xclass.
Definition normedZmodType := @Num.NormedZmodule.Pack R phR cT xclass.
Definition pointedType := @Pointed.Pack cT xclass.
Definition filteredType := @Filtered.Pack xT cT xclass.
Definition topologicalType := @Topological.Pack cT xclass.
Definition pseudoMetricType := @PseudoMetric.Pack R cT xclass.
Definition pointed_zmodType := @GRing.Zmodule.Pack pointedType xclass.
Definition filtered_zmodType := @GRing.Zmodule.Pack filteredType xclass.
Definition topological_zmodType := @GRing.Zmodule.Pack topologicalType xclass.
Definition pseudoMetric_zmodType := @GRing.Zmodule.Pack pseudoMetricType xclass.
Definition pointed_normedZmodType := @Num.NormedZmodule.Pack R phR pointedType xclass.
Definition filtered_normedZmodType := @Num.NormedZmodule.Pack R phR filteredType xclass.
Definition topological_normedZmodType := @Num.NormedZmodule.Pack R phR topologicalType xclass.
Definition pseudoMetric_normedZmodType := @Num.NormedZmodule.Pack R phR pseudoMetricType xclass.
End ClassDef.
(*Definition numDomain_normedDomainType (R : numDomainType) : type (Phant R) :=
Pack (Phant R) (@Class R _ _ (NumDomain.normed_mixin (NumDomain.class R))).*)
Module Exports.
Coercion base : class_of >-> Num.NormedZmodule.class_of.
Coercion base2 : class_of >-> PseudoMetric.class_of.
Coercion sort : type >-> Sortclass.
Coercion eqType : type >-> Equality.type.
Canonical eqType.
Coercion choiceType : type >-> Choice.type.
Canonical choiceType.
Coercion zmodType : type >-> GRing.Zmodule.type.
Canonical zmodType.
Coercion normedZmodType : type >-> Num.NormedZmodule.type.
Canonical normedZmodType.
Coercion pointedType : type >-> Pointed.type.
Canonical pointedType.
Coercion filteredType : type >-> Filtered.type.
Canonical filteredType.
Coercion topologicalType : type >-> Topological.type.
Canonical topologicalType.
Coercion pseudoMetricType : type >-> PseudoMetric.type.
Canonical pseudoMetricType.
Canonical pointed_zmodType.
Canonical filtered_zmodType.
Canonical topological_zmodType.
Canonical pseudoMetric_zmodType.
Canonical pointed_normedZmodType.
Canonical filtered_normedZmodType.
Canonical topological_normedZmodType.
Canonical pseudoMetric_normedZmodType.
Notation pseudoMetricNormedZmodType R := (type (Phant R)).
Notation PseudoMetricNormedZmodType R T m :=
(@pack _ (Phant R) T _ _ _ m _ _ idfun _ _ idfun _ idfun).
Notation "[ 'pseudoMetricNormedZmodType' R 'of' T 'for' cT ]" :=
(@clone _ (Phant R) T cT _ idfun)
(at level 0, format "[ 'pseudoMetricNormedZmodType' R 'of' T 'for' cT ]") :
form_scope.
Notation "[ 'pseudoMetricNormedZmodType' R 'of' T ]" :=
(@clone _ (Phant R) T _ _ idfun)
(at level 0, format "[ 'pseudoMetricNormedZmodType' R 'of' T ]") : form_scope.
End Exports.
End PseudoMetricNormedZmodule.
Export PseudoMetricNormedZmodule.Exports.
Section pseudoMetricnormedzmodule_lemmas.
Context {K : numDomainType} {V : pseudoMetricNormedZmodType K}.
Local Notation ball_norm := (ball_ (@normr K V)).
Lemma ball_normE : ball_norm = ball.
Proof. by case: V => ? [? ? ? ? ? []]. Qed.
End pseudoMetricnormedzmodule_lemmas.
Section numFieldType_canonical_contd.
Variable R : numFieldType.
Lemma R_ball : @ball _ [pseudoMetricType R of R^o] = ball_ (fun x => `| x |).
Proof. by []. Qed.
Definition numFieldType_pseudoMetricNormedZmodMixin :=
PseudoMetricNormedZmodule.Mixin R_ball.
Canonical numFieldType_pseudoMetricNormedZmodType :=
@PseudoMetricNormedZmodType R R^o numFieldType_pseudoMetricNormedZmodMixin.
End numFieldType_canonical_contd.
(** locally *)
Section Locally.
Context {R : numDomainType} {T : pseudoMetricType R}.
Lemma forallN {U} (P : set U) : (forall x, ~ P x) = ~ exists x, P x.
Proof. (*boolP*)
rewrite propeqE; split; first by move=> fP [x /fP].
by move=> nexP x Px; apply: nexP; exists x.
Qed.
Lemma eqNNP (P : Prop) : (~ ~ P) = P. (*boolP*)
Proof. by rewrite propeqE; split=> [/contrapT|?]. Qed.
Lemma existsN {U} (P : set U) : (exists x, ~ P x) = ~ forall x, P x. (*boolP*)
Proof.
rewrite propeqE; split=> [[x Px] Nall|Nall]; first exact: Px.
by apply: contrapT; rewrite -forallN => allP; apply: Nall => x; apply: contrapT.
Qed.
End Locally.
Section Locally'.
Context {R : numDomainType} {T : pseudoMetricType R}.
Lemma ex_ball_sig (x : T) (P : set T) :
~ (forall eps : {posnum R}, ~ (ball x eps%:num `<=` ~` P)) ->
{d : {posnum R} | ball x d%:num `<=` ~` P}.
Proof.
rewrite forallN eqNNP => exNP.
pose D := [set d : R | d > 0 /\ ball x d `<=` ~` P].
have [|d_gt0] := @getPex _ D; last by exists (PosNum d_gt0).
by move: exNP => [e eP]; exists e%:num.
Qed.
Lemma locallyC (x : T) (P : set T) :
~ (forall eps : {posnum R}, ~ (ball x eps%:num `<=` ~` P)) ->
locally x (~` P).
Proof. by move=> /ex_ball_sig [e] ?; apply/locallyP; exists e%:num. Qed.
Lemma locallyC_ball (x : T) (P : set T) :
locally x (~` P) -> {d : {posnum R} | ball x d%:num `<=` ~` P}.
Proof.
move=> /locallyP xNP; apply: ex_ball_sig.
by have [_ /posnumP[e] eP /(_ _ eP)] := xNP.
Qed.
Lemma locally_ex (x : T) (P : T -> Prop) : locally x P ->
{d : {posnum R} | forall y, ball x d%:num y -> P y}.
Proof.
move=> /locallyP xP.
pose D := [set d : R | d > 0 /\ forall y, ball x d y -> P y].
have [|d_gt0 dP] := @getPex _ D; last by exists (PosNum d_gt0).
by move: xP => [e bP]; exists (e : R).
Qed.
End Locally'.
Lemma ler_addgt0Pr (R : numFieldType) (x y : R) :
reflect (forall e, e > 0 -> x <= y + e) (x <= y).
Proof.
apply/(iffP idP)=> [lexy _/posnumP[e] | lexye]; first by rewrite ler_paddr.
have [||ltyx]// := comparable_leP.
rewrite (@comparabler_trans _ (y + 1))// /Order.comparable ?lexye//.
by rewrite ler_addl ler01 orbT.
have /midf_lt [_] := ltyx; rewrite le_gtF//.
by rewrite -(@addrK _ y y) addrAC -addrA 2!mulrDl -splitr lexye// divr_gt0//
subr_gt0.
Qed.
Lemma ler_addgt0Pl (R : numFieldType) (x y : R) :
reflect (forall e, e > 0 -> x <= e + y) (x <= y).
Proof.
by apply/(equivP (ler_addgt0Pr x y)); split=> lexy e /lexy; rewrite addrC.
Qed.
Lemma in_segment_addgt0Pr (R : numFieldType) (x y z : R) :
reflect (forall e, e > 0 -> y \in `[(x - e), (z + e)]) (y \in `[x, z]).
Proof.
apply/(iffP idP)=> [xyz _/posnumP[e] | xyz_e].
rewrite inE/=; apply/andP; split; last by rewrite ler_paddr // (itvP xyz).
by rewrite ler_subl_addr ler_paddr // (itvP xyz).
rewrite inE/=; apply/andP.
by split; apply/ler_addgt0Pr => ? /xyz_e /andP /= []; rewrite ler_subl_addr.
Qed.
Lemma in_segment_addgt0Pl (R : numFieldType) (x y z : R) :
reflect (forall e, e > 0 -> y \in `[(- e + x), (e + z)]) (y \in `[x, z]).
Proof.
apply/(equivP (in_segment_addgt0Pr x y z)).
by split=> zxy e /zxy; rewrite [z + _]addrC [_ + x]addrC.
Qed.
Lemma coord_continuous {K : numFieldType} m n i j :
continuous (fun M : 'M[K^o]_(m.+1, n.+1) => M i j).
Proof.
move=> /= M s /= /(locallyP (M i j)); rewrite locally_E => -[e e0 es].
apply/locallyP; rewrite locally_E; exists e => //= N MN; exact/es/MN.
Qed.
Global Instance Proper_locally'_numFieldType (R : numFieldType) (x : R^o) :
ProperFilter (locally' x).
Proof.
apply: Build_ProperFilter => A [_/posnumP[e] Ae].
exists (x + e%:num / 2); apply: Ae; last first.
by rewrite eq_sym addrC -subr_eq subrr eq_sym.
rewrite /= opprD addrA subrr distrC subr0 ger0_norm //.
by rewrite {2}(splitr e%:num) ltr_spaddl.
Qed.
Global Instance Proper_locally'_realType (R : realType) (x : R^o) :
ProperFilter (locally' x).
Proof. exact: Proper_locally'_numFieldType. Qed.
(** * Some Topology on [Rbar] *)
Canonical ereal_pointed (R : numDomainType) := PointedType {ereal R} (+oo%E).
Section ereal_locally.
Context {R : numFieldType}.
Let R_topologicalType := [topologicalType of R^o].
Local Open Scope ereal_scope.
Definition ereal_locally' (a : {ereal R}) (P : {ereal R} -> Prop) : Prop :=
match a with
| a%:E => @locally' R_topologicalType a (fun x => P x%:E)
| +oo => exists M, M \is Num.real /\ forall x, (M%:E < x)%E -> P x
| -oo => exists M, M \is Num.real /\ forall x, (x < M%:E)%E -> P x
end.
Definition ereal_locally (a : {ereal R}) (P : {ereal R} -> Prop) : Prop :=
match a with
| a%:E => @locally _ R_topologicalType a (fun x => P x%:E)
| +oo => exists M, M \is Num.real /\ forall x, (M%:E < x)%E -> P x
| -oo => exists M, M \is Num.real /\ forall x, (x < M%:E)%E -> P x
end.
Canonical ereal_ereal_filter := FilteredType {ereal R} {ereal R} (ereal_locally).
End ereal_locally.
Section ereal_locally_instances.
Context {R : numFieldType}.
Let R_topologicalType := [topologicalType of R^o].
Global Instance ereal_locally'_filter :
forall x : {ereal R}, ProperFilter (ereal_locally' x).
Proof.
case=> [x||].
- case: (Proper_locally'_numFieldType x) => x0 [//= xT xI xS].
apply Build_ProperFilter' => //=; apply Build_Filter => //=.
move=> P Q lP lQ; exact: xI.
by move=> P Q PQ /xS; apply => y /PQ.
- apply Build_ProperFilter.
move=> P [x [xr xP]]; exists (x + 1)%:E; apply xP => /=.
by rewrite lte_fin ltr_addl.
split=> /= [|P Q [MP [MPr gtMP]] [MQ [MQr gtMQ]] |P Q sPQ [M [Mr gtM]]].
+ by exists 0; rewrite real0.
+ have [/eqP MP0|MP0] := boolP (MP == 0).
have [/eqP MQ0|MQ0] := boolP (MQ == 0).
by exists 0; rewrite real0; split => // x x0; split;
[apply/gtMP; rewrite MP0 | apply/gtMQ; rewrite MQ0].
exists `|MQ|; rewrite realE normr_ge0; split => // x Hx; split.
by apply gtMP; rewrite (le_lt_trans _ Hx) // MP0 lee_fin.
by apply gtMQ; rewrite (le_lt_trans _ Hx) // lee_fin real_ler_normr // lexx.
have [/eqP MQ0|MQ0] := boolP (MQ == 0).
exists `|MP|; rewrite realE normr_ge0; split => // x MPx; split.
by apply gtMP; rewrite (le_lt_trans _ MPx) // lee_fin real_ler_normr // lexx.
by apply gtMQ; rewrite (le_lt_trans _ MPx) // lee_fin MQ0.
have {}MP0 : 0 < `|MP| by rewrite normr_gt0.
have {}MQ0 : 0 < `|MQ| by rewrite normr_gt0.
exists (Num.max (PosNum MP0) (PosNum MQ0))%:num.
rewrite realE /= posnum_ge0 /=; split => //.
case=> [r| |//].
* rewrite lte_fin pos_ltUx /= => /andP[MPx MQx]; split.
by apply/gtMP; rewrite lte_fin (le_lt_trans _ MPx) // real_ler_normr // lexx.
by apply/gtMQ; rewrite lte_fin (le_lt_trans _ MQx) // real_ler_normr // lexx.
* by move=> _; split; [apply/gtMP | apply/gtMQ].
+ by exists M; split => // ? /gtM /sPQ.
- apply Build_ProperFilter.
+ move=> P [M [Mr ltMP]]; exists (M - 1)%:E.
by apply: ltMP; rewrite lte_fin gtr_addl oppr_lt0.
+ split=> /= [|P Q [MP [MPr ltMP]] [MQ [MQr ltMQ]] |P Q sPQ [M [Mr ltM]]].
* by exists 0; rewrite real0.
* have [/eqP MP0|MP0] := boolP (MP == 0).
have [/eqP MQ0|MQ0] := boolP (MQ == 0).
by exists 0; rewrite real0; split => // x x0; split;
[apply/ltMP; rewrite MP0 | apply/ltMQ; rewrite MQ0].
exists (- `|MQ|); rewrite realN realE normr_ge0; split => // x xMQ; split.
by apply ltMP; rewrite (lt_le_trans xMQ) // lee_fin MP0 ler_oppl oppr0.
apply ltMQ; rewrite (lt_le_trans xMQ) // lee_fin ler_oppl -normrN.
by rewrite real_ler_normr ?realN // lexx.
* have [/eqP MQ0|MQ0] := boolP (MQ == 0).
exists (- `|MP|); rewrite realN realE normr_ge0; split => // x MPx; split.
apply ltMP; rewrite (lt_le_trans MPx) // lee_fin ler_oppl -normrN.
by rewrite real_ler_normr ?realN // lexx.
by apply ltMQ; rewrite (lt_le_trans MPx) // lee_fin MQ0 ler_oppl oppr0.
have {}MP0 : 0 < `|MP| by rewrite normr_gt0.
have {}MQ0 : 0 < `|MQ| by rewrite normr_gt0.
exists (- (Num.max (PosNum MP0) (PosNum MQ0))%:num).
rewrite realN realE /= posnum_ge0 /=; split => //.
case=> [r|//|].
- rewrite lte_fin ltr_oppr pos_ltUx => /andP[].
rewrite ltr_oppr => MPx; rewrite ltr_oppr => MQx; split.
apply/ltMP; rewrite lte_fin (lt_le_trans MPx) //= ler_oppl -normrN.
by rewrite real_ler_normr ?realN // lexx.
apply/ltMQ; rewrite lte_fin (lt_le_trans MQx) //= ler_oppl -normrN.
by rewrite real_ler_normr ?realN // lexx.
- by move=> _; split; [apply/ltMP | apply/ltMQ].
* by exists M; split => // x /ltM /sPQ.
Qed.
Typeclasses Opaque ereal_locally'.
Global Instance ereal_locally_filter :
forall x, ProperFilter (@ereal_locally R x).
Proof.
case=> [x| |].
- case: (ereal_locally'_filter x%:E) => x0 [//=nxT xI xS].
apply Build_ProperFilter => //=.
by move=> P [r r0 xr]; exists x%:E; apply xr => //=; rewrite subrr normr0.
apply Build_Filter => //=.
by rewrite locallyE'.
move=> P Q.
rewrite !locallyE' => -[xP axP] [xQ axQ]; split => //=.
exact: xI.
move=> P Q PQ; rewrite !locallyE' => -[xP axP]; split => //=.
apply (xS P) => //=.
exact: PQ.
exact: (ereal_locally'_filter +oo).
exact: (ereal_locally'_filter -oo).
Qed.
Typeclasses Opaque ereal_locally.
End ereal_locally_instances.
Section ereal_topologicalType.
Variable R : realFieldType.
Lemma ereal_loc_singleton (p : {ereal R}) (A : set {ereal R}) :
ereal_locally p A -> A p.
Proof.
move: p => -[p | [M [Mreal MA]] | [M [Mreal MA]]] /=; [|exact: MA | exact: MA].
move/locallyP; rewrite locally_E => -[_/posnumP[e]]; apply; exact/ballxx.
Qed.
Lemma ereal_loc_loc (p : {ereal R}) (A : set {ereal R}) :
ereal_locally p A -> ereal_locally p (ereal_locally^~ A).
Proof.
move: p => -[p| [M [Mreal MA]] | [M [Mreal MA]]] //=.
- move/locallyP; rewrite locally_E => -[_/posnumP[e]] ballA.
apply/locallyP; rewrite locally_E; exists (e%:num / 2) => //= r per.
apply/locallyP; rewrite locally_E; exists (e%:num / 2) => //= x rex.
apply/ballA/(@ball_splitl _ _ r) => //; exact/ball_sym.
- exists (M + 1); split; first by rewrite realD // real1.
move=> -[x| _ |] //=.
rewrite lte_fin => M'x /=.
apply/locallyP; rewrite locally_E; exists 1 => //= y x1y.
apply MA; rewrite lte_fin.
rewrite addrC -ltr_subr_addl in M'x.
rewrite (lt_le_trans M'x) // ler_subl_addl addrC -ler_subl_addl.
rewrite (le_trans _ (ltW x1y)) // real_ler_norm // realB //.
rewrite ltr_subr_addr in M'x.
rewrite -comparabler0 (@comparabler_trans _ (M + 1)) //.
by rewrite /Order.comparable (ltW M'x) orbT.
by rewrite comparabler0 realD // real1.
by rewrite num_real. (* where we really use realFieldType *)
by exists M.
- exists (M - 1); split; first by rewrite realB // real1.
move=> -[x| _ |] //=.
rewrite lte_fin => M'x /=.
apply/locallyP; rewrite locally_E; exists 1 => //= y x1y.
apply MA; rewrite lte_fin.
rewrite ltr_subr_addl in M'x.
rewrite (le_lt_trans _ M'x) // addrC -ler_subl_addl.
rewrite (le_trans _ (ltW x1y)) // distrC real_ler_norm // realB //.
by rewrite num_real. (* where we really use realFieldType *)
rewrite addrC -ltr_subr_addr in M'x.
rewrite -comparabler0 (@comparabler_trans _ (M - 1)) //.
by rewrite /Order.comparable (ltW M'x).
by rewrite comparabler0 realB // real1.
by exists M.
Qed.
Definition ereal_topologicalMixin : Topological.mixin_of (@ereal_locally R) :=
topologyOfFilterMixin _ ereal_loc_singleton ereal_loc_loc.
Canonical ereal_topologicalType := TopologicalType _ ereal_topologicalMixin.
End ereal_topologicalType.
Definition pinfty_locally (R : numFieldType) : set (set R) :=
fun P => exists M, M \is Num.real /\ forall x, M < x -> P x.
Arguments pinfty_locally R : clear implicits.
Definition ninfty_locally (R : numFieldType) : set (set R) :=
fun P => exists M, M \is Num.real /\ forall x, x < M -> P x.
Arguments ninfty_locally R : clear implicits.
Notation "+oo" := (pinfty_locally _) : ring_scope.
Notation "-oo" := (ninfty_locally _) : ring_scope.
Section infty_locally_instances.
Context {R : numFieldType}.
Let R_topologicalType := [topologicalType of R^o].
Global Instance proper_pinfty_locally : ProperFilter (pinfty_locally R).
Proof.
apply Build_ProperFilter.
by move=> P [M [Mreal MP]]; exists (M + 1); apply MP; rewrite ltr_addl.
split=> /= [|P Q [MP [MPr gtMP]] [MQ [MQr gtMQ]] |P Q sPQ [M [Mr gtM]]].
- by exists 0; rewrite real0.
- have [/eqP MP0|MP0] := boolP (MP == 0).
have [/eqP MQ0|MQ0] := boolP (MQ == 0).
by exists 0; rewrite real0; split => // x x0; split;
[apply/gtMP; rewrite MP0 | apply/gtMQ; rewrite MQ0].
exists `|MQ|; rewrite realE normr_ge0; split => // x Hx; split.
by apply gtMP; rewrite (le_lt_trans _ Hx) // MP0.
by apply gtMQ; rewrite (le_lt_trans _ Hx) // real_ler_normr // lexx.
have [/eqP MQ0|MQ0] := boolP (MQ == 0).
exists `|MP|; rewrite realE normr_ge0; split => // x MPx; split.
by apply gtMP; rewrite (le_lt_trans _ MPx) // real_ler_normr // lexx.
by apply gtMQ; rewrite (le_lt_trans _ MPx) // MQ0.
have {}MP0 : 0 < `|MP| by rewrite normr_gt0.
have {}MQ0 : 0 < `|MQ| by rewrite normr_gt0.
exists (Num.max (PosNum MP0) (PosNum MQ0))%:num.
rewrite realE /= posnum_ge0 /=; split => // x.
rewrite pos_ltUx /= => /andP[MPx MQx]; split.
by apply/gtMP; rewrite (le_lt_trans _ MPx) // real_ler_normr // lexx.
by apply/gtMQ; rewrite (le_lt_trans _ MQx) // real_ler_normr // lexx.
- by exists M; split => // ? /gtM /sPQ.
Defined.
Typeclasses Opaque proper_pinfty_locally.
Global Instance proper_ninfty_locally : ProperFilter (ninfty_locally R).
Proof.
apply Build_ProperFilter.
- move=> P [M [Mr ltMP]]; exists (M - 1).
by apply: ltMP; rewrite gtr_addl oppr_lt0.
- split=> /= [|P Q [MP [MPr ltMP]] [MQ [MQr ltMQ]] |P Q sPQ [M [Mr ltM]]].
+ by exists 0; rewrite real0.
+ have [/eqP MP0|MP0] := boolP (MP == 0).
have [/eqP MQ0|MQ0] := boolP (MQ == 0).
by exists 0; rewrite real0; split => // x x0; split;
[apply/ltMP; rewrite MP0 | apply/ltMQ; rewrite MQ0].
exists (- `|MQ|); rewrite realN realE normr_ge0; split => // x xMQ; split.
by apply ltMP; rewrite (lt_le_trans xMQ) // MP0 ler_oppl oppr0.
apply ltMQ; rewrite (lt_le_trans xMQ) // ler_oppl -normrN.
by rewrite real_ler_normr ?realN // lexx.
+ have [/eqP MQ0|MQ0] := boolP (MQ == 0).
exists (- `|MP|); rewrite realN realE normr_ge0; split => // x MPx; split.
apply ltMP; rewrite (lt_le_trans MPx) // ler_oppl -normrN.
by rewrite real_ler_normr ?realN // lexx.
by apply ltMQ; rewrite (lt_le_trans MPx) // MQ0 ler_oppl oppr0.
have {}MP0 : 0 < `|MP| by rewrite normr_gt0.
have {}MQ0 : 0 < `|MQ| by rewrite normr_gt0.
exists (- (Num.max (PosNum MP0) (PosNum MQ0))%:num).
rewrite realN realE /= posnum_ge0 /=; split => // x.
rewrite ltr_oppr pos_ltUx => /andP[].
rewrite ltr_oppr => MPx; rewrite ltr_oppr => MQx; split.
apply/ltMP; rewrite (lt_le_trans MPx) //= ler_oppl -normrN.
by rewrite real_ler_normr ?realN // lexx.
apply/ltMQ; rewrite (lt_le_trans MQx) //= ler_oppl -normrN.
by rewrite real_ler_normr ?realN // lexx.
+ by exists M; split => // x /ltM /sPQ.
Defined.
Typeclasses Opaque proper_ninfty_locally.
(*Global Instance ereal_locally'_filter :
forall x : {ereal R}, ProperFilter (ereal_locally' x).
Proof.
case=> [x||]; first exact: Proper_locally'_numFieldType.
- apply Build_ProperFilter.
by move=> P [M [Mreal MP]]; exists (M + 1); apply MP; rewrite ltr_addl.
split=> /= [|P Q [MP [MPr gtMP]] [MQ [MQr gtMQ]] |P Q sPQ [M [Mr gtM]]].
+ by exists 0; rewrite real0.
+ have [/eqP MP0|MP0] := boolP (MP == 0).
have [/eqP MQ0|MQ0] := boolP (MQ == 0).
by exists 0; rewrite real0; split => // x x0; split;
[apply/gtMP; rewrite MP0 | apply/gtMQ; rewrite MQ0].
exists `|MQ|; rewrite realE normr_ge0; split => // x Hx; split.
by apply gtMP; rewrite (le_lt_trans _ Hx) // MP0.
by apply gtMQ; rewrite (le_lt_trans _ Hx) // real_ler_normr // lexx.
have [/eqP MQ0|MQ0] := boolP (MQ == 0).
exists `|MP|; rewrite realE normr_ge0; split => // x MPx; split.
by apply gtMP; rewrite (le_lt_trans _ MPx) // real_ler_normr // lexx.
by apply gtMQ; rewrite (le_lt_trans _ MPx) // MQ0.
have {}MP0 : 0 < `|MP| by rewrite normr_gt0.
have {}MQ0 : 0 < `|MQ| by rewrite normr_gt0.
exists (Num.max (PosNum MP0) (PosNum MQ0))%:num.
rewrite realE /= posnum_ge0 /=; split => // x.
rewrite pos_ltUx /= => /andP[MPx MQx]; split.
by apply/gtMP; rewrite (le_lt_trans _ MPx) // real_ler_normr // lexx.
by apply/gtMQ; rewrite (le_lt_trans _ MQx) // real_ler_normr // lexx.
+ by exists M; split => // ? /gtM /sPQ.
- apply Build_ProperFilter.
+ move=> P [M [Mr ltMP]]; exists (M - 1).
by apply: ltMP; rewrite gtr_addl oppr_lt0.
+ split=> /= [|P Q [MP [MPr ltMP]] [MQ [MQr ltMQ]] |P Q sPQ [M [Mr ltM]]].
* by exists 0; rewrite real0.
* have [/eqP MP0|MP0] := boolP (MP == 0).
have [/eqP MQ0|MQ0] := boolP (MQ == 0).
by exists 0; rewrite real0; split => // x x0; split;
[apply/ltMP; rewrite MP0 | apply/ltMQ; rewrite MQ0].
exists (- `|MQ|); rewrite realN realE normr_ge0; split => // x xMQ; split.
by apply ltMP; rewrite (lt_le_trans xMQ) // MP0 ler_oppl oppr0.
apply ltMQ; rewrite (lt_le_trans xMQ) // ler_oppl -normrN.
by rewrite real_ler_normr ?realN // lexx.
* have [/eqP MQ0|MQ0] := boolP (MQ == 0).
exists (- `|MP|); rewrite realN realE normr_ge0; split => // x MPx; split.
apply ltMP; rewrite (lt_le_trans MPx) // ler_oppl -normrN.
by rewrite real_ler_normr ?realN // lexx.
by apply ltMQ; rewrite (lt_le_trans MPx) // MQ0 ler_oppl oppr0.
have {}MP0 : 0 < `|MP| by rewrite normr_gt0.
have {}MQ0 : 0 < `|MQ| by rewrite normr_gt0.
exists (- (Num.max (PosNum MP0) (PosNum MQ0))%:num).
rewrite realN realE /= posnum_ge0 /=; split => // x.
rewrite ltr_oppr pos_ltUx => /andP[].
rewrite ltr_oppr => MPx; rewrite ltr_oppr => MQx; split.
apply/ltMP; rewrite (lt_le_trans MPx) //= ler_oppl -normrN.
by rewrite real_ler_normr ?realN // lexx.
apply/ltMQ; rewrite (lt_le_trans MQx) //= ler_oppl -normrN.
by rewrite real_ler_normr ?realN // lexx.
* by exists M; split => // x /ltM /sPQ.
Qed.
Typeclasses Opaque ereal_locally'.*)
(*Global Instance ereal_locally_filter :
forall x, ProperFilter (@ereal_locally R x).
Proof.
case=> [x||].
exact: ereal_locally_filter.
exact: (ereal_locally'_filter +oo).
exact: (ereal_locally'_filter -oo).
Qed.
Typeclasses Opaque ereal_locally.*)
Lemma near_pinfty_div2 (A : set R) :
(\forall k \near +oo, A k) -> (\forall k \near +oo, A (k / 2)).
Proof.
move=> [M [Mreal AM]]; exists (M * 2); split.
by rewrite realM // realE; apply/orP; left.
by move=> x; rewrite -ltr_pdivl_mulr //; apply: AM.
Qed.
Lemma locally_pinfty_gt (c : {posnum R}) : \forall x \near +oo, c%:num < x.
Proof. by exists c%:num; split => // ; rewrite realE posnum_ge0. Qed.
Lemma locally_pinfty_ge (c : {posnum R}) : \forall x \near +oo, c%:num <= x.
Proof. by exists c%:num; rewrite realE posnum_ge0; split => //; apply: ltW. Qed.
Lemma locally_pinfty_gt_real (c : R) : c \is Num.real ->
\forall x \near +oo, c < x.
Proof. by exists c. Qed.
Lemma locally_pinfty_ge_real (c : R) : c \is Num.real ->
\forall x \near +oo, c <= x.
Proof. by exists c; split => //; apply: ltW. Qed.
Lemma locally_minfty_lt (c : {posnum R}) : \forall x \near -oo, c%:num > x.
Proof. by exists c%:num; split => // ; rewrite realE posnum_ge0. Qed.
Lemma locally_minfty_le (c : {posnum R}) : \forall x \near -oo, c%:num >= x.
Proof. by exists c%:num; rewrite realE posnum_ge0/=; split => // x; apply: ltW. Qed.
Lemma locally_minfty_lt_real (c : R) : c \is Num.real ->
\forall x \near -oo, c > x.
Proof. by exists c. Qed.
Lemma locally_minfty_le_real (c : R) : c \is Num.real ->
\forall x \near -oo, c >= x.
Proof. by exists c; split => // ?; apply: ltW. Qed.
End infty_locally_instances.
Hint Extern 0 (is_true (0 < _)) => match goal with
H : ?x \is_near (locally +oo) |- _ =>
solve[near: x; exists 0 => _/posnumP[x] //] end : core.
Lemma locallyNe (R : realFieldType) (x : {ereal R}) :
locally (- x)%E = [set [set (- y)%E | y in A] | A in locally x].
Proof.
case: x => [r /=| |].
- rewrite predeqE => S; split => [[_/posnumP[e] reS]|[S' [_ /posnumP[e] reS' <-]]].
exists (-%E @` S).
exists e%:num => // x rex; exists (- x%:E)%E; last by rewrite oppeK.
by apply reS; rewrite /= opprK -normrN opprD opprK.
rewrite predeqE => s; split => [[y [z Sz] <- <-]|Ss].
by rewrite oppeK.
by exists (- s)%E; [exists s | rewrite oppeK].
exists e%:num => // x rex; exists (- x%:E)%E; last by rewrite oppeK.
by apply reS'; rewrite /= opprK -normrN opprD.
- rewrite predeqE => S; split=> [[M [Mreal MS]]|[x [M [Mreal Mx]] <-]].
exists (-%E @` S).
exists (- M); rewrite realN Mreal; split => // x Mx.
by exists (- x)%E; [apply MS; rewrite lte_oppl | rewrite oppeK].
rewrite predeqE => x; split=> [[y [z Sz <- <-]]|Sx]; first by rewrite oppeK.
by exists (- x)%E; [exists x | rewrite oppeK].
exists (- M); rewrite realN; split => // y yM.
exists (- y)%E; by [apply Mx; rewrite lte_oppr|rewrite oppeK].
- rewrite predeqE => S; split=> [[M [Mreal MS]]|[x [M [Mreal Mx]] <-]].
exists (-%E @` S).
exists (- M); rewrite realN Mreal; split => // x Mx.
by exists (- x)%E; [apply MS; rewrite lte_oppr | rewrite oppeK].
rewrite predeqE => x; split=> [[y [z Sz <- <-]]|Sx]; first by rewrite oppeK.
by exists (- x)%E; [exists x | rewrite oppeK].
exists (- M); rewrite realN; split => // y yM.
exists (- y)%E; by [apply Mx; rewrite lte_oppl|rewrite oppeK].
Qed.
Lemma locallyNKe (R : realFieldType) (z : {ereal R}) (A : set {ereal R}) :
locally (- z)%E (-%E @` A) -> locally z A.
Proof.
rewrite locallyNe => -[S zS] SA; rewrite -(oppeK z) locallyNe.
exists (-%E @` S); first by rewrite locallyNe; exists S.
rewrite predeqE => x; split => [[y [u Su <-{y} <-]]|Ax].
rewrite oppeK.
move: SA; rewrite predeqE => /(_ (- u)%E) [h _].
have : (exists2 y : {ereal R}, S y & (- y)%E = (- u)%E) by exists u.
by move/h => -[y Ay] /eqP; rewrite eqe_opp => /eqP <-.
exists (- x)%E; last by rewrite oppeK.
exists x => //.
move: SA; rewrite predeqE => /(_ (- x)%E) [_ h].
have : (-%E @` A) (- x)%E by exists x.
by move/h => [y Sy] /eqP; rewrite eqe_opp => /eqP <-.
Qed.
Section contract_expand.
Variable R : realFieldType.
Definition contract (x : {ereal R}) : R :=
match x with
| r%:E => r / (1 + `|r|) | +oo%E => 1 | -oo%E => -1
end.
Lemma contract_lt1 x : `|contract x%:E| < 1.
Proof.
rewrite normrM normrV ?unitfE //; last by rewrite eq_sym lt_eqF // ltr_spaddl.
rewrite ltr_pdivr_mulr // ?mul1r; last by rewrite gtr0_norm ltr_spaddl.
by rewrite [X in _ < X]gtr0_norm ?ltr_addr// ltr_spaddl.
Qed.
Lemma contract_le1 x : `|contract x| <= 1.
Proof.
by case: x => [x| |] /=; rewrite ?normrN1 ?normr1 // (ltW (contract_lt1 _)).
Qed.
Lemma contract0 : contract 0%:E = 0.
Proof. by rewrite /contract mul0r. Qed.
Lemma contractN x : contract (- x) = - contract x.
Proof. by case: x => //= [r|]; [ rewrite normrN mulNr | rewrite opprK]. Qed.
Lemma contract_imageN (S : set {ereal R}) :
contract @` (-%E @` S) = -%R @` (contract @` S).
Proof.
rewrite predeqE => r; split => [[y [z Sz <-{y} <-{r}]]|[s [y Sy <-{s} <-{r}]]].
by exists (contract z); [exists z | rewrite contractN].
by exists (- y)%E; [exists y | rewrite contractN].
Qed.
(* TODO: not exploited yet: expand is nondecreasing everywhere so it should be
possible to use some of the homoRL/homoLR lemma where monoRL/monoLR do not
apply *)