| 1 |
Require Import CoRN.algebra.RSetoid. |
| 2 |
Require Import CoRN.metric2.Metric. |
| 3 |
Require Import CoRN.metric2.UniformContinuity. |
| 4 |
From Coq Require Import Qabs. |
| 5 |
Require Import CoRN.reals.fast.CRArith CoRN.reals.fast.CRabs. |
| 6 |
|
| 7 |
(** Balls with real radii instead of rational radii. *) |
| 8 |
|
| 9 |
Open Scope CR_scope. |
| 10 |
|
| 11 |
Section contents. |
| 12 |
|
| 13 |
Context {M: MetricSpace}. |
| 14 |
|
| 15 |
Definition CRball (r: CR) (x y: M): Prop |
| 16 |
:= forall (q:Q), r <= ' q -> ball q x y. |
| 17 |
|
| 18 |
Global Instance proper: Proper (@msp_eq _ ==> @msp_eq _ ==> @msp_eq _ ==> iff) CRball. |
| 19 |
Proof. |
| 20 |
intros ?? E ?? F ?? G. |
| 21 |
split. intros. intros q H0. |
| 22 |
rewrite <- E in H0. |
| 23 |
specialize (H q H0). rewrite <- F, <- G. exact H. |
| 24 |
intros. intros q H0. |
| 25 |
rewrite E in H0. |
| 26 |
specialize (H q H0). rewrite F, G. exact H. |
| 27 |
Qed. |
| 28 |
|
| 29 |
Global Instance reflexive (r: CR): CRnonNeg r -> Reflexive (CRball r). |
| 30 |
Proof with auto. |
| 31 |
unfold CRball, Reflexive. |
| 32 |
intros. |
| 33 |
apply ball_refl. |
| 34 |
apply CRle_Qle. |
| 35 |
apply CRle_trans with r... |
| 36 |
apply -> CRnonNeg_le_0... |
| 37 |
Qed. |
| 38 |
|
| 39 |
Lemma zero (x y: M): msp_eq x y <-> CRball 0 x y. |
| 40 |
Proof with auto. |
| 41 |
split. intros H z zpos. |
| 42 |
apply (@ball_weak_le _ 0). apply CRle_Qle, zpos. |
| 43 |
exact H. intros. apply H. apply CRle_refl. |
| 44 |
Qed. |
| 45 |
|
| 46 |
Lemma weak_le (r r': CR): r <= r' -> forall x y, CRball r x y -> CRball r' x y. |
| 47 |
Proof. intros ??? E ??. apply E. apply CRle_trans with r'; assumption. Qed. |
| 48 |
|
| 49 |
Lemma rational (r: Q) (x y: M): ball r x y <-> CRball ('r) x y. |
| 50 |
Proof with auto. |
| 51 |
split... |
| 52 |
repeat intro. |
| 53 |
apply CRle_Qle in H0. |
| 54 |
apply ball_weak_le with r... |
| 55 |
intros. apply H, CRle_refl. |
| 56 |
Qed. |
| 57 |
|
| 58 |
End contents. |
| 59 |
|
| 60 |
(* In the CR metric space, CRball is what you'd expect. *) |
| 61 |
|
| 62 |
Lemma as_distance_bound (r x y: CR): CRball r x y <-> CRdistance x y <= r. |
| 63 |
Proof with auto. |
| 64 |
unfold CRball. |
| 65 |
rewrite <- CRdistance_CRle. |
| 66 |
assert ((forall x0 : Q, r <= ' x0 -> x - ' x0 <= y /\ y <= x + ' x0) <-> |
| 67 |
x - r <= y /\ y <= x + r). |
| 68 |
split; intros. |
| 69 |
- split. |
| 70 |
+ apply CRplus_le_l with (r - y). |
| 71 |
CRring_replace (r - y + (x - r)) (x - y). |
| 72 |
CRring_replace (r - y + y) r. |
| 73 |
apply (proj1 (Qle_CRle_r _ _)). |
| 74 |
intros. |
| 75 |
apply CRplus_le_l with (y - ' y'). |
| 76 |
CRring_replace (y - 'y' + (x - y)) (x - 'y'). |
| 77 |
CRring_replace (y - 'y' + 'y') y. |
| 78 |
now apply (H y'). |
| 79 |
+ apply CRplus_le_r with (-x). |
| 80 |
CRring_replace (x + r - x) r. |
| 81 |
apply (proj1 (Qle_CRle_r _ _)). intros. |
| 82 |
apply CRplus_le_l with x. |
| 83 |
CRring_replace (x + (y - x)) y... |
| 84 |
apply H... |
| 85 |
- split. |
| 86 |
apply CRle_trans with (x - r). |
| 87 |
apply CRplus_le_compat... |
| 88 |
apply CRle_refl. |
| 89 |
apply -> CRle_opp... |
| 90 |
apply H. |
| 91 |
apply CRle_trans with (x + r). |
| 92 |
apply H. |
| 93 |
apply CRplus_le_compat... |
| 94 |
apply CRle_refl. |
| 95 |
- split. intros. destruct H. apply H. |
| 96 |
intros; rewrite in_CRgball; intuition. |
| 97 |
intros. destruct H. |
| 98 |
rewrite <- in_CRgball. apply H2; assumption. |
| 99 |
Qed. (* todo: clean up *) |
| 100 |
|
| 101 |
Lemma gball_CRabs (r : Q) (x y : CR) : ball r x y <-> CRabs (x - y) <= ' r. |
| 102 |
Proof. rewrite rational. apply as_distance_bound. Qed. |
| 103 |
|
| 104 |
Lemma gball_CRmult_Q (e a : Q) (x y : CR) : |
| 105 |
ball e x y -> ball (Qabs a * e) ('a * x) ('a * y). |
| 106 |
Proof. |
| 107 |
intro A. apply gball_CRabs. |
| 108 |
setoid_replace ('a * x - 'a * y) with ('a * (x - y)) |
| 109 |
by (unfold canonical_names.equiv, msp_Equiv; ring). |
| 110 |
rewrite CRabs_CRmult_Q, <- CRmult_Qmult. |
| 111 |
assert (0 <= 'Qabs a) by (apply CRle_Qle, Qabs_nonneg). |
| 112 |
apply (orders.order_preserving (CRmult (' Qabs a))). |
| 113 |
now apply gball_CRabs. |
| 114 |
Qed. |
| 115 |
|
| 116 |
Lemma gball_CRmult_Q_nonneg (e a : Q) (x y : CR) : |
| 117 |
(0 <= a)%Q -> ball e x y -> ball (a * e) ('a * x) ('a * y). |
| 118 |
Proof. |
| 119 |
intros A1 A2. rewrite <- (Qabs_pos a) at 1; [apply gball_CRmult_Q |]; easy. |
| 120 |
Qed. |
| 121 |
|
| 122 |
Module notations. |
| 123 |
|
| 124 |
Notation CRball := CRball. |
| 125 |
|
| 126 |
End notations. |