| 1 |
Require Import |
| 2 |
CoRN.algebra.RSetoid |
| 3 |
CoRN.metric2.Metric |
| 4 |
CoRN.metric2.UniformContinuity |
| 5 |
CoRN.metric2.MetricMorphisms |
| 6 |
CoRN.reals.fast.CRarctan_small |
| 7 |
CoRN.reals.fast.CRarctan |
| 8 |
CoRN.reals.fast.CRpi_fast |
| 9 |
CoRN.reals.faster.ARpi |
| 10 |
CoRN.reals.faster.ARarctan_small. |
| 11 |
Require Export |
| 12 |
CoRN.reals.faster.ARArith. |
| 13 |
|
| 14 |
Section ARarctan. |
| 15 |
Context `{AppRationals AQ}. |
| 16 |
|
| 17 |
Lemma AQarctan_big_pos_prf (a : AQ) : 1 < a → 0 < a. |
| 18 |
Proof. |
| 19 |
intros. |
| 20 |
apply (orders.le_lt_trans _ 1). 2: exact H5. |
| 21 |
apply semirings.le_0_1. |
| 22 |
Qed. |
| 23 |
|
| 24 |
Lemma AQarctan_big_prf (a : AQ) : 1 < a → -a < 1 < a. |
| 25 |
Proof. |
| 26 |
split. 2: exact H5. |
| 27 |
transitivity 0. |
| 28 |
2: apply semirings.lt_0_1. |
| 29 |
rewrite <- rings.negate_0. |
| 30 |
apply (rings.flip_lt_negate 0 a). |
| 31 |
transitivity 1. 2: exact H5. |
| 32 |
apply semirings.lt_0_1. |
| 33 |
Qed. |
| 34 |
|
| 35 |
Definition AQarctan_big_pos {a : AQ} (Pa : 1 < a) : msp_car AR := |
| 36 |
AQpi (1 ≪ (-1)) - AQarctan_small (AQarctan_big_prf a Pa) |
| 37 |
(AQarctan_big_pos_prf a Pa). |
| 38 |
|
| 39 |
Lemma AQarctan_big_pos_correct {a : AQ} `(Pa : 1 < a) : |
| 40 |
'AQarctan_big_pos Pa = rational_arctan ('a). |
| 41 |
Proof. |
| 42 |
unfold AQarctan_big_pos. |
| 43 |
rewrite rings.preserves_minus. |
| 44 |
rewrite ARtoCR_preserves_AQpi. |
| 45 |
rewrite aq_shift_opp_1, rings.preserves_1. |
| 46 |
transitivity (r_pi (1 / 2)%mc - rational_arctan (/ ' a)). |
| 47 |
apply ucFun2_wd. reflexivity. |
| 48 |
rewrite AQarctan_small_correct. |
| 49 |
rewrite rational_arctan_small_correct. |
| 50 |
rewrite rational_arctan_correct. |
| 51 |
apply Cmap_wd. reflexivity. |
| 52 |
apply CRIR.IRasCR_wd, InvTrigonom.ArcTan_wd, Q_in_CReals.inj_Q_wd. |
| 53 |
now rewrite rings.preserves_1, rings.mult_1_l. |
| 54 |
apply rational_arctan_half_pi. |
| 55 |
transitivity (1:Q). |
| 56 |
now apply (semirings.lt_0_1 (R:=Q)). |
| 57 |
now apply semirings.preserves_gt_1. |
| 58 |
Qed. |
| 59 |
|
| 60 |
Lemma AQarctan_mid_prf (a : AQ) : 0 < a → -(a+1) < a-1 < a+1. |
| 61 |
Proof. |
| 62 |
split. |
| 63 |
- rewrite rings.negate_plus_distr. |
| 64 |
apply (strictly_order_preserving (+ _)). |
| 65 |
now apply rings.between_pos. |
| 66 |
- apply (strictly_order_preserving (_ +)). |
| 67 |
apply rings.between_pos. |
| 68 |
apply semirings.lt_0_1. |
| 69 |
Qed. |
| 70 |
|
| 71 |
Program Definition AQarctan_mid_pos {a : AQ} (Ha : 0 < a) : msp_car AR := |
| 72 |
AQpi (1 ≪ (-2)) + AQarctan_small (AQarctan_mid_prf a Ha) _. |
| 73 |
Next Obligation. |
| 74 |
transitivity (0+1). |
| 75 |
rewrite rings.plus_0_l. |
| 76 |
apply semirings.lt_0_1. |
| 77 |
apply (strictly_order_preserving (+ _)), Ha. |
| 78 |
Qed. |
| 79 |
|
| 80 |
Lemma AQarctan_mid_pos_correct {a : AQ} `(Pa : 0 < a) : |
| 81 |
'AQarctan_mid_pos Pa = rational_arctan ('a). |
| 82 |
Proof. |
| 83 |
unfold AQarctan_mid_pos. |
| 84 |
rewrite rings.preserves_plus. |
| 85 |
rewrite ARtoCR_preserves_AQpi. |
| 86 |
transitivity (r_pi (' (1 ≪ (-2))) + rational_arctan (('a - 1) / ('a + 1) : Q)). |
| 87 |
apply ucFun2_wd. reflexivity. |
| 88 |
rewrite AQarctan_small_correct. |
| 89 |
rewrite rational_arctan_small_correct. |
| 90 |
rewrite rational_arctan_correct. |
| 91 |
apply CRIR.IRasCR_wd, InvTrigonom.ArcTan_wd, Q_in_CReals.inj_Q_wd. |
| 92 |
mc_setoid_replace ('(a - 1) / '(a + 1) : Q) with (('a - 1) / ('a + 1) : Q). |
| 93 |
reflexivity. |
| 94 |
rewrite rings.preserves_minus, rings.preserves_plus. |
| 95 |
now rewrite rings.preserves_1. |
| 96 |
rewrite aq_shift_opp_2, rings.preserves_1. |
| 97 |
apply rational_arctan_fourth_pi. |
| 98 |
now apply semirings.preserves_pos. |
| 99 |
Qed. |
| 100 |
|
| 101 |
Lemma AQarctan_pos_prf1 {a : AQ} : 0 ≤ a → a ≤ 1 ≪ (-1) → -1 < a < 1. |
| 102 |
Proof. |
| 103 |
split. |
| 104 |
- apply (orders.lt_le_trans _ 0). 2: exact H5. |
| 105 |
rewrite <- rings.negate_0. |
| 106 |
apply (rings.flip_lt_negate 0 1). |
| 107 |
apply semirings.lt_0_1. |
| 108 |
- apply orders.le_lt_trans with (1 ≪ (-1)); [easy |]. |
| 109 |
apply (strictly_order_reflecting (cast AQ Q)). |
| 110 |
rewrite aq_shift_opp_1, rings.preserves_1. |
| 111 |
split; easy. |
| 112 |
Qed. |
| 113 |
|
| 114 |
Lemma AQarctan_pos_prf2 {a : AQ} : ¬a ≤ 1 ≪ (-1) → 0 < a. |
| 115 |
Proof. |
| 116 |
intros. apply orders.lt_le_trans with (1 ≪ (-1)). |
| 117 |
apply (strictly_order_reflecting (cast AQ Q)). |
| 118 |
rewrite aq_shift_opp_1, rings.preserves_0, rings.preserves_1. |
| 119 |
split; easy. |
| 120 |
now apply orders.le_flip. |
| 121 |
Qed. |
| 122 |
|
| 123 |
Lemma AQarctan_pos_prf3 {a : AQ} : ¬a ≤ 2 → 1 < a. |
| 124 |
Proof. |
| 125 |
intros. apply orders.lt_le_trans with 2. |
| 126 |
apply semirings.lt_1_2. |
| 127 |
now apply orders.le_flip. |
| 128 |
Qed. |
| 129 |
|
| 130 |
Definition AQarctan_pos {a : AQ} (Pa1 : 0 ≤ a) : msp_car AR := |
| 131 |
match decide_rel (≤) a (1 ≪ (-1)) with |
| 132 |
| left Pa2 => AQarctan_small (AQarctan_pos_prf1 Pa1 Pa2) semirings.lt_0_1 |
| 133 |
| right Pa2 => match decide_rel (≤) a 2 with |
| 134 |
| left Pa3 => AQarctan_mid_pos (AQarctan_pos_prf2 Pa2) |
| 135 |
| right Pa3 => AQarctan_big_pos (AQarctan_pos_prf3 Pa3) |
| 136 |
end |
| 137 |
end. |
| 138 |
|
| 139 |
Lemma AQarctan_pos_correct {a : AQ} `(Pa : 0 ≤ a) : |
| 140 |
'AQarctan_pos Pa = rational_arctan ('a). |
| 141 |
Proof. |
| 142 |
unfold AQarctan_pos. |
| 143 |
case (decide_rel _); intros. |
| 144 |
rewrite AQarctan_small_correct. |
| 145 |
rewrite rational_arctan_small_correct. |
| 146 |
rewrite rational_arctan_correct. |
| 147 |
apply CRIR.IRasCR_wd, InvTrigonom.ArcTan_wd, Q_in_CReals.inj_Q_wd. |
| 148 |
mc_setoid_replace (('a / '1)%mc : Q) with ('a). |
| 149 |
reflexivity. |
| 150 |
rewrite rings.preserves_1. |
| 151 |
rewrite dec_fields.dec_recip_1. |
| 152 |
now apply rings.mult_1_r. |
| 153 |
case (decide_rel _); intros. |
| 154 |
apply AQarctan_mid_pos_correct. |
| 155 |
apply AQarctan_big_pos_correct. |
| 156 |
Qed. |
| 157 |
|
| 158 |
Lemma AQarctan_prf {a : AQ} : ¬0 ≤ a → 0 ≤ - a. |
| 159 |
Proof. intros. apply rings.flip_nonpos_negate. now apply orders.le_flip. Qed. |
| 160 |
|
| 161 |
Definition AQarctan (a : AQ) : msp_car AR := |
| 162 |
match decide_rel (≤) 0 a with |
| 163 |
| left Pa => AQarctan_pos Pa |
| 164 |
| right Pa => -AQarctan_pos (AQarctan_prf Pa) |
| 165 |
end. |
| 166 |
|
| 167 |
Lemma AQarctan_correct (a : AQ) : |
| 168 |
'AQarctan a = rational_arctan ('a). |
| 169 |
Proof. |
| 170 |
unfold AQarctan. |
| 171 |
case (decide_rel _); intros. |
| 172 |
apply AQarctan_pos_correct. |
| 173 |
rewrite rings.preserves_negate. |
| 174 |
rewrite AQarctan_pos_correct. |
| 175 |
rewrite rings.preserves_negate. |
| 176 |
apply rational_arctan_opp. |
| 177 |
Qed. |
| 178 |
|
| 179 |
Definition ARarctan_uc |
| 180 |
:= unary_complete_uc |
| 181 |
Qmetric.QPrelengthSpace (cast AQ (msp_car Qmetric.Q_as_MetricSpace)) |
| 182 |
AQarctan arctan_uc AQarctan_correct. |
| 183 |
|
| 184 |
Definition ARarctan := Cbind AQPrelengthSpace ARarctan_uc. |
| 185 |
|
| 186 |
Lemma ARtoCR_preserves_arctan x : ' ucFun ARarctan x = ucFun arctan ('x). |
| 187 |
Proof. apply preserves_unary_complete_fun. Qed. |
| 188 |
|
| 189 |
End ARarctan. |