Flocq_rnd_generic.v 17.3 KB
 Guillaume Melquiond committed Mar 26, 2009 1 2 3 ``````Require Import Flocq_Raux. Require Import Flocq_defs. Require Import Flocq_rnd_ex. `````` Guillaume Melquiond committed Mar 27, 2009 4 ``````Require Import Flocq_float_prop. `````` Guillaume Melquiond committed Mar 26, 2009 5 6 7 8 9 10 11 12 13 `````` Section RND_generic. Variable beta : radix. Notation bpow := (epow beta). Variable fexp : Z -> Z. `````` Guillaume Melquiond committed Apr 08, 2009 14 15 16 17 18 19 20 21 ``````Definition valid_exp := forall k : Z, ( (fexp k < k)%Z -> (fexp (k + 1) <= k)%Z ) /\ ( (k <= fexp k)%Z -> (fexp (fexp k + 1) <= fexp k)%Z /\ forall l : Z, (l <= fexp k)%Z -> fexp l = fexp k ). Variable prop_exp : valid_exp. `````` Guillaume Melquiond committed Mar 26, 2009 22 23 24 `````` Definition generic_format (x : R) := exists f : float beta, `````` Guillaume Melquiond committed Apr 09, 2009 25 `````` x = F2R f /\ Fexp f = fexp (projT1 (ln_beta beta (Rabs x))). `````` Guillaume Melquiond committed Mar 26, 2009 26 `````` `````` Guillaume Melquiond committed Apr 08, 2009 27 28 29 30 31 ``````Theorem generic_DN_pt_large_pos_ge_pow : forall x ex, (fexp ex < ex)%Z -> (bpow (ex - 1)%Z <= x)%R -> (bpow (ex - 1)%Z <= F2R (Float beta (up (x * bpow (- fexp ex)%Z) - 1) (fexp ex)))%R. `````` Guillaume Melquiond committed Mar 26, 2009 32 ``````Proof. `````` Guillaume Melquiond committed Apr 08, 2009 33 ``````intros x ex He1 Hx1. `````` Guillaume Melquiond committed Mar 27, 2009 34 ``````unfold F2R. simpl. `````` Guillaume Melquiond committed Mar 26, 2009 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 ``````replace (ex - 1)%Z with ((ex - 1 - fexp ex) + fexp ex)%Z by ring. rewrite epow_add. apply Rmult_le_compat_r. apply epow_ge_0. assert (bpow (ex - 1 - fexp ex)%Z < Z2R (up (x * bpow (- fexp ex)%Z)))%R. rewrite Z2R_IZR. apply Rle_lt_trans with (2 := proj1 (archimed _)). unfold Zminus. rewrite epow_add. apply Rmult_le_compat_r. apply epow_ge_0. exact Hx1. case_eq (ex - 1 - fexp ex)%Z. intros He2. change (bpow 0%Z) with (Z2R 1). apply Z2R_le. change 1%Z at 1 with (1 + 1 - 1)%Z. apply Zplus_le_compat_r. apply (Zlt_le_succ 1). apply lt_Z2R. now rewrite He2 in H. intros ep He2. simpl. apply Z2R_le. replace (Zpower_pos (radix_val beta) ep) with (Zpower_pos (radix_val beta) ep + 1 - 1)%Z by ring. apply Zplus_le_compat_r. apply Zlt_le_succ. apply lt_Z2R. change (bpow (Zpos ep) < Z2R (up (x * bpow (- fexp ex)%Z)))%R. now rewrite <- He2. clear H Hx1. intros. assert (ex - 1 - fexp ex < 0)%Z. now rewrite H. apply False_ind. omega. `````` Guillaume Melquiond committed Apr 08, 2009 71 72 73 74 75 76 77 78 79 80 81 82 ``````Qed. Theorem generic_DN_pt_pos : forall x ex, (bpow (ex - 1)%Z <= x < bpow ex)%R -> Rnd_DN_pt generic_format x (F2R (Float beta (up (x * bpow (Zopp (fexp ex))) - 1) (fexp ex))). Proof. intros x ex (Hx1, Hx2). destruct (Z_lt_le_dec (fexp ex) ex) as [He1|He1]. (* - positive big enough *) assert (Hbl : (bpow (ex - 1)%Z <= F2R (Float beta (up (x * bpow (- fexp ex)%Z) - 1) (fexp ex)))%R). now apply generic_DN_pt_large_pos_ge_pow. `````` Guillaume Melquiond committed Mar 26, 2009 83 84 ``````split. (* - . rounded *) `````` Guillaume Melquiond committed Mar 27, 2009 85 ``````eexists ; split ; [ reflexivity | idtac ]. `````` Guillaume Melquiond committed Mar 26, 2009 86 87 88 89 90 91 92 93 ``````simpl. apply f_equal. apply sym_eq. apply ln_beta_unique. rewrite Rabs_right. split. exact Hbl. apply Rle_lt_trans with (2 := Hx2). `````` Guillaume Melquiond committed Mar 27, 2009 94 ``````unfold F2R. simpl. `````` Guillaume Melquiond committed Mar 26, 2009 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 ``````pattern x at 2 ; replace x with ((x * bpow (- fexp ex)%Z) * bpow (fexp ex))%R. generalize (x * bpow (- fexp ex)%Z)%R. clear. intros x. apply Rmult_le_compat_r. apply epow_ge_0. rewrite minus_Z2R. rewrite Z2R_IZR. simpl. apply Rplus_le_reg_l with (- x + 1)%R. ring_simplify. rewrite Rplus_comm. exact (proj2 (archimed x)). rewrite Rmult_assoc. rewrite <- epow_add. rewrite Zplus_opp_l. apply Rmult_1_r. apply Rle_ge. apply Rle_trans with (2 := Hbl). apply epow_ge_0. split. (* - . smaller *) `````` Guillaume Melquiond committed Mar 27, 2009 117 ``````unfold F2R. simpl. `````` Guillaume Melquiond committed Mar 26, 2009 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 ``````generalize (fexp ex). clear. intros e. pattern x at 2 ; rewrite <- Rmult_1_r. change R1 with (bpow Z0). rewrite <- (Zplus_opp_l e). rewrite epow_add, <- Rmult_assoc. apply Rmult_le_compat_r. apply epow_ge_0. rewrite minus_Z2R. rewrite Z2R_IZR. simpl. apply Rplus_le_reg_l with (1 - x * bpow (-e)%Z)%R. ring_simplify. rewrite Rplus_comm. rewrite Ropp_mult_distr_l_reverse. exact (proj2 (archimed _)). (* - . biggest *) intros g ((gm, ge), (Hg1, Hg2)) Hgx. destruct (Rle_or_lt g R0) as [Hg3|Hg3]. apply Rle_trans with (2 := Hbl). apply Rle_trans with (1 := Hg3). apply epow_ge_0. apply Rnot_lt_le. intros Hrg. assert (bpow (ex - 1)%Z <= g < bpow ex)%R. split. apply Rle_trans with (1 := Hbl). now apply Rlt_le. now apply Rle_lt_trans with (1 := Hgx). `````` Guillaume Melquiond committed Mar 27, 2009 148 ``````rewrite <- (Rabs_pos_eq g (Rlt_le _ _ Hg3)) in H. `````` Guillaume Melquiond committed Mar 26, 2009 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 ``````rewrite ln_beta_unique with (1 := H) in Hg2. simpl in Hg2. apply Rlt_not_le with (1 := Hrg). rewrite Hg1, Hg2. unfold F2R. simpl. apply Rmult_le_compat_r. apply epow_ge_0. apply Z2R_le. cut (gm < up (x * bpow (- fexp ex)%Z))%Z. omega. apply lt_IZR. apply Rle_lt_trans with (2 := proj1 (archimed _)). apply Rmult_le_reg_r with (bpow (fexp ex)). apply epow_gt_0. rewrite <- Hg2 at 1. rewrite <- Z2R_IZR. rewrite Rmult_assoc. rewrite <- epow_add. rewrite Zplus_opp_l. rewrite Rmult_1_r. unfold F2R in Hg1. simpl in Hg1. now rewrite <- Hg1. (* - positive too small *) cutrewrite (up (x * bpow (- fexp ex)%Z) = 1%Z). (* - . rounded *) unfold F2R. simpl. rewrite Rmult_0_l. split. `````` Guillaume Melquiond committed Apr 09, 2009 178 ``````exists (Float beta Z0 _) ; repeat split. `````` Guillaume Melquiond committed Mar 26, 2009 179 180 181 ``````unfold F2R. simpl. now rewrite Rmult_0_l. split. `````` Guillaume Melquiond committed Apr 08, 2009 182 183 ``````apply Rle_trans with (2 := Hx1). apply epow_ge_0. `````` Guillaume Melquiond committed Mar 26, 2009 184 185 186 187 ``````(* - . biggest *) intros g ((gm, ge), (Hg1, Hg2)) Hgx. apply Rnot_lt_le. intros Hg3. `````` Guillaume Melquiond committed Apr 09, 2009 188 189 ``````destruct (ln_beta beta g) as (ge', Hg4). specialize (Hg4 Hg3). `````` Guillaume Melquiond committed Mar 27, 2009 190 191 192 ``````generalize Hg4. intros Hg5. rewrite <- (Rabs_pos_eq g (Rlt_le _ _ Hg3)) in Hg5. rewrite ln_beta_unique with (1 := Hg5) in Hg2. `````` Guillaume Melquiond committed Mar 26, 2009 193 194 195 ``````apply (Rlt_not_le _ _ (Rle_lt_trans _ _ _ Hgx Hx2)). apply Rle_trans with (bpow ge). apply -> epow_le. `````` Guillaume Melquiond committed Mar 27, 2009 196 ``````simpl in Hg2. `````` Guillaume Melquiond committed Mar 26, 2009 197 ``````rewrite Hg2. `````` Guillaume Melquiond committed Apr 08, 2009 198 ``````rewrite (proj2 (proj2 (prop_exp ex) He1) ge'). `````` Guillaume Melquiond committed Mar 26, 2009 199 200 ``````exact He1. apply Zle_trans with (2 := He1). `````` Guillaume Melquiond committed Mar 27, 2009 201 ``````cut (ge' - 1 < ex)%Z. omega. `````` Guillaume Melquiond committed Mar 26, 2009 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 ``````apply <- epow_lt. apply Rle_lt_trans with (2 := Hx2). apply Rle_trans with (2 := Hgx). exact (proj1 Hg4). rewrite Hg1. unfold F2R. simpl. pattern (bpow ge) at 1 ; rewrite <- Rmult_1_l. apply Rmult_le_compat_r. apply epow_ge_0. apply (Z2R_le 1). apply (Zlt_le_succ 0). apply lt_Z2R. apply Rmult_lt_reg_r with (bpow ge). apply epow_gt_0. rewrite Rmult_0_l. unfold F2R in Hg1. simpl in Hg1. now rewrite <- Hg1. (* - . . *) apply sym_eq. rewrite <- (Zplus_0_l 1). apply up_tech. apply Rlt_le. apply Rmult_lt_0_compat. `````` Guillaume Melquiond committed Apr 08, 2009 225 226 ``````apply Rlt_le_trans with (2 := Hx1). apply epow_gt_0. `````` Guillaume Melquiond committed Mar 26, 2009 227 228 229 230 231 232 233 234 ``````apply epow_gt_0. change (IZR (0 + 1)) with (bpow Z0). rewrite <- (Zplus_opp_r (fexp ex)). rewrite epow_add. apply Rmult_lt_compat_r. apply epow_gt_0. apply Rlt_le_trans with (1 := Hx2). now apply -> epow_le. `````` Guillaume Melquiond committed Apr 08, 2009 235 236 237 238 239 240 241 242 243 244 245 246 247 ``````Qed. Theorem generic_DN_pt_neg : forall x ex, (bpow (ex - 1)%Z <= -x < bpow ex)%R -> Rnd_DN_pt generic_format x (F2R (Float beta (up (x * bpow (Zopp (fexp ex))) - 1) (fexp ex))). Proof. intros x ex (Hx1, Hx2). assert (Hx : (x < 0)%R). apply Ropp_lt_cancel. rewrite Ropp_0. apply Rlt_le_trans with (2 := Hx1). apply epow_gt_0. `````` Guillaume Melquiond committed Mar 26, 2009 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 ``````assert (Hbr : (F2R (Float beta (up (x * bpow (- fexp ex)%Z) - 1) (fexp ex)) <= x)%R). (* - bounded right *) unfold F2R. simpl. pattern x at 2 ; rewrite <- Rmult_1_r. change R1 with (bpow Z0). rewrite <- (Zplus_opp_l (fexp ex)). rewrite epow_add. rewrite <- Rmult_assoc. generalize (x * bpow (- fexp ex)%Z)%R. clear. intros x. apply Rmult_le_compat_r. apply epow_ge_0. rewrite minus_Z2R. simpl. rewrite Z2R_IZR. apply Rplus_le_reg_l with (-x + 1)%R. ring_simplify. rewrite Rplus_comm. exact (proj2 (archimed x)). destruct (Z_lt_le_dec (fexp ex) ex) as [He1|He1]. (* - negative big enough *) assert (Hbl : (- bpow ex <= F2R (Float beta (up (x * bpow (- fexp ex)%Z) - 1) (fexp ex)))%R). (* - . bounded left *) unfold F2R. simpl. pattern ex at 1 ; replace ex with (ex - fexp ex + fexp ex)%Z by ring. rewrite epow_add. rewrite <- Ropp_mult_distr_l_reverse. apply Rmult_le_compat_r. apply epow_ge_0. cut (0 < ex - fexp ex)%Z. 2: omega. case_eq (ex - fexp ex)%Z ; try (intros ; discriminate H0). intros ep Hp _. simpl. rewrite <- opp_Z2R. apply Z2R_le. cut (- Zpower_pos (radix_val beta) ep < up (x * bpow (- fexp ex)%Z))%Z. omega. apply lt_Z2R. apply Rle_lt_trans with (x * bpow (- fexp ex)%Z)%R. rewrite opp_Z2R. change (- bpow (Zpos ep) <= x * bpow (- fexp ex)%Z)%R. rewrite <- Hp. apply Rmult_le_reg_r with (bpow (fexp ex)). apply epow_gt_0. rewrite Rmult_assoc. rewrite <- epow_add. rewrite Zplus_opp_l. rewrite Rmult_1_r. rewrite Ropp_mult_distr_l_reverse. rewrite <- epow_add. replace (ex - fexp ex + fexp ex)%Z with ex by ring. `````` Guillaume Melquiond committed Mar 27, 2009 300 301 ``````apply Ropp_le_cancel. rewrite Ropp_involutive. `````` Guillaume Melquiond committed Mar 26, 2009 302 303 304 305 306 307 308 ``````now apply Rlt_le. rewrite Z2R_IZR. exact (proj1 (archimed _)). split. (* - . rounded *) destruct (Rle_lt_or_eq_dec _ _ Hbl) as [Hbl2|Hbl2]. (* - . . not a radix power *) `````` Guillaume Melquiond committed Apr 09, 2009 309 ``````eexists ; repeat split. `````` Guillaume Melquiond committed Mar 26, 2009 310 311 312 313 ``````simpl. apply f_equal. apply sym_eq. apply ln_beta_unique. `````` Guillaume Melquiond committed Mar 27, 2009 314 ``````rewrite Rabs_left. `````` Guillaume Melquiond committed Mar 26, 2009 315 ``````split. `````` Guillaume Melquiond committed Mar 27, 2009 316 317 ``````apply Ropp_le_cancel. rewrite Ropp_involutive. `````` Guillaume Melquiond committed Mar 26, 2009 318 ``````apply Rle_trans with (1 := Hbr). `````` Guillaume Melquiond committed Mar 27, 2009 319 320 321 322 ``````apply Ropp_le_cancel. now rewrite Ropp_involutive. apply Ropp_lt_cancel. now rewrite Ropp_involutive. `````` Guillaume Melquiond committed Mar 26, 2009 323 324 325 326 ``````apply Rle_lt_trans with (1 := Hbr). exact Hx. (* - . . a radix power *) rewrite <- Hbl2. `````` Guillaume Melquiond committed Apr 08, 2009 327 ``````generalize (proj1 (prop_exp _) He1). `````` Guillaume Melquiond committed Mar 26, 2009 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 ``````clear. intros He2. exists (Float beta (- Zpower (radix_val beta) (ex - fexp (ex + 1))) (fexp (ex + 1))). unfold F2R. simpl. split. clear -He2. pattern ex at 1 ; replace ex with (ex - fexp (ex + 1) + fexp (ex + 1))%Z by ring. rewrite epow_add. rewrite <- Ropp_mult_distr_l_reverse. rewrite opp_Z2R. apply (f_equal (fun x => (- x * _)%R)). cut (0 <= ex - fexp (ex + 1))%Z. 2: omega. case (ex - fexp (ex + 1))%Z ; trivial. intros ep H. now elim H. apply f_equal. apply sym_eq. apply ln_beta_unique. `````` Guillaume Melquiond committed Mar 27, 2009 346 347 ``````rewrite Rabs_Ropp. rewrite Rabs_right. `````` Guillaume Melquiond committed Mar 26, 2009 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 ``````split. apply -> epow_le. omega. apply -> epow_lt. apply Zlt_succ. apply Rle_ge. apply epow_ge_0. split. exact Hbr. (* - . biggest *) intros g ((gm, ge), (Hg1, Hg2)) Hgx. apply Rnot_lt_le. intros Hg3. assert (Hg4 : (g < 0)%R). now apply Rle_lt_trans with (1 := Hgx). `````` Guillaume Melquiond committed Apr 09, 2009 363 ``````destruct (ln_beta beta (Rabs g)) as (ge', Hge). `````` Guillaume Melquiond committed Mar 26, 2009 364 ``````simpl in Hg2. `````` Guillaume Melquiond committed Apr 09, 2009 365 ``````specialize (Hge (Rabs_pos_lt g (Rlt_not_eq g 0 Hg4))). `````` Guillaume Melquiond committed Mar 26, 2009 366 367 368 369 370 371 372 373 ``````apply Rlt_not_le with (1 := Hg3). rewrite Hg1. unfold F2R. simpl. rewrite Hg2. assert (Hge' : ge' = ex). apply epow_unique with (1 := Hge). split. apply Rle_trans with (1 := Hx1). `````` Guillaume Melquiond committed Mar 27, 2009 374 ``````rewrite Rabs_left with (1 := Hg4). `````` Guillaume Melquiond committed Mar 26, 2009 375 376 ``````now apply Ropp_le_contravar. apply Ropp_lt_cancel. `````` Guillaume Melquiond committed Mar 27, 2009 377 378 379 ``````rewrite Rabs_left with (1 := Hg4). rewrite Ropp_involutive. now apply Rle_lt_trans with (1 := Hbl). `````` Guillaume Melquiond committed Mar 26, 2009 380 381 382 383 ``````rewrite Hge'. apply Rmult_le_compat_r. apply epow_ge_0. apply Z2R_le. `````` Guillaume Melquiond committed Mar 27, 2009 384 ``````cut (gm < up (x * bpow (- fexp ex)%Z))%Z. omega. `````` Guillaume Melquiond committed Mar 26, 2009 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 ``````apply lt_IZR. apply Rle_lt_trans with (2 := proj1 (archimed _)). rewrite <- Z2R_IZR. apply Rmult_le_reg_r with (bpow (fexp ex)). apply epow_gt_0. rewrite Rmult_assoc. rewrite <- epow_add. rewrite Zplus_opp_l. rewrite Rmult_1_r. rewrite <- Hge'. rewrite <- Hg2. unfold F2R in Hg1. simpl in Hg1. now rewrite <- Hg1. (* - negative too small *) cutrewrite (up (x * bpow (- fexp ex)%Z) = 0%Z). unfold F2R. simpl. rewrite Ropp_mult_distr_l_reverse. rewrite Rmult_1_l. (* - . rounded *) split. `````` Guillaume Melquiond committed Apr 08, 2009 405 ``````destruct (proj2 (prop_exp _) He1) as (He2, _). `````` Guillaume Melquiond committed Mar 26, 2009 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 ``````exists (Float beta (- Zpower (radix_val beta) (fexp ex - fexp (fexp ex + 1))) (fexp (fexp ex + 1))). unfold F2R. simpl. split. rewrite opp_Z2R. pattern (fexp ex) at 1 ; replace (fexp ex) with (fexp ex - fexp (fexp ex + 1) + fexp (fexp ex + 1))%Z by ring. rewrite epow_add. rewrite Ropp_mult_distr_l_reverse. apply (f_equal (fun x => (- (x * _))%R)). cut (0 <= fexp ex - fexp (fexp ex + 1))%Z. 2: omega. clear. case (fexp ex - fexp (fexp ex + 1))%Z ; trivial. intros ep Hp. now elim Hp. apply f_equal. apply sym_eq. apply ln_beta_unique. `````` Guillaume Melquiond committed Mar 27, 2009 422 423 ``````rewrite Rabs_left. rewrite Ropp_involutive. `````` Guillaume Melquiond committed Mar 26, 2009 424 425 426 427 428 ``````split. replace (fexp ex + 1 - 1)%Z with (fexp ex) by ring. apply Rle_refl. apply -> epow_lt. apply Zlt_succ. `````` Guillaume Melquiond committed Mar 27, 2009 429 430 431 ``````rewrite <- Ropp_0. apply Ropp_lt_contravar. apply epow_gt_0. `````` Guillaume Melquiond committed Mar 26, 2009 432 433 ``````split. (* - . smaller *) `````` Guillaume Melquiond committed Mar 27, 2009 434 435 ``````apply Ropp_le_cancel. rewrite Ropp_involutive. `````` Guillaume Melquiond committed Mar 26, 2009 436 437 438 439 440 441 442 443 444 ``````apply Rlt_le. apply Rlt_le_trans with (1 := Hx2). now apply -> epow_le. (* - . biggest *) intros g ((gm, ge), (Hg1, Hg2)) Hgx. apply Rnot_lt_le. intros Hg3. assert (Hg4 : (g < 0)%R). now apply Rle_lt_trans with (1 := Hgx). `````` Guillaume Melquiond committed Apr 09, 2009 445 ``````destruct (ln_beta beta (Rabs g)) as (ge', Hge). `````` Guillaume Melquiond committed Mar 26, 2009 446 ``````simpl in Hg2. `````` Guillaume Melquiond committed Apr 09, 2009 447 ``````specialize (Hge (Rabs_pos_lt g (Rlt_not_eq g 0 Hg4))). `````` Guillaume Melquiond committed Mar 27, 2009 448 ``````rewrite (Rabs_left _ Hg4) in Hge. `````` Guillaume Melquiond committed Mar 26, 2009 449 450 451 452 453 454 ``````assert (Hge' : (ge' <= fexp ex)%Z). cut (ge' - 1 < fexp ex)%Z. omega. apply <- epow_lt. apply Rle_lt_trans with (1 := proj1 Hge). apply Ropp_lt_cancel. now rewrite Ropp_involutive. `````` Guillaume Melquiond committed Apr 08, 2009 455 ``````rewrite (proj2 (proj2 (prop_exp _) He1) _ Hge') in Hg2. `````` Guillaume Melquiond committed Mar 26, 2009 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 ``````rewrite <- Hg2 in Hge'. apply Rlt_not_le with (1 := proj2 Hge). rewrite Hg1. unfold F2R. simpl. rewrite <- Ropp_mult_distr_l_reverse. replace ge with (ge - ge' + ge')%Z by ring. rewrite epow_add. rewrite <- Rmult_assoc. pattern (bpow ge') at 1 ; rewrite <- Rmult_1_l. apply Rmult_le_compat_r. apply epow_ge_0. rewrite <- opp_Z2R. assert (1 <= -gm)%Z. apply (Zlt_le_succ 0). apply lt_Z2R. apply Rmult_lt_reg_r with (bpow ge). apply epow_gt_0. rewrite Rmult_0_l. `````` Guillaume Melquiond committed Mar 27, 2009 474 475 ``````change (0 < F2R (Float beta (-gm) ge))%R. rewrite <- opp_F2R. `````` Guillaume Melquiond committed Mar 27, 2009 476 477 478 ``````rewrite <- Hg1. rewrite <- Ropp_0. now apply Ropp_lt_contravar. `````` Guillaume Melquiond committed Mar 26, 2009 479 480 481 482 483 484 485 486 487 488 489 ``````apply Rle_trans with (1 * bpow (ge - ge')%Z)%R. rewrite Rmult_1_l. cut (0 <= ge - ge')%Z. 2: omega. clear. case (ge - ge')%Z. intros _. apply Rle_refl. intros ep _. simpl. apply (Z2R_le 1). apply (Zlt_le_succ 0). `````` Guillaume Melquiond committed Apr 08, 2009 490 ``````apply Zpower_pos_gt_0. `````` Guillaume Melquiond committed Mar 26, 2009 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 ``````now apply Zlt_le_trans with (2 := radix_prop beta). intros ep Hp. now elim Hp. apply Rmult_le_compat_r. apply epow_ge_0. now apply (Z2R_le 1). (* - . . *) apply sym_eq. apply (up_tech _ (-1)). apply Ropp_le_cancel. simpl. rewrite Ropp_involutive. change R1 with (bpow Z0). rewrite <- (Zplus_opp_r (fexp ex)). rewrite epow_add. rewrite <- Ropp_mult_distr_l_reverse. apply Rmult_le_compat_r. apply epow_ge_0. apply Rlt_le. apply Rlt_le_trans with (1 := Hx2). now apply -> epow_le. simpl. rewrite <- (Rmult_0_l (bpow (- fexp ex)%Z)). apply Rmult_lt_compat_r. apply epow_gt_0. exact Hx. Qed. `````` Guillaume Melquiond committed Apr 08, 2009 518 519 520 521 522 ``````Theorem generic_format_satisfies_any : satisfies_any generic_format. Proof. refine ((fun D => Satisfies_any _ _ _ (projT1 D) (projT2 D)) _). (* symmetric set *) `````` Guillaume Melquiond committed Apr 09, 2009 523 ``````exists (Float beta 0 _) ; repeat split. `````` Guillaume Melquiond committed Apr 08, 2009 524 525 526 ``````unfold F2R. simpl. now rewrite Rmult_0_l. intros x ((m,e),(H1,H2)). `````` Guillaume Melquiond committed Apr 09, 2009 527 528 529 530 531 532 ``````exists (Float beta (-m) _) ; repeat split. rewrite H1 at 1. rewrite Rabs_Ropp. rewrite opp_F2R. apply (f_equal (fun v => F2R (Float beta (- m) v))). exact H2. `````` Guillaume Melquiond committed Apr 08, 2009 533 534 535 536 ``````(* rounding down *) exists (fun x => match total_order_T 0 x with | inleft (left Hx) => `````` Guillaume Melquiond committed Apr 09, 2009 537 `````` let e := fexp (projT1 (ln_beta beta x)) in `````` Guillaume Melquiond committed Apr 08, 2009 538 539 540 `````` F2R (Float beta (up (x * bpow (Zopp e)) - 1) e) | inleft (right _) => R0 | inright Hx => `````` Guillaume Melquiond committed Apr 09, 2009 541 `````` let e := fexp (projT1 (ln_beta beta (-x))) in `````` Guillaume Melquiond committed Apr 08, 2009 542 543 544 545 546 `````` F2R (Float beta (up (x * bpow (Zopp e)) - 1) e) end). intros x. destruct (total_order_T 0 x) as [[Hx|Hx]|Hx]. (* positive *) `````` Guillaume Melquiond committed Apr 09, 2009 547 ``````destruct (ln_beta beta x) as (ex, Hx'). `````` Guillaume Melquiond committed Apr 08, 2009 548 ``````simpl. `````` Guillaume Melquiond committed Apr 09, 2009 549 550 ``````apply generic_DN_pt_pos. now apply Hx'. `````` Guillaume Melquiond committed Apr 08, 2009 551 552 ``````(* zero *) split. `````` Guillaume Melquiond committed Apr 09, 2009 553 554 ``````exists (Float beta 0 _) ; repeat split. unfold F2R. simpl. `````` Guillaume Melquiond committed Apr 08, 2009 555 556 557 558 559 560 561 ``````now rewrite Rmult_0_l. rewrite <- Hx. split. apply Rle_refl. intros g _ H. exact H. (* negative *) `````` Guillaume Melquiond committed Apr 09, 2009 562 ``````destruct (ln_beta beta (- x)) as (ex, Hx'). `````` Guillaume Melquiond committed Apr 08, 2009 563 ``````simpl. `````` Guillaume Melquiond committed Apr 09, 2009 564 565 566 567 ``````apply generic_DN_pt_neg. apply Hx'. rewrite <- Ropp_0. now apply Ropp_lt_contravar. `````` Guillaume Melquiond committed Apr 08, 2009 568 569 570 ``````Qed. Theorem generic_DN_pt_small_pos : `````` Guillaume Melquiond committed Apr 08, 2009 571 572 573 574 575 576 577 `````` forall x ex, (bpow (ex - 1)%Z <= x < bpow ex)%R -> (ex <= fexp ex)%Z -> Rnd_DN_pt generic_format x R0. Proof. intros x ex Hx He. split. `````` Guillaume Melquiond committed Apr 09, 2009 578 ``````exists (Float beta 0 _) ; repeat split. `````` Guillaume Melquiond committed Apr 08, 2009 579 580 581 582 583 584 585 586 587 ``````unfold F2R. simpl. now rewrite Rmult_0_l. split. apply Rle_trans with (2 := proj1 Hx). apply epow_ge_0. (* . *) intros g ((gm, ge), (Hg1, Hg2)) Hgx. apply Rnot_lt_le. intros Hg3. `````` Guillaume Melquiond committed Apr 09, 2009 588 ``````destruct (ln_beta beta (Rabs g)) as (eg, Hg4). `````` Guillaume Melquiond committed Apr 08, 2009 589 ``````simpl in Hg2. `````` Guillaume Melquiond committed Apr 09, 2009 590 ``````specialize (Hg4 (Rabs_pos_lt g (Rgt_not_eq g 0 Hg3))). `````` Guillaume Melquiond committed Apr 08, 2009 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 ``````rewrite Rabs_right in Hg4. apply Rle_not_lt with (1 := Hgx). rewrite Hg1. apply Rlt_le_trans with (1 := proj2 Hx). rewrite (proj2 (proj2 (prop_exp _) He) eg) in Hg2. rewrite Hg2. apply Rle_trans with (bpow (fexp ex)). now apply -> epow_le. rewrite <- Hg2. rewrite Hg1 in Hg3. apply epow_le_F2R with (1 := Hg3). apply epow_lt_epow with beta. apply Rlt_le_trans with (bpow ex). apply Rle_lt_trans with (2 := proj2 Hx). now apply Rle_trans with g. now apply -> epow_le. apply Rle_ge. now apply Rlt_le. Qed. `````` Guillaume Melquiond committed Apr 08, 2009 611 ``````Theorem generic_UP_pt_small_pos : `````` Guillaume Melquiond committed Apr 08, 2009 612 613 614 615 616 617 `````` forall x ex, (bpow (ex - 1)%Z <= x < bpow ex)%R -> (ex <= fexp ex)%Z -> Rnd_UP_pt generic_format x (bpow (fexp ex)). Proof. intros x ex Hx He. `````` Guillaume Melquiond committed Apr 09, 2009 618 ``````assert (bpow (fexp ex) = F2R (Float beta (Zpower (radix_val beta) (fexp ex - fexp (fexp ex + 1))) (fexp (fexp ex + 1)))). `````` Guillaume Melquiond committed Apr 08, 2009 619 ``````unfold F2R. simpl. `````` Guillaume Melquiond committed Apr 09, 2009 620 621 622 623 ``````rewrite Z2R_Zpower. rewrite <- epow_add. apply f_equal. ring. `````` Guillaume Melquiond committed Apr 08, 2009 624 625 626 627 628 ``````generalize (proj1 (proj2 (prop_exp ex) He)). omega. split. (* . *) rewrite H. `````` Guillaume Melquiond committed Apr 09, 2009 629 ``````eexists ; repeat split. `````` Guillaume Melquiond committed Apr 08, 2009 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 ``````simpl. apply f_equal. apply sym_eq. apply ln_beta_unique. rewrite <- H. split. replace (fexp ex + 1 - 1)%Z with (fexp ex) by ring. apply RRle_abs. rewrite Rabs_right. apply -> epow_lt. apply Zle_lt_succ. apply Zle_refl. apply Rle_ge. apply epow_ge_0. split. (* . *) apply Rlt_le. apply Rlt_le_trans with (1 := proj2 Hx). now apply -> epow_le. (* . *) intros g ((gm, ge), (Hg1, Hg2)) Hgx. assert (g <> R0). apply Rgt_not_eq. apply Rlt_le_trans with (2 := Hgx). apply Rlt_le_trans with (2 := proj1 Hx). apply epow_gt_0. `````` Guillaume Melquiond committed Apr 09, 2009 656 ``````destruct (ln_beta beta (Rabs g)) as (eg, Hg3). `````` Guillaume Melquiond committed Apr 08, 2009 657 ``````simpl in Hg2. `````` Guillaume Melquiond committed Apr 09, 2009 658 ``````specialize (Hg3 (Rabs_pos_lt g H0)). `````` Guillaume Melquiond committed Apr 08, 2009 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 ``````apply Rnot_lt_le. intros Hgp. apply Rlt_not_le with (1 := Hgp). rewrite <- (proj2 (proj2 (prop_exp ex) He) eg). rewrite <- Hg2. rewrite Hg1. apply (epow_le_F2R _ (Float beta gm ge)). rewrite <- Hg1. apply Rlt_le_trans with (2 := Hgx). apply Rlt_le_trans with (2 := proj1 Hx). apply epow_gt_0. apply epow_lt_epow with beta. apply Rle_lt_trans with g. rewrite <- (Rabs_right g). apply Hg3. apply Rle_ge. apply Rle_trans with (2 := Hgx). apply Rle_trans with (2 := proj1 Hx). apply epow_ge_0. exact Hgp. Qed. `````` Guillaume Melquiond committed Apr 08, 2009 681 ``````Theorem generic_UP_pt_large_pos_le_pow : `````` Guillaume Melquiond committed Apr 08, 2009 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 `````` forall x xu ex, (bpow (ex - 1)%Z <= x < bpow ex)%R -> (fexp ex < ex)%Z -> Rnd_UP_pt generic_format x xu -> (xu <= bpow ex)%R. Proof. intros x xu ex Hx He (((dm, de), (Hu1, Hu2)), (Hu3, Hu4)). apply Hu4 with (2 := (Rlt_le _ _ (proj2 Hx))). exists (Float beta (Zpower (radix_val beta) (ex - fexp (ex + 1))) (fexp (ex + 1))). unfold F2R. simpl. split. (* . *) rewrite Z2R_Zpower. rewrite <- epow_add. apply f_equal. ring. generalize (proj1 (prop_exp _) He). omega. (* . *) apply f_equal. apply sym_eq. apply ln_beta_unique. rewrite Rabs_pos_eq. split. ring_simplify (ex + 1 - 1)%Z. apply Rle_refl. apply -> epow_lt. apply Zlt_succ. apply epow_ge_0. Qed. `````` Guillaume Melquiond committed Apr 08, 2009 713 ``End RND_generic.``