| 1 |
Require Import CoRN.algebra.RSetoid. |
| 2 |
Require Import CoRN.metric2.Metric. |
| 3 |
Require Import CoRN.metric2.UniformContinuity. |
| 4 |
From Coq Require Import QArith. |
| 5 |
Require Import CoRN.model.totalorder.QposMinMax |
| 6 |
CoRN.model.metric2.Qmetric CoRN.reals.fast.CRArith. |
| 7 |
|
| 8 |
(** The approximation function for CRplus results distributes a given error evenly |
| 9 |
among its two operands. This is a perfectly reasonable implementation choice, |
| 10 |
but it is conceptually arbitrary: any ratio works fine. Furthermore, when |
| 11 |
reasoning about particular uses of CRplus, different ratios can be more |
| 12 |
natural fits to the proof at hand. For instance, in the additivity proof for the Riemann |
| 13 |
integral implementation, having the error for the sum of two integrals distributed |
| 14 |
proportionally to the widths of the two contiguous ranges makes it nicely match the |
| 15 |
error for the full integral on both sides. |
| 16 |
|
| 17 |
For situations like these, we now do a very ad-hoc redefinition of addition with |
| 18 |
a user-specified error distribution ratio, and show that it is equivalent to the |
| 19 |
normal CRplus. *) |
| 20 |
|
| 21 |
Section uneven_CRplus. |
| 22 |
|
| 23 |
Variables |
| 24 |
(l r: Qpos) (* These are the error weights for x and y. *) |
| 25 |
(x y: CR). |
| 26 |
|
| 27 |
Let ll: Qpos := (l * Qpos_inv (l + r))%Qpos. |
| 28 |
Let rr: Qpos := (r * Qpos_inv (l + r))%Qpos. |
| 29 |
|
| 30 |
Let llrr: QposEq (ll + rr) (1#1). |
| 31 |
Proof. |
| 32 |
unfold ll, rr. simpl. |
| 33 |
unfold QposEq; simpl; field. intro. |
| 34 |
apply (Qpos_nonzero (l+r)%Qpos). |
| 35 |
assumption. |
| 36 |
Qed. |
| 37 |
|
| 38 |
Definition uneven_CRplus_approx (e: Qpos): Q_as_MetricSpace |
| 39 |
:= approximate x (Qpos2QposInf (e * ll)) + approximate y (Qpos2QposInf (e * rr)). |
| 40 |
|
| 41 |
Lemma uneven_CRplus_is_RegularFunction: is_RegularFunction_noInf _ uneven_CRplus_approx. |
| 42 |
Proof with auto. |
| 43 |
intros e1 e2. |
| 44 |
unfold uneven_CRplus_approx. simpl. |
| 45 |
assert (QposEq (e1 + e2) ((e1 * ll + e2 * ll) + (e1 * rr + e2 * rr))). |
| 46 |
{ unfold QposEq. |
| 47 |
transitivity (proj1_sig (e1 + e2)%Qpos * proj1_sig (ll + rr)%Qpos). |
| 48 |
unfold QposEq in llrr. rewrite llrr. simpl. ring. |
| 49 |
simpl. ring. } |
| 50 |
apply (ball_wd _ H _ _ (reflexivity _) _ _ (reflexivity _)). clear H. |
| 51 |
apply Qball_plus. |
| 52 |
apply (regFun_prf x (e1*ll)%Qpos (e2*ll)%Qpos). |
| 53 |
apply (regFun_prf y (e1*rr)%Qpos (e2*rr)%Qpos). |
| 54 |
Qed. |
| 55 |
|
| 56 |
Definition uneven_CRplus: CR := @mkRegularFunction Q_as_MetricSpace 0 _ uneven_CRplus_is_RegularFunction. |
| 57 |
|
| 58 |
Lemma uneven_CRplus_correct: (uneven_CRplus == x + y)%CR. |
| 59 |
Proof. |
| 60 |
simpl. |
| 61 |
apply regFunEq_equiv, regFunEq_e. intro e. |
| 62 |
unfold ball, Q_as_MetricSpace, Qball, QAbsSmall. |
| 63 |
rewrite approximate_CRplus... |
| 64 |
unfold uneven_CRplus_approx. |
| 65 |
setoid_replace (proj1_sig e + proj1_sig e) |
| 66 |
with (proj1_sig ((e * ll + (1#2) * e) + (e * rr + (1#2) * e)))%Qpos. |
| 67 |
apply Qball_plus; apply regFun_prf. |
| 68 |
simpl in llrr. |
| 69 |
transitivity (proj1_sig e + proj1_sig e * proj1_sig (ll + rr)%Qpos)... |
| 70 |
unfold QposEq in llrr. simpl in llrr. simpl. rewrite llrr. |
| 71 |
unfold canonical_names.equiv, stdlib_rationals.Q_eq. ring. |
| 72 |
unfold canonical_names.equiv, stdlib_rationals.Q_eq. simpl. ring. |
| 73 |
Qed. |
| 74 |
|
| 75 |
End uneven_CRplus. |