author | immler |
Sun, 03 Nov 2019 19:59:56 -0500 | |
changeset 71037 | f630f2e707a6 |
parent 71036 | dfcc1882d05a |
child 73537 | 56db8559eadb |
permissions | -rw-r--r-- |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1 |
(* |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2 |
Author: Johannes Hoelzl, TU Muenchen |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3 |
Coercions removed by Dmitriy Traytel |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
4 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
5 |
This file contains only general material about computing lower/upper bounds |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
6 |
on real functions. Approximation.thy contains the actual approximation algorithm |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
7 |
and the approximation oracle. This is in order to make a clear separation between |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
8 |
"morally immaculate" material about upper/lower bounds and the trusted oracle/reflection. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
9 |
*) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
10 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
11 |
theory Approximation_Bounds |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
12 |
imports |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
13 |
Complex_Main |
71036 | 14 |
"HOL-Library.Interval_Float" |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
15 |
Dense_Linear_Order |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
16 |
begin |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
17 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
18 |
declare powr_neg_one [simp] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
19 |
declare powr_neg_numeral [simp] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
20 |
|
71036 | 21 |
context includes interval.lifting begin |
22 |
||
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
23 |
section "Horner Scheme" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
24 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
25 |
subsection \<open>Define auxiliary helper \<open>horner\<close> function\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
26 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
27 |
primrec horner :: "(nat \<Rightarrow> nat) \<Rightarrow> (nat \<Rightarrow> nat \<Rightarrow> nat) \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> real \<Rightarrow> real" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
28 |
"horner F G 0 i k x = 0" | |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
29 |
"horner F G (Suc n) i k x = 1 / k - x * horner F G n (F i) (G i k) x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
30 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
31 |
lemma horner_schema': |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
32 |
fixes x :: real and a :: "nat \<Rightarrow> real" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
33 |
shows "a 0 - x * (\<Sum> i=0..<n. (-1)^i * a (Suc i) * x^i) = (\<Sum> i=0..<Suc n. (-1)^i * a i * x^i)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
34 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
35 |
have shift_pow: "\<And>i. - (x * ((-1)^i * a (Suc i) * x ^ i)) = (-1)^(Suc i) * a (Suc i) * x ^ (Suc i)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
36 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
37 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
38 |
unfolding sum_distrib_left shift_pow uminus_add_conv_diff [symmetric] sum_negf[symmetric] |
70097
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
paulson <lp15@cam.ac.uk>
parents:
69597
diff
changeset
|
39 |
sum.atLeast_Suc_lessThan[OF zero_less_Suc] |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
40 |
sum.reindex[OF inj_Suc, unfolded comp_def, symmetric, of "\<lambda> n. (-1)^n *a n * x^n"] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
41 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
42 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
43 |
lemma horner_schema: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
44 |
fixes f :: "nat \<Rightarrow> nat" and G :: "nat \<Rightarrow> nat \<Rightarrow> nat" and F :: "nat \<Rightarrow> nat" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
45 |
assumes f_Suc: "\<And>n. f (Suc n) = G ((F ^^ n) s) (f n)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
46 |
shows "horner F G n ((F ^^ j') s) (f j') x = (\<Sum> j = 0..< n. (- 1) ^ j * (1 / (f (j' + j))) * x ^ j)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
47 |
proof (induct n arbitrary: j') |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
48 |
case 0 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
49 |
then show ?case by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
50 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
51 |
case (Suc n) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
52 |
show ?case unfolding horner.simps Suc[where j'="Suc j'", unfolded funpow.simps comp_def f_Suc] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
53 |
using horner_schema'[of "\<lambda> j. 1 / (f (j' + j))"] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
54 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
55 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
56 |
lemma horner_bounds': |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
57 |
fixes lb :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" and ub :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
58 |
assumes "0 \<le> real_of_float x" and f_Suc: "\<And>n. f (Suc n) = G ((F ^^ n) s) (f n)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
59 |
and lb_0: "\<And> i k x. lb 0 i k x = 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
60 |
and lb_Suc: "\<And> n i k x. lb (Suc n) i k x = float_plus_down prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
61 |
(lapprox_rat prec 1 k) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
62 |
(- float_round_up prec (x * (ub n (F i) (G i k) x)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
63 |
and ub_0: "\<And> i k x. ub 0 i k x = 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
64 |
and ub_Suc: "\<And> n i k x. ub (Suc n) i k x = float_plus_up prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
65 |
(rapprox_rat prec 1 k) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
66 |
(- float_round_down prec (x * (lb n (F i) (G i k) x)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
67 |
shows "(lb n ((F ^^ j') s) (f j') x) \<le> horner F G n ((F ^^ j') s) (f j') x \<and> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
68 |
horner F G n ((F ^^ j') s) (f j') x \<le> (ub n ((F ^^ j') s) (f j') x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
69 |
(is "?lb n j' \<le> ?horner n j' \<and> ?horner n j' \<le> ?ub n j'") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
70 |
proof (induct n arbitrary: j') |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
71 |
case 0 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
72 |
thus ?case unfolding lb_0 ub_0 horner.simps by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
73 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
74 |
case (Suc n) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
75 |
thus ?case using lapprox_rat[of prec 1 "f j'"] using rapprox_rat[of 1 "f j'" prec] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
76 |
Suc[where j'="Suc j'"] \<open>0 \<le> real_of_float x\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
77 |
by (auto intro!: add_mono mult_left_mono float_round_down_le float_round_up_le |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
78 |
order_trans[OF add_mono[OF _ float_plus_down_le]] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
79 |
order_trans[OF _ add_mono[OF _ float_plus_up_le]] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
80 |
simp add: lb_Suc ub_Suc field_simps f_Suc) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
81 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
82 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
83 |
subsection "Theorems for floating point functions implementing the horner scheme" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
84 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
85 |
text \<open> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
86 |
|
69597 | 87 |
Here \<^term_type>\<open>f :: nat \<Rightarrow> nat\<close> is the sequence defining the Taylor series, the coefficients are |
88 |
all alternating and reciprocs. We use \<^term>\<open>G\<close> and \<^term>\<open>F\<close> to describe the computation of \<^term>\<open>f\<close>. |
|
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
89 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
90 |
\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
91 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
92 |
lemma horner_bounds: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
93 |
fixes F :: "nat \<Rightarrow> nat" and G :: "nat \<Rightarrow> nat \<Rightarrow> nat" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
94 |
assumes "0 \<le> real_of_float x" and f_Suc: "\<And>n. f (Suc n) = G ((F ^^ n) s) (f n)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
95 |
and lb_0: "\<And> i k x. lb 0 i k x = 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
96 |
and lb_Suc: "\<And> n i k x. lb (Suc n) i k x = float_plus_down prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
97 |
(lapprox_rat prec 1 k) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
98 |
(- float_round_up prec (x * (ub n (F i) (G i k) x)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
99 |
and ub_0: "\<And> i k x. ub 0 i k x = 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
100 |
and ub_Suc: "\<And> n i k x. ub (Suc n) i k x = float_plus_up prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
101 |
(rapprox_rat prec 1 k) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
102 |
(- float_round_down prec (x * (lb n (F i) (G i k) x)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
103 |
shows "(lb n ((F ^^ j') s) (f j') x) \<le> (\<Sum>j=0..<n. (- 1) ^ j * (1 / (f (j' + j))) * (x ^ j))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
104 |
(is "?lb") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
105 |
and "(\<Sum>j=0..<n. (- 1) ^ j * (1 / (f (j' + j))) * (x ^ j)) \<le> (ub n ((F ^^ j') s) (f j') x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
106 |
(is "?ub") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
107 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
108 |
have "?lb \<and> ?ub" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
109 |
using horner_bounds'[where lb=lb, OF \<open>0 \<le> real_of_float x\<close> f_Suc lb_0 lb_Suc ub_0 ub_Suc] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
110 |
unfolding horner_schema[where f=f, OF f_Suc] by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
111 |
thus "?lb" and "?ub" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
112 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
113 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
114 |
lemma horner_bounds_nonpos: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
115 |
fixes F :: "nat \<Rightarrow> nat" and G :: "nat \<Rightarrow> nat \<Rightarrow> nat" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
116 |
assumes "real_of_float x \<le> 0" and f_Suc: "\<And>n. f (Suc n) = G ((F ^^ n) s) (f n)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
117 |
and lb_0: "\<And> i k x. lb 0 i k x = 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
118 |
and lb_Suc: "\<And> n i k x. lb (Suc n) i k x = float_plus_down prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
119 |
(lapprox_rat prec 1 k) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
120 |
(float_round_down prec (x * (ub n (F i) (G i k) x)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
121 |
and ub_0: "\<And> i k x. ub 0 i k x = 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
122 |
and ub_Suc: "\<And> n i k x. ub (Suc n) i k x = float_plus_up prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
123 |
(rapprox_rat prec 1 k) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
124 |
(float_round_up prec (x * (lb n (F i) (G i k) x)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
125 |
shows "(lb n ((F ^^ j') s) (f j') x) \<le> (\<Sum>j=0..<n. (1 / (f (j' + j))) * real_of_float x ^ j)" (is "?lb") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
126 |
and "(\<Sum>j=0..<n. (1 / (f (j' + j))) * real_of_float x ^ j) \<le> (ub n ((F ^^ j') s) (f j') x)" (is "?ub") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
127 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
128 |
have diff_mult_minus: "x - y * z = x + - y * z" for x y z :: float by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
129 |
have sum_eq: "(\<Sum>j=0..<n. (1 / (f (j' + j))) * real_of_float x ^ j) = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
130 |
(\<Sum>j = 0..<n. (- 1) ^ j * (1 / (f (j' + j))) * real_of_float (- x) ^ j)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
131 |
by (auto simp add: field_simps power_mult_distrib[symmetric]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
132 |
have "0 \<le> real_of_float (-x)" using assms by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
133 |
from horner_bounds[where G=G and F=F and f=f and s=s and prec=prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
134 |
and lb="\<lambda> n i k x. lb n i k (-x)" and ub="\<lambda> n i k x. ub n i k (-x)", |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
135 |
unfolded lb_Suc ub_Suc diff_mult_minus, |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
136 |
OF this f_Suc lb_0 _ ub_0 _] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
137 |
show "?lb" and "?ub" unfolding minus_minus sum_eq |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
138 |
by (auto simp: minus_float_round_up_eq minus_float_round_down_eq) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
139 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
140 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
141 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
142 |
subsection \<open>Selectors for next even or odd number\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
143 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
144 |
text \<open> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
145 |
The horner scheme computes alternating series. To get the upper and lower bounds we need to |
69597 | 146 |
guarantee to access a even or odd member. To do this we use \<^term>\<open>get_odd\<close> and \<^term>\<open>get_even\<close>. |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
147 |
\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
148 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
149 |
definition get_odd :: "nat \<Rightarrow> nat" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
150 |
"get_odd n = (if odd n then n else (Suc n))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
151 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
152 |
definition get_even :: "nat \<Rightarrow> nat" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
153 |
"get_even n = (if even n then n else (Suc n))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
154 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
155 |
lemma get_odd[simp]: "odd (get_odd n)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
156 |
unfolding get_odd_def by (cases "odd n") auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
157 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
158 |
lemma get_even[simp]: "even (get_even n)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
159 |
unfolding get_even_def by (cases "even n") auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
160 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
161 |
lemma get_odd_ex: "\<exists> k. Suc k = get_odd n \<and> odd (Suc k)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
162 |
by (auto simp: get_odd_def odd_pos intro!: exI[of _ "n - 1"]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
163 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
164 |
lemma get_even_double: "\<exists>i. get_even n = 2 * i" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
165 |
using get_even by (blast elim: evenE) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
166 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
167 |
lemma get_odd_double: "\<exists>i. get_odd n = 2 * i + 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
168 |
using get_odd by (blast elim: oddE) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
169 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
170 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
171 |
section "Power function" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
172 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
173 |
definition float_power_bnds :: "nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float * float" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
174 |
"float_power_bnds prec n l u = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
175 |
(if 0 < l then (power_down_fl prec l n, power_up_fl prec u n) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
176 |
else if odd n then |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
177 |
(- power_up_fl prec \<bar>l\<bar> n, |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
178 |
if u < 0 then - power_down_fl prec \<bar>u\<bar> n else power_up_fl prec u n) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
179 |
else if u < 0 then (power_down_fl prec \<bar>u\<bar> n, power_up_fl prec \<bar>l\<bar> n) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
180 |
else (0, power_up_fl prec (max \<bar>l\<bar> \<bar>u\<bar>) n))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
181 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
182 |
lemma le_minus_power_downI: "0 \<le> x \<Longrightarrow> x ^ n \<le> - a \<Longrightarrow> a \<le> - power_down prec x n" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
183 |
by (subst le_minus_iff) (auto intro: power_down_le power_mono_odd) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
184 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
185 |
lemma float_power_bnds: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
186 |
"(l1, u1) = float_power_bnds prec n l u \<Longrightarrow> x \<in> {l .. u} \<Longrightarrow> (x::real) ^ n \<in> {l1..u1}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
187 |
by (auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
188 |
simp: float_power_bnds_def max_def real_power_up_fl real_power_down_fl minus_le_iff |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
189 |
split: if_split_asm |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
190 |
intro!: power_up_le power_down_le le_minus_power_downI |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
191 |
intro: power_mono_odd power_mono power_mono_even zero_le_even_power) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
192 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
193 |
lemma bnds_power: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
194 |
"\<forall>(x::real) l u. (l1, u1) = float_power_bnds prec n l u \<and> x \<in> {l .. u} \<longrightarrow> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
195 |
l1 \<le> x ^ n \<and> x ^ n \<le> u1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
196 |
using float_power_bnds by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
197 |
|
71036 | 198 |
lift_definition power_float_interval :: "nat \<Rightarrow> nat \<Rightarrow> float interval \<Rightarrow> float interval" |
199 |
is "\<lambda>p n (l, u). float_power_bnds p n l u" |
|
200 |
using float_power_bnds |
|
201 |
by (auto simp: bnds_power dest!: float_power_bnds[OF sym]) |
|
202 |
||
203 |
lemma lower_power_float_interval: |
|
204 |
"lower (power_float_interval p n x) = fst (float_power_bnds p n (lower x) (upper x))" |
|
205 |
by transfer auto |
|
206 |
lemma upper_power_float_interval: |
|
207 |
"upper (power_float_interval p n x) = snd (float_power_bnds p n (lower x) (upper x))" |
|
208 |
by transfer auto |
|
209 |
||
210 |
lemma power_float_intervalI: "x \<in>\<^sub>r X \<Longrightarrow> x ^ n \<in>\<^sub>r power_float_interval p n X" |
|
211 |
using float_power_bnds[OF prod.collapse] |
|
212 |
by (auto simp: set_of_eq lower_power_float_interval upper_power_float_interval) |
|
213 |
||
214 |
lemma power_float_interval_mono: |
|
215 |
"set_of (power_float_interval prec n A) |
|
216 |
\<subseteq> set_of (power_float_interval prec n B)" |
|
217 |
if "set_of A \<subseteq> set_of B" |
|
218 |
proof - |
|
219 |
define la where "la = real_of_float (lower A)" |
|
220 |
define ua where "ua = real_of_float (upper A)" |
|
221 |
define lb where "lb = real_of_float (lower B)" |
|
222 |
define ub where "ub = real_of_float (upper B)" |
|
223 |
have ineqs: "lb \<le> la" "la \<le> ua" "ua \<le> ub" "lb \<le> ub" |
|
224 |
using that lower_le_upper[of A] lower_le_upper[of B] |
|
225 |
by (auto simp: la_def ua_def lb_def ub_def set_of_eq) |
|
226 |
show ?thesis |
|
227 |
using ineqs |
|
228 |
by (simp add: set_of_subset_iff float_power_bnds_def max_def |
|
229 |
power_down_fl.rep_eq power_up_fl.rep_eq |
|
230 |
lower_power_float_interval upper_power_float_interval |
|
231 |
la_def[symmetric] ua_def[symmetric] lb_def[symmetric] ub_def[symmetric]) |
|
232 |
(auto intro!: power_down_mono power_up_mono intro: order_trans[where y=0]) |
|
233 |
qed |
|
234 |
||
235 |
||
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
236 |
section \<open>Approximation utility functions\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
237 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
238 |
definition bnds_mult :: "nat \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float \<times> float" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
239 |
"bnds_mult prec a1 a2 b1 b2 = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
240 |
(float_plus_down prec (nprt a1 * pprt b2) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
241 |
(float_plus_down prec (nprt a2 * nprt b2) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
242 |
(float_plus_down prec (pprt a1 * pprt b1) (pprt a2 * nprt b1))), |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
243 |
float_plus_up prec (pprt a2 * pprt b2) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
244 |
(float_plus_up prec (pprt a1 * nprt b2) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
245 |
(float_plus_up prec (nprt a2 * pprt b1) (nprt a1 * nprt b1))))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
246 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
247 |
lemma bnds_mult: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
248 |
fixes prec :: nat and a1 aa2 b1 b2 :: float |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
249 |
assumes "(l, u) = bnds_mult prec a1 a2 b1 b2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
250 |
assumes "a \<in> {real_of_float a1..real_of_float a2}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
251 |
assumes "b \<in> {real_of_float b1..real_of_float b2}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
252 |
shows "a * b \<in> {real_of_float l..real_of_float u}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
253 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
254 |
from assms have "real_of_float l \<le> a * b" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
255 |
by (intro order.trans[OF _ mult_ge_prts[of a1 a a2 b1 b b2]]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
256 |
(auto simp: bnds_mult_def intro!: float_plus_down_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
257 |
moreover from assms have "real_of_float u \<ge> a * b" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
258 |
by (intro order.trans[OF mult_le_prts[of a1 a a2 b1 b b2]]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
259 |
(auto simp: bnds_mult_def intro!: float_plus_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
260 |
ultimately show ?thesis by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
261 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
262 |
|
71036 | 263 |
lift_definition mult_float_interval::"nat \<Rightarrow> float interval \<Rightarrow> float interval \<Rightarrow> float interval" |
264 |
is "\<lambda>prec. \<lambda>(a1, a2). \<lambda>(b1, b2). bnds_mult prec a1 a2 b1 b2" |
|
265 |
by (auto dest!: bnds_mult[OF sym]) |
|
266 |
||
267 |
lemma lower_mult_float_interval: |
|
268 |
"lower (mult_float_interval p x y) = fst (bnds_mult p (lower x) (upper x) (lower y) (upper y))" |
|
269 |
by transfer auto |
|
270 |
lemma upper_mult_float_interval: |
|
271 |
"upper (mult_float_interval p x y) = snd (bnds_mult p (lower x) (upper x) (lower y) (upper y))" |
|
272 |
by transfer auto |
|
273 |
||
274 |
lemma mult_float_interval: |
|
275 |
"set_of (real_interval A) * set_of (real_interval B) \<subseteq> |
|
276 |
set_of (real_interval (mult_float_interval prec A B))" |
|
277 |
proof - |
|
278 |
let ?bm = "bnds_mult prec (lower A) (upper A) (lower B) (upper B)" |
|
279 |
show ?thesis |
|
280 |
using bnds_mult[of "fst ?bm" "snd ?bm", simplified, OF refl] |
|
281 |
by (auto simp: set_of_eq set_times_def upper_mult_float_interval lower_mult_float_interval) |
|
282 |
qed |
|
283 |
||
284 |
lemma mult_float_intervalI: |
|
285 |
"x * y \<in>\<^sub>r mult_float_interval prec A B" |
|
286 |
if "x \<in>\<^sub>i real_interval A" "y \<in>\<^sub>i real_interval B" |
|
287 |
using mult_float_interval[of A B] that |
|
288 |
by (auto simp: ) |
|
289 |
||
290 |
lemma mult_float_interval_mono: |
|
291 |
"set_of (mult_float_interval prec A B) \<subseteq> set_of (mult_float_interval prec X Y)" |
|
292 |
if "set_of A \<subseteq> set_of X" "set_of B \<subseteq> set_of Y" |
|
293 |
using that |
|
294 |
apply transfer |
|
295 |
unfolding bnds_mult_def atLeastatMost_subset_iff float_plus_down.rep_eq float_plus_up.rep_eq |
|
296 |
by (auto simp: float_plus_down.rep_eq float_plus_up.rep_eq mult_float_mono1 mult_float_mono2) |
|
297 |
||
298 |
||
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
299 |
definition map_bnds :: "(nat \<Rightarrow> float \<Rightarrow> float) \<Rightarrow> (nat \<Rightarrow> float \<Rightarrow> float) \<Rightarrow> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
300 |
nat \<Rightarrow> (float \<times> float) \<Rightarrow> (float \<times> float)" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
301 |
"map_bnds lb ub prec = (\<lambda>(l,u). (lb prec l, ub prec u))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
302 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
303 |
lemma map_bnds: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
304 |
assumes "(lf, uf) = map_bnds lb ub prec (l, u)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
305 |
assumes "mono f" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
306 |
assumes "x \<in> {real_of_float l..real_of_float u}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
307 |
assumes "real_of_float (lb prec l) \<le> f (real_of_float l)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
308 |
assumes "real_of_float (ub prec u) \<ge> f (real_of_float u)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
309 |
shows "f x \<in> {real_of_float lf..real_of_float uf}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
310 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
311 |
from assms have "real_of_float lf = real_of_float (lb prec l)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
312 |
by (simp add: map_bnds_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
313 |
also have "real_of_float (lb prec l) \<le> f (real_of_float l)" by fact |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
314 |
also from assms have "\<dots> \<le> f x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
315 |
by (intro monoD[OF \<open>mono f\<close>]) auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
316 |
finally have lf: "real_of_float lf \<le> f x" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
317 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
318 |
from assms have "f x \<le> f (real_of_float u)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
319 |
by (intro monoD[OF \<open>mono f\<close>]) auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
320 |
also have "\<dots> \<le> real_of_float (ub prec u)" by fact |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
321 |
also from assms have "\<dots> = real_of_float uf" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
322 |
by (simp add: map_bnds_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
323 |
finally have uf: "f x \<le> real_of_float uf" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
324 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
325 |
from lf uf show ?thesis by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
326 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
327 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
328 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
329 |
section "Square root" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
330 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
331 |
text \<open> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
332 |
The square root computation is implemented as newton iteration. As first first step we use the |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
333 |
nearest power of two greater than the square root. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
334 |
\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
335 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
336 |
fun sqrt_iteration :: "nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
337 |
"sqrt_iteration prec 0 x = Float 1 ((bitlen \<bar>mantissa x\<bar> + exponent x) div 2 + 1)" | |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
338 |
"sqrt_iteration prec (Suc m) x = (let y = sqrt_iteration prec m x |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
339 |
in Float 1 (- 1) * float_plus_up prec y (float_divr prec x y))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
340 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
341 |
lemma compute_sqrt_iteration_base[code]: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
342 |
shows "sqrt_iteration prec n (Float m e) = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
343 |
(if n = 0 then Float 1 ((if m = 0 then 0 else bitlen \<bar>m\<bar> + e) div 2 + 1) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
344 |
else (let y = sqrt_iteration prec (n - 1) (Float m e) in |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
345 |
Float 1 (- 1) * float_plus_up prec y (float_divr prec (Float m e) y)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
346 |
using bitlen_Float by (cases n) simp_all |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
347 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
348 |
function ub_sqrt lb_sqrt :: "nat \<Rightarrow> float \<Rightarrow> float" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
349 |
"ub_sqrt prec x = (if 0 < x then (sqrt_iteration prec prec x) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
350 |
else if x < 0 then - lb_sqrt prec (- x) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
351 |
else 0)" | |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
352 |
"lb_sqrt prec x = (if 0 < x then (float_divl prec x (sqrt_iteration prec prec x)) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
353 |
else if x < 0 then - ub_sqrt prec (- x) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
354 |
else 0)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
355 |
by pat_completeness auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
356 |
termination by (relation "measure (\<lambda> v. let (prec, x) = case_sum id id v in (if x < 0 then 1 else 0))", auto) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
357 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
358 |
declare lb_sqrt.simps[simp del] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
359 |
declare ub_sqrt.simps[simp del] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
360 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
361 |
lemma sqrt_ub_pos_pos_1: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
362 |
assumes "sqrt x < b" and "0 < b" and "0 < x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
363 |
shows "sqrt x < (b + x / b)/2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
364 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
365 |
from assms have "0 < (b - sqrt x)\<^sup>2 " by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
366 |
also have "\<dots> = b\<^sup>2 - 2 * b * sqrt x + (sqrt x)\<^sup>2" by algebra |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
367 |
also have "\<dots> = b\<^sup>2 - 2 * b * sqrt x + x" using assms by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
368 |
finally have "0 < b\<^sup>2 - 2 * b * sqrt x + x" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
369 |
hence "0 < b / 2 - sqrt x + x / (2 * b)" using assms |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
370 |
by (simp add: field_simps power2_eq_square) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
371 |
thus ?thesis by (simp add: field_simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
372 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
373 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
374 |
lemma sqrt_iteration_bound: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
375 |
assumes "0 < real_of_float x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
376 |
shows "sqrt x < sqrt_iteration prec n x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
377 |
proof (induct n) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
378 |
case 0 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
379 |
show ?case |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
380 |
proof (cases x) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
381 |
case (Float m e) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
382 |
hence "0 < m" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
383 |
using assms |
70817
dd675800469d
dedicated fact collections for algebraic simplification rules potentially splitting goals
haftmann
parents:
70350
diff
changeset
|
384 |
by (auto simp: algebra_split_simps) |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
385 |
hence "0 < sqrt m" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
386 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
387 |
have int_nat_bl: "(nat (bitlen m)) = bitlen m" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
388 |
using bitlen_nonneg by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
389 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
390 |
have "x = (m / 2^nat (bitlen m)) * 2 powr (e + (nat (bitlen m)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
391 |
unfolding Float by (auto simp: powr_realpow[symmetric] field_simps powr_add) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
392 |
also have "\<dots> < 1 * 2 powr (e + nat (bitlen m))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
393 |
proof (rule mult_strict_right_mono, auto) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
394 |
show "m < 2^nat (bitlen m)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
395 |
using bitlen_bounds[OF \<open>0 < m\<close>, THEN conjunct2] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
396 |
unfolding of_int_less_iff[of m, symmetric] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
397 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
398 |
finally have "sqrt x < sqrt (2 powr (e + bitlen m))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
399 |
unfolding int_nat_bl by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
400 |
also have "\<dots> \<le> 2 powr ((e + bitlen m) div 2 + 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
401 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
402 |
let ?E = "e + bitlen m" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
403 |
have E_mod_pow: "2 powr (?E mod 2) < 4" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
404 |
proof (cases "?E mod 2 = 1") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
405 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
406 |
thus ?thesis by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
407 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
408 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
409 |
have "0 \<le> ?E mod 2" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
410 |
have "?E mod 2 < 2" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
411 |
from this[THEN zless_imp_add1_zle] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
412 |
have "?E mod 2 \<le> 0" using False by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
413 |
from xt1(5)[OF \<open>0 \<le> ?E mod 2\<close> this] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
414 |
show ?thesis by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
415 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
416 |
hence "sqrt (2 powr (?E mod 2)) < sqrt (2 * 2)" |
66280
0c5eb47e2696
Adapted Approximation_Bounds to changes in Multiset
eberlm <eberlm@in.tum.de>
parents:
65582
diff
changeset
|
417 |
by (intro real_sqrt_less_mono) auto |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
418 |
hence E_mod_pow: "sqrt (2 powr (?E mod 2)) < 2" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
419 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
420 |
have E_eq: "2 powr ?E = 2 powr (?E div 2 + ?E div 2 + ?E mod 2)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
421 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
422 |
have "sqrt (2 powr ?E) = sqrt (2 powr (?E div 2) * 2 powr (?E div 2) * 2 powr (?E mod 2))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
423 |
unfolding E_eq unfolding powr_add[symmetric] by (metis of_int_add) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
424 |
also have "\<dots> = 2 powr (?E div 2) * sqrt (2 powr (?E mod 2))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
425 |
unfolding real_sqrt_mult[of _ "2 powr (?E mod 2)"] real_sqrt_abs2 by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
426 |
also have "\<dots> < 2 powr (?E div 2) * 2 powr 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
427 |
by (rule mult_strict_left_mono) (auto intro: E_mod_pow) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
428 |
also have "\<dots> = 2 powr (?E div 2 + 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
429 |
unfolding add.commute[of _ 1] powr_add[symmetric] by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
430 |
finally show ?thesis by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
431 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
432 |
finally show ?thesis using \<open>0 < m\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
433 |
unfolding Float |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
434 |
by (subst compute_sqrt_iteration_base) (simp add: ac_simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
435 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
436 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
437 |
case (Suc n) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
438 |
let ?b = "sqrt_iteration prec n x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
439 |
have "0 < sqrt x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
440 |
using \<open>0 < real_of_float x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
441 |
also have "\<dots> < real_of_float ?b" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
442 |
using Suc . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
443 |
finally have "sqrt x < (?b + x / ?b)/2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
444 |
using sqrt_ub_pos_pos_1[OF Suc _ \<open>0 < real_of_float x\<close>] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
445 |
also have "\<dots> \<le> (?b + (float_divr prec x ?b))/2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
446 |
by (rule divide_right_mono, auto simp add: float_divr) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
447 |
also have "\<dots> = (Float 1 (- 1)) * (?b + (float_divr prec x ?b))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
448 |
by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
449 |
also have "\<dots> \<le> (Float 1 (- 1)) * (float_plus_up prec ?b (float_divr prec x ?b))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
450 |
by (auto simp add: algebra_simps float_plus_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
451 |
finally show ?case |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
452 |
unfolding sqrt_iteration.simps Let_def distrib_left . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
453 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
454 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
455 |
lemma sqrt_iteration_lower_bound: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
456 |
assumes "0 < real_of_float x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
457 |
shows "0 < real_of_float (sqrt_iteration prec n x)" (is "0 < ?sqrt") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
458 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
459 |
have "0 < sqrt x" using assms by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
460 |
also have "\<dots> < ?sqrt" using sqrt_iteration_bound[OF assms] . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
461 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
462 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
463 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
464 |
lemma lb_sqrt_lower_bound: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
465 |
assumes "0 \<le> real_of_float x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
466 |
shows "0 \<le> real_of_float (lb_sqrt prec x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
467 |
proof (cases "0 < x") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
468 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
469 |
hence "0 < real_of_float x" and "0 \<le> x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
470 |
using \<open>0 \<le> real_of_float x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
471 |
hence "0 < sqrt_iteration prec prec x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
472 |
using sqrt_iteration_lower_bound by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
473 |
hence "0 \<le> real_of_float (float_divl prec x (sqrt_iteration prec prec x))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
474 |
using float_divl_lower_bound[OF \<open>0 \<le> x\<close>] unfolding less_eq_float_def by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
475 |
thus ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
476 |
unfolding lb_sqrt.simps using True by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
477 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
478 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
479 |
with \<open>0 \<le> real_of_float x\<close> have "real_of_float x = 0" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
480 |
thus ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
481 |
unfolding lb_sqrt.simps by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
482 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
483 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
484 |
lemma bnds_sqrt': "sqrt x \<in> {(lb_sqrt prec x) .. (ub_sqrt prec x)}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
485 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
486 |
have lb: "lb_sqrt prec x \<le> sqrt x" if "0 < x" for x :: float |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
487 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
488 |
from that have "0 < real_of_float x" and "0 \<le> real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
489 |
hence sqrt_gt0: "0 < sqrt x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
490 |
hence sqrt_ub: "sqrt x < sqrt_iteration prec prec x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
491 |
using sqrt_iteration_bound by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
492 |
have "(float_divl prec x (sqrt_iteration prec prec x)) \<le> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
493 |
x / (sqrt_iteration prec prec x)" by (rule float_divl) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
494 |
also have "\<dots> < x / sqrt x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
495 |
by (rule divide_strict_left_mono[OF sqrt_ub \<open>0 < real_of_float x\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
496 |
mult_pos_pos[OF order_less_trans[OF sqrt_gt0 sqrt_ub] sqrt_gt0]]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
497 |
also have "\<dots> = sqrt x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
498 |
unfolding inverse_eq_iff_eq[of _ "sqrt x", symmetric] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
499 |
sqrt_divide_self_eq[OF \<open>0 \<le> real_of_float x\<close>, symmetric] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
500 |
finally show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
501 |
unfolding lb_sqrt.simps if_P[OF \<open>0 < x\<close>] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
502 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
503 |
have ub: "sqrt x \<le> ub_sqrt prec x" if "0 < x" for x :: float |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
504 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
505 |
from that have "0 < real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
506 |
hence "0 < sqrt x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
507 |
hence "sqrt x < sqrt_iteration prec prec x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
508 |
using sqrt_iteration_bound by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
509 |
then show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
510 |
unfolding ub_sqrt.simps if_P[OF \<open>0 < x\<close>] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
511 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
512 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
513 |
using lb[of "-x"] ub[of "-x"] lb[of x] ub[of x] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
514 |
by (auto simp add: lb_sqrt.simps ub_sqrt.simps real_sqrt_minus) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
515 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
516 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
517 |
lemma bnds_sqrt: "\<forall>(x::real) lx ux. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
518 |
(l, u) = (lb_sqrt prec lx, ub_sqrt prec ux) \<and> x \<in> {lx .. ux} \<longrightarrow> l \<le> sqrt x \<and> sqrt x \<le> u" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
519 |
proof ((rule allI) +, rule impI, erule conjE, rule conjI) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
520 |
fix x :: real |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
521 |
fix lx ux |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
522 |
assume "(l, u) = (lb_sqrt prec lx, ub_sqrt prec ux)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
523 |
and x: "x \<in> {lx .. ux}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
524 |
hence l: "l = lb_sqrt prec lx " and u: "u = ub_sqrt prec ux" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
525 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
526 |
have "sqrt lx \<le> sqrt x" using x by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
527 |
from order_trans[OF _ this] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
528 |
show "l \<le> sqrt x" unfolding l using bnds_sqrt'[of lx prec] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
529 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
530 |
have "sqrt x \<le> sqrt ux" using x by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
531 |
from order_trans[OF this] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
532 |
show "sqrt x \<le> u" unfolding u using bnds_sqrt'[of ux prec] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
533 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
534 |
|
71036 | 535 |
lift_definition sqrt_float_interval::"nat \<Rightarrow> float interval \<Rightarrow> float interval" |
536 |
is "\<lambda>prec. \<lambda>(lx, ux). (lb_sqrt prec lx, ub_sqrt prec ux)" |
|
537 |
using bnds_sqrt' |
|
538 |
by auto (meson order_trans real_sqrt_le_iff) |
|
539 |
||
540 |
lemma lower_float_interval: "lower (sqrt_float_interval prec X) = lb_sqrt prec (lower X)" |
|
541 |
by transfer auto |
|
542 |
||
543 |
lemma upper_float_interval: "upper (sqrt_float_interval prec X) = ub_sqrt prec (upper X)" |
|
544 |
by transfer auto |
|
545 |
||
546 |
lemma sqrt_float_interval: |
|
547 |
"sqrt ` set_of (real_interval X) \<subseteq> set_of (real_interval (sqrt_float_interval prec X))" |
|
548 |
using bnds_sqrt |
|
549 |
by (auto simp: set_of_eq lower_float_interval upper_float_interval) |
|
550 |
||
551 |
lemma sqrt_float_intervalI: "sqrt x \<in>\<^sub>r sqrt_float_interval p X" if "x \<in>\<^sub>r X" |
|
552 |
using sqrt_float_interval[of X p] that |
|
553 |
by auto |
|
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
554 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
555 |
section "Arcus tangens and \<pi>" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
556 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
557 |
subsection "Compute arcus tangens series" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
558 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
559 |
text \<open> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
560 |
As first step we implement the computation of the arcus tangens series. This is only valid in the range |
69597 | 561 |
\<^term>\<open>{-1 :: real .. 1}\<close>. This is used to compute \<pi> and then the entire arcus tangens. |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
562 |
\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
563 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
564 |
fun ub_arctan_horner :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
565 |
and lb_arctan_horner :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
566 |
"ub_arctan_horner prec 0 k x = 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
567 |
| "ub_arctan_horner prec (Suc n) k x = float_plus_up prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
568 |
(rapprox_rat prec 1 k) (- float_round_down prec (x * (lb_arctan_horner prec n (k + 2) x)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
569 |
| "lb_arctan_horner prec 0 k x = 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
570 |
| "lb_arctan_horner prec (Suc n) k x = float_plus_down prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
571 |
(lapprox_rat prec 1 k) (- float_round_up prec (x * (ub_arctan_horner prec n (k + 2) x)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
572 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
573 |
lemma arctan_0_1_bounds': |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
574 |
assumes "0 \<le> real_of_float y" "real_of_float y \<le> 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
575 |
and "even n" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
576 |
shows "arctan (sqrt y) \<in> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
577 |
{(sqrt y * lb_arctan_horner prec n 1 y) .. (sqrt y * ub_arctan_horner prec (Suc n) 1 y)}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
578 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
579 |
let ?c = "\<lambda>i. (- 1) ^ i * (1 / (i * 2 + (1::nat)) * sqrt y ^ (i * 2 + 1))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
580 |
let ?S = "\<lambda>n. \<Sum> i=0..<n. ?c i" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
581 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
582 |
have "0 \<le> sqrt y" using assms by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
583 |
have "sqrt y \<le> 1" using assms by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
584 |
from \<open>even n\<close> obtain m where "2 * m = n" by (blast elim: evenE) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
585 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
586 |
have "arctan (sqrt y) \<in> { ?S n .. ?S (Suc n) }" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
587 |
proof (cases "sqrt y = 0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
588 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
589 |
then show ?thesis by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
590 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
591 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
592 |
hence "0 < sqrt y" using \<open>0 \<le> sqrt y\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
593 |
hence prem: "0 < 1 / (0 * 2 + (1::nat)) * sqrt y ^ (0 * 2 + 1)" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
594 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
595 |
have "\<bar> sqrt y \<bar> \<le> 1" using \<open>0 \<le> sqrt y\<close> \<open>sqrt y \<le> 1\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
596 |
from mp[OF summable_Leibniz(2)[OF zeroseq_arctan_series[OF this] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
597 |
monoseq_arctan_series[OF this]] prem, THEN spec, of m, unfolded \<open>2 * m = n\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
598 |
show ?thesis unfolding arctan_series[OF \<open>\<bar> sqrt y \<bar> \<le> 1\<close>] Suc_eq_plus1 atLeast0LessThan . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
599 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
600 |
note arctan_bounds = this[unfolded atLeastAtMost_iff] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
601 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
602 |
have F: "\<And>n. 2 * Suc n + 1 = 2 * n + 1 + 2" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
603 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
604 |
note bounds = horner_bounds[where s=1 and f="\<lambda>i. 2 * i + 1" and j'=0 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
605 |
and lb="\<lambda>n i k x. lb_arctan_horner prec n k x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
606 |
and ub="\<lambda>n i k x. ub_arctan_horner prec n k x", |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
607 |
OF \<open>0 \<le> real_of_float y\<close> F lb_arctan_horner.simps ub_arctan_horner.simps] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
608 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
609 |
have "(sqrt y * lb_arctan_horner prec n 1 y) \<le> arctan (sqrt y)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
610 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
611 |
have "(sqrt y * lb_arctan_horner prec n 1 y) \<le> ?S n" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
612 |
using bounds(1) \<open>0 \<le> sqrt y\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
613 |
apply (simp only: power_add power_one_right mult.assoc[symmetric] sum_distrib_right[symmetric]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
614 |
apply (simp only: mult.commute[where 'a=real] mult.commute[of _ "2::nat"] power_mult) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
615 |
apply (auto intro!: mult_left_mono) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
616 |
done |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
617 |
also have "\<dots> \<le> arctan (sqrt y)" using arctan_bounds .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
618 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
619 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
620 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
621 |
have "arctan (sqrt y) \<le> (sqrt y * ub_arctan_horner prec (Suc n) 1 y)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
622 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
623 |
have "arctan (sqrt y) \<le> ?S (Suc n)" using arctan_bounds .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
624 |
also have "\<dots> \<le> (sqrt y * ub_arctan_horner prec (Suc n) 1 y)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
625 |
using bounds(2)[of "Suc n"] \<open>0 \<le> sqrt y\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
626 |
apply (simp only: power_add power_one_right mult.assoc[symmetric] sum_distrib_right[symmetric]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
627 |
apply (simp only: mult.commute[where 'a=real] mult.commute[of _ "2::nat"] power_mult) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
628 |
apply (auto intro!: mult_left_mono) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
629 |
done |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
630 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
631 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
632 |
ultimately show ?thesis by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
633 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
634 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
635 |
lemma arctan_0_1_bounds: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
636 |
assumes "0 \<le> real_of_float y" "real_of_float y \<le> 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
637 |
shows "arctan (sqrt y) \<in> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
638 |
{(sqrt y * lb_arctan_horner prec (get_even n) 1 y) .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
639 |
(sqrt y * ub_arctan_horner prec (get_odd n) 1 y)}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
640 |
using |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
641 |
arctan_0_1_bounds'[OF assms, of n prec] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
642 |
arctan_0_1_bounds'[OF assms, of "n + 1" prec] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
643 |
arctan_0_1_bounds'[OF assms, of "n - 1" prec] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
644 |
by (auto simp: get_even_def get_odd_def odd_pos |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
645 |
simp del: ub_arctan_horner.simps lb_arctan_horner.simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
646 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
647 |
lemma arctan_lower_bound: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
648 |
assumes "0 \<le> x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
649 |
shows "x / (1 + x\<^sup>2) \<le> arctan x" (is "?l x \<le> _") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
650 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
651 |
have "?l x - arctan x \<le> ?l 0 - arctan 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
652 |
using assms |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
653 |
by (intro DERIV_nonpos_imp_nonincreasing[where f="\<lambda>x. ?l x - arctan x"]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
654 |
(auto intro!: derivative_eq_intros simp: add_nonneg_eq_0_iff field_simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
655 |
thus ?thesis by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
656 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
657 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
658 |
lemma arctan_divide_mono: "0 < x \<Longrightarrow> x \<le> y \<Longrightarrow> arctan y / y \<le> arctan x / x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
659 |
by (rule DERIV_nonpos_imp_nonincreasing[where f="\<lambda>x. arctan x / x"]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
660 |
(auto intro!: derivative_eq_intros divide_nonpos_nonneg |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
661 |
simp: inverse_eq_divide arctan_lower_bound) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
662 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
663 |
lemma arctan_mult_mono: "0 \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> x * arctan y \<le> y * arctan x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
664 |
using arctan_divide_mono[of x y] by (cases "x = 0") (simp_all add: field_simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
665 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
666 |
lemma arctan_mult_le: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
667 |
assumes "0 \<le> x" "x \<le> y" "y * z \<le> arctan y" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
668 |
shows "x * z \<le> arctan x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
669 |
proof (cases "x = 0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
670 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
671 |
then show ?thesis by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
672 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
673 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
674 |
with assms have "z \<le> arctan y / y" by (simp add: field_simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
675 |
also have "\<dots> \<le> arctan x / x" using assms \<open>x \<noteq> 0\<close> by (auto intro!: arctan_divide_mono) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
676 |
finally show ?thesis using assms \<open>x \<noteq> 0\<close> by (simp add: field_simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
677 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
678 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
679 |
lemma arctan_le_mult: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
680 |
assumes "0 < x" "x \<le> y" "arctan x \<le> x * z" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
681 |
shows "arctan y \<le> y * z" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
682 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
683 |
from assms have "arctan y / y \<le> arctan x / x" by (auto intro!: arctan_divide_mono) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
684 |
also have "\<dots> \<le> z" using assms by (auto simp: field_simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
685 |
finally show ?thesis using assms by (simp add: field_simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
686 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
687 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
688 |
lemma arctan_0_1_bounds_le: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
689 |
assumes "0 \<le> x" "x \<le> 1" "0 < real_of_float xl" "real_of_float xl \<le> x * x" "x * x \<le> real_of_float xu" "real_of_float xu \<le> 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
690 |
shows "arctan x \<in> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
691 |
{x * lb_arctan_horner p1 (get_even n) 1 xu .. x * ub_arctan_horner p2 (get_odd n) 1 xl}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
692 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
693 |
from assms have "real_of_float xl \<le> 1" "sqrt (real_of_float xl) \<le> x" "x \<le> sqrt (real_of_float xu)" "0 \<le> real_of_float xu" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
694 |
"0 \<le> real_of_float xl" "0 < sqrt (real_of_float xl)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
695 |
by (auto intro!: real_le_rsqrt real_le_lsqrt simp: power2_eq_square) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
696 |
from arctan_0_1_bounds[OF \<open>0 \<le> real_of_float xu\<close> \<open>real_of_float xu \<le> 1\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
697 |
have "sqrt (real_of_float xu) * real_of_float (lb_arctan_horner p1 (get_even n) 1 xu) \<le> arctan (sqrt (real_of_float xu))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
698 |
by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
699 |
from arctan_mult_le[OF \<open>0 \<le> x\<close> \<open>x \<le> sqrt _\<close> this] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
700 |
have "x * real_of_float (lb_arctan_horner p1 (get_even n) 1 xu) \<le> arctan x" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
701 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
702 |
from arctan_0_1_bounds[OF \<open>0 \<le> real_of_float xl\<close> \<open>real_of_float xl \<le> 1\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
703 |
have "arctan (sqrt (real_of_float xl)) \<le> sqrt (real_of_float xl) * real_of_float (ub_arctan_horner p2 (get_odd n) 1 xl)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
704 |
by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
705 |
from arctan_le_mult[OF \<open>0 < sqrt xl\<close> \<open>sqrt xl \<le> x\<close> this] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
706 |
have "arctan x \<le> x * real_of_float (ub_arctan_horner p2 (get_odd n) 1 xl)" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
707 |
ultimately show ?thesis by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
708 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
709 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
710 |
lemma arctan_0_1_bounds_round: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
711 |
assumes "0 \<le> real_of_float x" "real_of_float x \<le> 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
712 |
shows "arctan x \<in> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
713 |
{real_of_float x * lb_arctan_horner p1 (get_even n) 1 (float_round_up (Suc p2) (x * x)) .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
714 |
real_of_float x * ub_arctan_horner p3 (get_odd n) 1 (float_round_down (Suc p4) (x * x))}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
715 |
using assms |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
716 |
apply (cases "x > 0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
717 |
apply (intro arctan_0_1_bounds_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
718 |
apply (auto simp: float_round_down.rep_eq float_round_up.rep_eq |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
719 |
intro!: truncate_up_le1 mult_le_one truncate_down_le truncate_up_le truncate_down_pos |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
720 |
mult_pos_pos) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
721 |
done |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
722 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
723 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
724 |
subsection "Compute \<pi>" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
725 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
726 |
definition ub_pi :: "nat \<Rightarrow> float" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
727 |
"ub_pi prec = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
728 |
(let |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
729 |
A = rapprox_rat prec 1 5 ; |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
730 |
B = lapprox_rat prec 1 239 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
731 |
in ((Float 1 2) * float_plus_up prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
732 |
((Float 1 2) * float_round_up prec (A * (ub_arctan_horner prec (get_odd (prec div 4 + 1)) 1 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
733 |
(float_round_down (Suc prec) (A * A))))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
734 |
(- float_round_down prec (B * (lb_arctan_horner prec (get_even (prec div 14 + 1)) 1 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
735 |
(float_round_up (Suc prec) (B * B)))))))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
736 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
737 |
definition lb_pi :: "nat \<Rightarrow> float" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
738 |
"lb_pi prec = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
739 |
(let |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
740 |
A = lapprox_rat prec 1 5 ; |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
741 |
B = rapprox_rat prec 1 239 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
742 |
in ((Float 1 2) * float_plus_down prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
743 |
((Float 1 2) * float_round_down prec (A * (lb_arctan_horner prec (get_even (prec div 4 + 1)) 1 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
744 |
(float_round_up (Suc prec) (A * A))))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
745 |
(- float_round_up prec (B * (ub_arctan_horner prec (get_odd (prec div 14 + 1)) 1 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
746 |
(float_round_down (Suc prec) (B * B)))))))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
747 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
748 |
lemma pi_boundaries: "pi \<in> {(lb_pi n) .. (ub_pi n)}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
749 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
750 |
have machin_pi: "pi = 4 * (4 * arctan (1 / 5) - arctan (1 / 239))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
751 |
unfolding machin[symmetric] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
752 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
753 |
{ |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
754 |
fix prec n :: nat |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
755 |
fix k :: int |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
756 |
assume "1 < k" hence "0 \<le> k" and "0 < k" and "1 \<le> k" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
757 |
let ?k = "rapprox_rat prec 1 k" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
758 |
let ?kl = "float_round_down (Suc prec) (?k * ?k)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
759 |
have "1 div k = 0" using div_pos_pos_trivial[OF _ \<open>1 < k\<close>] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
760 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
761 |
have "0 \<le> real_of_float ?k" by (rule order_trans[OF _ rapprox_rat]) (auto simp add: \<open>0 \<le> k\<close>) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
762 |
have "real_of_float ?k \<le> 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
763 |
by (auto simp add: \<open>0 < k\<close> \<open>1 \<le> k\<close> less_imp_le |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
764 |
intro!: mult_le_one order_trans[OF _ rapprox_rat] rapprox_rat_le1) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
765 |
have "1 / k \<le> ?k" using rapprox_rat[where x=1 and y=k] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
766 |
hence "arctan (1 / k) \<le> arctan ?k" by (rule arctan_monotone') |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
767 |
also have "\<dots> \<le> (?k * ub_arctan_horner prec (get_odd n) 1 ?kl)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
768 |
using arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float ?k\<close> \<open>real_of_float ?k \<le> 1\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
769 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
770 |
finally have "arctan (1 / k) \<le> ?k * ub_arctan_horner prec (get_odd n) 1 ?kl" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
771 |
} note ub_arctan = this |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
772 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
773 |
{ |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
774 |
fix prec n :: nat |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
775 |
fix k :: int |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
776 |
assume "1 < k" hence "0 \<le> k" and "0 < k" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
777 |
let ?k = "lapprox_rat prec 1 k" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
778 |
let ?ku = "float_round_up (Suc prec) (?k * ?k)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
779 |
have "1 div k = 0" using div_pos_pos_trivial[OF _ \<open>1 < k\<close>] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
780 |
have "1 / k \<le> 1" using \<open>1 < k\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
781 |
have "0 \<le> real_of_float ?k" using lapprox_rat_nonneg[where x=1 and y=k, OF zero_le_one \<open>0 \<le> k\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
782 |
by (auto simp add: \<open>1 div k = 0\<close>) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
783 |
have "0 \<le> real_of_float (?k * ?k)" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
784 |
have "real_of_float ?k \<le> 1" using lapprox_rat by (rule order_trans, auto simp add: \<open>1 / k \<le> 1\<close>) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
785 |
hence "real_of_float (?k * ?k) \<le> 1" using \<open>0 \<le> real_of_float ?k\<close> by (auto intro!: mult_le_one) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
786 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
787 |
have "?k \<le> 1 / k" using lapprox_rat[where x=1 and y=k] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
788 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
789 |
have "?k * lb_arctan_horner prec (get_even n) 1 ?ku \<le> arctan ?k" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
790 |
using arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float ?k\<close> \<open>real_of_float ?k \<le> 1\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
791 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
792 |
also have "\<dots> \<le> arctan (1 / k)" using \<open>?k \<le> 1 / k\<close> by (rule arctan_monotone') |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
793 |
finally have "?k * lb_arctan_horner prec (get_even n) 1 ?ku \<le> arctan (1 / k)" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
794 |
} note lb_arctan = this |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
795 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
796 |
have "pi \<le> ub_pi n " |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
797 |
unfolding ub_pi_def machin_pi Let_def times_float.rep_eq Float_num |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
798 |
using lb_arctan[of 239] ub_arctan[of 5] powr_realpow[of 2 2] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
799 |
by (intro mult_left_mono float_plus_up_le float_plus_down_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
800 |
(auto intro!: mult_left_mono float_round_down_le float_round_up_le diff_mono) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
801 |
moreover have "lb_pi n \<le> pi" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
802 |
unfolding lb_pi_def machin_pi Let_def times_float.rep_eq Float_num |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
803 |
using lb_arctan[of 5] ub_arctan[of 239] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
804 |
by (intro mult_left_mono float_plus_up_le float_plus_down_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
805 |
(auto intro!: mult_left_mono float_round_down_le float_round_up_le diff_mono) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
806 |
ultimately show ?thesis by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
807 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
808 |
|
71036 | 809 |
lift_definition pi_float_interval::"nat \<Rightarrow> float interval" is "\<lambda>prec. (lb_pi prec, ub_pi prec)" |
810 |
using pi_boundaries |
|
811 |
by (auto intro: order_trans) |
|
812 |
||
813 |
lemma lower_pi_float_interval: "lower (pi_float_interval prec) = lb_pi prec" |
|
814 |
by transfer auto |
|
815 |
lemma upper_pi_float_interval: "upper (pi_float_interval prec) = ub_pi prec" |
|
816 |
by transfer auto |
|
817 |
lemma pi_float_interval: "pi \<in> set_of (real_interval (pi_float_interval prec))" |
|
818 |
using pi_boundaries |
|
819 |
by (auto simp: set_of_eq lower_pi_float_interval upper_pi_float_interval) |
|
820 |
||
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
821 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
822 |
subsection "Compute arcus tangens in the entire domain" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
823 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
824 |
function lb_arctan :: "nat \<Rightarrow> float \<Rightarrow> float" and ub_arctan :: "nat \<Rightarrow> float \<Rightarrow> float" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
825 |
"lb_arctan prec x = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
826 |
(let |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
827 |
ub_horner = \<lambda> x. float_round_up prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
828 |
(x * |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
829 |
ub_arctan_horner prec (get_odd (prec div 4 + 1)) 1 (float_round_down (Suc prec) (x * x))); |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
830 |
lb_horner = \<lambda> x. float_round_down prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
831 |
(x * |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
832 |
lb_arctan_horner prec (get_even (prec div 4 + 1)) 1 (float_round_up (Suc prec) (x * x))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
833 |
in |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
834 |
if x < 0 then - ub_arctan prec (-x) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
835 |
else if x \<le> Float 1 (- 1) then lb_horner x |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
836 |
else if x \<le> Float 1 1 then |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
837 |
Float 1 1 * |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
838 |
lb_horner |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
839 |
(float_divl prec x |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
840 |
(float_plus_up prec 1 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
841 |
(ub_sqrt prec (float_plus_up prec 1 (float_round_up prec (x * x)))))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
842 |
else let inv = float_divr prec 1 x in |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
843 |
if inv > 1 then 0 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
844 |
else float_plus_down prec (lb_pi prec * Float 1 (- 1)) ( - ub_horner inv))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
845 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
846 |
| "ub_arctan prec x = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
847 |
(let |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
848 |
lb_horner = \<lambda> x. float_round_down prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
849 |
(x * |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
850 |
lb_arctan_horner prec (get_even (prec div 4 + 1)) 1 (float_round_up (Suc prec) (x * x))) ; |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
851 |
ub_horner = \<lambda> x. float_round_up prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
852 |
(x * |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
853 |
ub_arctan_horner prec (get_odd (prec div 4 + 1)) 1 (float_round_down (Suc prec) (x * x))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
854 |
in if x < 0 then - lb_arctan prec (-x) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
855 |
else if x \<le> Float 1 (- 1) then ub_horner x |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
856 |
else if x \<le> Float 1 1 then |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
857 |
let y = float_divr prec x |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
858 |
(float_plus_down |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
859 |
(Suc prec) 1 (lb_sqrt prec (float_plus_down prec 1 (float_round_down prec (x * x))))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
860 |
in if y > 1 then ub_pi prec * Float 1 (- 1) else Float 1 1 * ub_horner y |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
861 |
else float_plus_up prec (ub_pi prec * Float 1 (- 1)) ( - lb_horner (float_divl prec 1 x)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
862 |
by pat_completeness auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
863 |
termination |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
864 |
by (relation "measure (\<lambda> v. let (prec, x) = case_sum id id v in (if x < 0 then 1 else 0))", auto) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
865 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
866 |
declare ub_arctan_horner.simps[simp del] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
867 |
declare lb_arctan_horner.simps[simp del] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
868 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
869 |
lemma lb_arctan_bound': |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
870 |
assumes "0 \<le> real_of_float x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
871 |
shows "lb_arctan prec x \<le> arctan x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
872 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
873 |
have "\<not> x < 0" and "0 \<le> x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
874 |
using \<open>0 \<le> real_of_float x\<close> by (auto intro!: truncate_up_le ) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
875 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
876 |
let "?ub_horner x" = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
877 |
"x * ub_arctan_horner prec (get_odd (prec div 4 + 1)) 1 (float_round_down (Suc prec) (x * x))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
878 |
and "?lb_horner x" = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
879 |
"x * lb_arctan_horner prec (get_even (prec div 4 + 1)) 1 (float_round_up (Suc prec) (x * x))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
880 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
881 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
882 |
proof (cases "x \<le> Float 1 (- 1)") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
883 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
884 |
hence "real_of_float x \<le> 1" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
885 |
from arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float x\<close> \<open>real_of_float x \<le> 1\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
886 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
887 |
unfolding lb_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>] if_P[OF True] using \<open>0 \<le> x\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
888 |
by (auto intro!: float_round_down_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
889 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
890 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
891 |
hence "0 < real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
892 |
let ?R = "1 + sqrt (1 + real_of_float x * real_of_float x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
893 |
let ?sxx = "float_plus_up prec 1 (float_round_up prec (x * x))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
894 |
let ?fR = "float_plus_up prec 1 (ub_sqrt prec ?sxx)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
895 |
let ?DIV = "float_divl prec x ?fR" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
896 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
897 |
have divisor_gt0: "0 < ?R" by (auto intro: add_pos_nonneg) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
898 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
899 |
have "sqrt (1 + x*x) \<le> sqrt ?sxx" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
900 |
by (auto simp: float_plus_up.rep_eq plus_up_def float_round_up.rep_eq intro!: truncate_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
901 |
also have "\<dots> \<le> ub_sqrt prec ?sxx" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
902 |
using bnds_sqrt'[of ?sxx prec] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
903 |
finally |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
904 |
have "sqrt (1 + x*x) \<le> ub_sqrt prec ?sxx" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
905 |
hence "?R \<le> ?fR" by (auto simp: float_plus_up.rep_eq plus_up_def intro!: truncate_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
906 |
hence "0 < ?fR" and "0 < real_of_float ?fR" using \<open>0 < ?R\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
907 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
908 |
have monotone: "?DIV \<le> x / ?R" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
909 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
910 |
have "?DIV \<le> real_of_float x / ?fR" by (rule float_divl) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
911 |
also have "\<dots> \<le> x / ?R" by (rule divide_left_mono[OF \<open>?R \<le> ?fR\<close> \<open>0 \<le> real_of_float x\<close> mult_pos_pos[OF order_less_le_trans[OF divisor_gt0 \<open>?R \<le> real_of_float ?fR\<close>] divisor_gt0]]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
912 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
913 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
914 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
915 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
916 |
proof (cases "x \<le> Float 1 1") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
917 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
918 |
have "x \<le> sqrt (1 + x * x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
919 |
using real_sqrt_sum_squares_ge2[where x=1, unfolded numeral_2_eq_2] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
920 |
also note \<open>\<dots> \<le> (ub_sqrt prec ?sxx)\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
921 |
finally have "real_of_float x \<le> ?fR" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
922 |
by (auto simp: float_plus_up.rep_eq plus_up_def intro!: truncate_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
923 |
moreover have "?DIV \<le> real_of_float x / ?fR" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
924 |
by (rule float_divl) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
925 |
ultimately have "real_of_float ?DIV \<le> 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
926 |
unfolding divide_le_eq_1_pos[OF \<open>0 < real_of_float ?fR\<close>, symmetric] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
927 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
928 |
have "0 \<le> real_of_float ?DIV" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
929 |
using float_divl_lower_bound[OF \<open>0 \<le> x\<close>] \<open>0 < ?fR\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
930 |
unfolding less_eq_float_def by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
931 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
932 |
from arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float (?DIV)\<close> \<open>real_of_float (?DIV) \<le> 1\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
933 |
have "Float 1 1 * ?lb_horner ?DIV \<le> 2 * arctan ?DIV" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
934 |
by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
935 |
also have "\<dots> \<le> 2 * arctan (x / ?R)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
936 |
using arctan_monotone'[OF monotone] by (auto intro!: mult_left_mono arctan_monotone') |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
937 |
also have "2 * arctan (x / ?R) = arctan x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
938 |
using arctan_half[symmetric] unfolding numeral_2_eq_2 power_Suc2 power_0 mult_1_left . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
939 |
finally show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
940 |
unfolding lb_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
941 |
if_not_P[OF \<open>\<not> x \<le> Float 1 (- 1)\<close>] if_P[OF True] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
942 |
by (auto simp: float_round_down.rep_eq |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
943 |
intro!: order_trans[OF mult_left_mono[OF truncate_down]]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
944 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
945 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
946 |
hence "2 < real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
947 |
hence "1 \<le> real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
948 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
949 |
let "?invx" = "float_divr prec 1 x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
950 |
have "0 \<le> arctan x" using arctan_monotone'[OF \<open>0 \<le> real_of_float x\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
951 |
using arctan_tan[of 0, unfolded tan_zero] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
952 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
953 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
954 |
proof (cases "1 < ?invx") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
955 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
956 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
957 |
unfolding lb_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
958 |
if_not_P[OF \<open>\<not> x \<le> Float 1 (- 1)\<close>] if_not_P[OF False] if_P[OF True] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
959 |
using \<open>0 \<le> arctan x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
960 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
961 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
962 |
hence "real_of_float ?invx \<le> 1" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
963 |
have "0 \<le> real_of_float ?invx" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
964 |
by (rule order_trans[OF _ float_divr]) (auto simp add: \<open>0 \<le> real_of_float x\<close>) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
965 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
966 |
have "1 / x \<noteq> 0" and "0 < 1 / x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
967 |
using \<open>0 < real_of_float x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
968 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
969 |
have "arctan (1 / x) \<le> arctan ?invx" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
970 |
unfolding one_float.rep_eq[symmetric] by (rule arctan_monotone', rule float_divr) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
971 |
also have "\<dots> \<le> ?ub_horner ?invx" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
972 |
using arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float ?invx\<close> \<open>real_of_float ?invx \<le> 1\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
973 |
by (auto intro!: float_round_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
974 |
also note float_round_up |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
975 |
finally have "pi / 2 - float_round_up prec (?ub_horner ?invx) \<le> arctan x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
976 |
using \<open>0 \<le> arctan x\<close> arctan_inverse[OF \<open>1 / x \<noteq> 0\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
977 |
unfolding sgn_pos[OF \<open>0 < 1 / real_of_float x\<close>] le_diff_eq by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
978 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
979 |
have "lb_pi prec * Float 1 (- 1) \<le> pi / 2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
980 |
unfolding Float_num times_divide_eq_right mult_1_left using pi_boundaries by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
981 |
ultimately |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
982 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
983 |
unfolding lb_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
984 |
if_not_P[OF \<open>\<not> x \<le> Float 1 (- 1)\<close>] if_not_P[OF \<open>\<not> x \<le> Float 1 1\<close>] if_not_P[OF False] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
985 |
by (auto intro!: float_plus_down_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
986 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
987 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
988 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
989 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
990 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
991 |
lemma ub_arctan_bound': |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
992 |
assumes "0 \<le> real_of_float x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
993 |
shows "arctan x \<le> ub_arctan prec x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
994 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
995 |
have "\<not> x < 0" and "0 \<le> x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
996 |
using \<open>0 \<le> real_of_float x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
997 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
998 |
let "?ub_horner x" = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
999 |
"float_round_up prec (x * ub_arctan_horner prec (get_odd (prec div 4 + 1)) 1 (float_round_down (Suc prec) (x * x)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1000 |
let "?lb_horner x" = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1001 |
"float_round_down prec (x * lb_arctan_horner prec (get_even (prec div 4 + 1)) 1 (float_round_up (Suc prec) (x * x)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1002 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1003 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1004 |
proof (cases "x \<le> Float 1 (- 1)") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1005 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1006 |
hence "real_of_float x \<le> 1" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1007 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1008 |
unfolding ub_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>] if_P[OF True] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1009 |
using arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float x\<close> \<open>real_of_float x \<le> 1\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1010 |
by (auto intro!: float_round_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1011 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1012 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1013 |
hence "0 < real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1014 |
let ?R = "1 + sqrt (1 + real_of_float x * real_of_float x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1015 |
let ?sxx = "float_plus_down prec 1 (float_round_down prec (x * x))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1016 |
let ?fR = "float_plus_down (Suc prec) 1 (lb_sqrt prec ?sxx)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1017 |
let ?DIV = "float_divr prec x ?fR" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1018 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1019 |
have sqr_ge0: "0 \<le> 1 + real_of_float x * real_of_float x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1020 |
using sum_power2_ge_zero[of 1 "real_of_float x", unfolded numeral_2_eq_2] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1021 |
hence "0 \<le> real_of_float (1 + x*x)" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1022 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1023 |
hence divisor_gt0: "0 < ?R" by (auto intro: add_pos_nonneg) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1024 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1025 |
have "lb_sqrt prec ?sxx \<le> sqrt ?sxx" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1026 |
using bnds_sqrt'[of ?sxx] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1027 |
also have "\<dots> \<le> sqrt (1 + x*x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1028 |
by (auto simp: float_plus_down.rep_eq plus_down_def float_round_down.rep_eq truncate_down_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1029 |
finally have "lb_sqrt prec ?sxx \<le> sqrt (1 + x*x)" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1030 |
hence "?fR \<le> ?R" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1031 |
by (auto simp: float_plus_down.rep_eq plus_down_def truncate_down_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1032 |
have "0 < real_of_float ?fR" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1033 |
by (auto simp: float_plus_down.rep_eq plus_down_def float_round_down.rep_eq |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1034 |
intro!: truncate_down_ge1 lb_sqrt_lower_bound order_less_le_trans[OF zero_less_one] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1035 |
truncate_down_nonneg add_nonneg_nonneg) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1036 |
have monotone: "x / ?R \<le> (float_divr prec x ?fR)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1037 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1038 |
from divide_left_mono[OF \<open>?fR \<le> ?R\<close> \<open>0 \<le> real_of_float x\<close> mult_pos_pos[OF divisor_gt0 \<open>0 < real_of_float ?fR\<close>]] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1039 |
have "x / ?R \<le> x / ?fR" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1040 |
also have "\<dots> \<le> ?DIV" by (rule float_divr) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1041 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1042 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1043 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1044 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1045 |
proof (cases "x \<le> Float 1 1") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1046 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1047 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1048 |
proof (cases "?DIV > 1") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1049 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1050 |
have "pi / 2 \<le> ub_pi prec * Float 1 (- 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1051 |
unfolding Float_num times_divide_eq_right mult_1_left using pi_boundaries by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1052 |
from order_less_le_trans[OF arctan_ubound this, THEN less_imp_le] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1053 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1054 |
unfolding ub_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1055 |
if_not_P[OF \<open>\<not> x \<le> Float 1 (- 1)\<close>] if_P[OF \<open>x \<le> Float 1 1\<close>] if_P[OF True] . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1056 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1057 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1058 |
hence "real_of_float ?DIV \<le> 1" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1059 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1060 |
have "0 \<le> x / ?R" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1061 |
using \<open>0 \<le> real_of_float x\<close> \<open>0 < ?R\<close> unfolding zero_le_divide_iff by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1062 |
hence "0 \<le> real_of_float ?DIV" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1063 |
using monotone by (rule order_trans) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1064 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1065 |
have "arctan x = 2 * arctan (x / ?R)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1066 |
using arctan_half unfolding numeral_2_eq_2 power_Suc2 power_0 mult_1_left . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1067 |
also have "\<dots> \<le> 2 * arctan (?DIV)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1068 |
using arctan_monotone'[OF monotone] by (auto intro!: mult_left_mono) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1069 |
also have "\<dots> \<le> (Float 1 1 * ?ub_horner ?DIV)" unfolding Float_num |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1070 |
using arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float ?DIV\<close> \<open>real_of_float ?DIV \<le> 1\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1071 |
by (auto intro!: float_round_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1072 |
finally show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1073 |
unfolding ub_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1074 |
if_not_P[OF \<open>\<not> x \<le> Float 1 (- 1)\<close>] if_P[OF \<open>x \<le> Float 1 1\<close>] if_not_P[OF False] . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1075 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1076 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1077 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1078 |
hence "2 < real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1079 |
hence "1 \<le> real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1080 |
hence "0 < real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1081 |
hence "0 < x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1082 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1083 |
let "?invx" = "float_divl prec 1 x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1084 |
have "0 \<le> arctan x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1085 |
using arctan_monotone'[OF \<open>0 \<le> real_of_float x\<close>] and arctan_tan[of 0, unfolded tan_zero] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1086 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1087 |
have "real_of_float ?invx \<le> 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1088 |
unfolding less_float_def |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1089 |
by (rule order_trans[OF float_divl]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1090 |
(auto simp add: \<open>1 \<le> real_of_float x\<close> divide_le_eq_1_pos[OF \<open>0 < real_of_float x\<close>]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1091 |
have "0 \<le> real_of_float ?invx" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1092 |
using \<open>0 < x\<close> by (intro float_divl_lower_bound) auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1093 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1094 |
have "1 / x \<noteq> 0" and "0 < 1 / x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1095 |
using \<open>0 < real_of_float x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1096 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1097 |
have "(?lb_horner ?invx) \<le> arctan (?invx)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1098 |
using arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float ?invx\<close> \<open>real_of_float ?invx \<le> 1\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1099 |
by (auto intro!: float_round_down_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1100 |
also have "\<dots> \<le> arctan (1 / x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1101 |
unfolding one_float.rep_eq[symmetric] by (rule arctan_monotone') (rule float_divl) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1102 |
finally have "arctan x \<le> pi / 2 - (?lb_horner ?invx)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1103 |
using \<open>0 \<le> arctan x\<close> arctan_inverse[OF \<open>1 / x \<noteq> 0\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1104 |
unfolding sgn_pos[OF \<open>0 < 1 / x\<close>] le_diff_eq by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1105 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1106 |
have "pi / 2 \<le> ub_pi prec * Float 1 (- 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1107 |
unfolding Float_num times_divide_eq_right mult_1_right |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1108 |
using pi_boundaries by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1109 |
ultimately |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1110 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1111 |
unfolding ub_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1112 |
if_not_P[OF \<open>\<not> x \<le> Float 1 (- 1)\<close>] if_not_P[OF False] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1113 |
by (auto intro!: float_round_up_le float_plus_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1114 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1115 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1116 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1117 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1118 |
lemma arctan_boundaries: "arctan x \<in> {(lb_arctan prec x) .. (ub_arctan prec x)}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1119 |
proof (cases "0 \<le> x") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1120 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1121 |
hence "0 \<le> real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1122 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1123 |
using ub_arctan_bound'[OF \<open>0 \<le> real_of_float x\<close>] lb_arctan_bound'[OF \<open>0 \<le> real_of_float x\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1124 |
unfolding atLeastAtMost_iff by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1125 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1126 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1127 |
let ?mx = "-x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1128 |
from False have "x < 0" and "0 \<le> real_of_float ?mx" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1129 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1130 |
hence bounds: "lb_arctan prec ?mx \<le> arctan ?mx \<and> arctan ?mx \<le> ub_arctan prec ?mx" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1131 |
using ub_arctan_bound'[OF \<open>0 \<le> real_of_float ?mx\<close>] lb_arctan_bound'[OF \<open>0 \<le> real_of_float ?mx\<close>] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1132 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1133 |
unfolding minus_float.rep_eq arctan_minus lb_arctan.simps[where x=x] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1134 |
ub_arctan.simps[where x=x] Let_def if_P[OF \<open>x < 0\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1135 |
unfolding atLeastAtMost_iff using bounds[unfolded minus_float.rep_eq arctan_minus] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1136 |
by (simp add: arctan_minus) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1137 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1138 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1139 |
lemma bnds_arctan: "\<forall> (x::real) lx ux. (l, u) = (lb_arctan prec lx, ub_arctan prec ux) \<and> x \<in> {lx .. ux} \<longrightarrow> l \<le> arctan x \<and> arctan x \<le> u" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1140 |
proof (rule allI, rule allI, rule allI, rule impI) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1141 |
fix x :: real |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1142 |
fix lx ux |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1143 |
assume "(l, u) = (lb_arctan prec lx, ub_arctan prec ux) \<and> x \<in> {lx .. ux}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1144 |
hence l: "lb_arctan prec lx = l " |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1145 |
and u: "ub_arctan prec ux = u" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1146 |
and x: "x \<in> {lx .. ux}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1147 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1148 |
show "l \<le> arctan x \<and> arctan x \<le> u" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1149 |
proof |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1150 |
show "l \<le> arctan x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1151 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1152 |
from arctan_boundaries[of lx prec, unfolded l] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1153 |
have "l \<le> arctan lx" by (auto simp del: lb_arctan.simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1154 |
also have "\<dots> \<le> arctan x" using x by (auto intro: arctan_monotone') |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1155 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1156 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1157 |
show "arctan x \<le> u" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1158 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1159 |
have "arctan x \<le> arctan ux" using x by (auto intro: arctan_monotone') |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1160 |
also have "\<dots> \<le> u" using arctan_boundaries[of ux prec, unfolded u] by (auto simp del: ub_arctan.simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1161 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1162 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1163 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1164 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1165 |
|
71036 | 1166 |
lemmas [simp del] = lb_arctan.simps ub_arctan.simps |
1167 |
||
1168 |
lemma lb_arctan: "arctan (real_of_float x) \<le> y \<Longrightarrow> real_of_float (lb_arctan prec x) \<le> y" |
|
1169 |
and ub_arctan: "y \<le> arctan x \<Longrightarrow> y \<le> ub_arctan prec x" |
|
1170 |
for x::float and y::real |
|
1171 |
using arctan_boundaries[of x prec] by auto |
|
1172 |
||
1173 |
lift_definition arctan_float_interval :: "nat \<Rightarrow> float interval \<Rightarrow> float interval" |
|
1174 |
is "\<lambda>prec. \<lambda>(lx, ux). (lb_arctan prec lx, ub_arctan prec ux)" |
|
1175 |
by (auto intro!: lb_arctan ub_arctan arctan_monotone') |
|
1176 |
||
1177 |
lemma lower_arctan_float_interval: "lower (arctan_float_interval p x) = lb_arctan p (lower x)" |
|
1178 |
by transfer auto |
|
1179 |
lemma upper_arctan_float_interval: "upper (arctan_float_interval p x) = ub_arctan p (upper x)" |
|
1180 |
by transfer auto |
|
1181 |
||
1182 |
lemma arctan_float_interval: |
|
1183 |
"arctan ` set_of (real_interval x) \<subseteq> set_of (real_interval (arctan_float_interval p x))" |
|
1184 |
by (auto simp: set_of_eq lower_arctan_float_interval upper_arctan_float_interval |
|
1185 |
intro!: lb_arctan ub_arctan arctan_monotone') |
|
1186 |
||
1187 |
lemma arctan_float_intervalI: |
|
1188 |
"arctan x \<in>\<^sub>r arctan_float_interval p X" if "x \<in>\<^sub>r X" |
|
1189 |
using arctan_float_interval[of X p] that |
|
1190 |
by auto |
|
1191 |
||
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1192 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1193 |
section "Sinus and Cosinus" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1194 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1195 |
subsection "Compute the cosinus and sinus series" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1196 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1197 |
fun ub_sin_cos_aux :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1198 |
and lb_sin_cos_aux :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1199 |
"ub_sin_cos_aux prec 0 i k x = 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1200 |
| "ub_sin_cos_aux prec (Suc n) i k x = float_plus_up prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1201 |
(rapprox_rat prec 1 k) (- |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1202 |
float_round_down prec (x * (lb_sin_cos_aux prec n (i + 2) (k * i * (i + 1)) x)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1203 |
| "lb_sin_cos_aux prec 0 i k x = 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1204 |
| "lb_sin_cos_aux prec (Suc n) i k x = float_plus_down prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1205 |
(lapprox_rat prec 1 k) (- |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1206 |
float_round_up prec (x * (ub_sin_cos_aux prec n (i + 2) (k * i * (i + 1)) x)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1207 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1208 |
lemma cos_aux: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1209 |
shows "(lb_sin_cos_aux prec n 1 1 (x * x)) \<le> (\<Sum> i=0..<n. (- 1) ^ i * (1/(fact (2 * i))) * x ^(2 * i))" (is "?lb") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1210 |
and "(\<Sum> i=0..<n. (- 1) ^ i * (1/(fact (2 * i))) * x^(2 * i)) \<le> (ub_sin_cos_aux prec n 1 1 (x * x))" (is "?ub") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1211 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1212 |
have "0 \<le> real_of_float (x * x)" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1213 |
let "?f n" = "fact (2 * n) :: nat" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1214 |
have f_eq: "?f (Suc n) = ?f n * ((\<lambda>i. i + 2) ^^ n) 1 * (((\<lambda>i. i + 2) ^^ n) 1 + 1)" for n |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1215 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1216 |
have "\<And>m. ((\<lambda>i. i + 2) ^^ n) m = m + 2 * n" by (induct n) auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1217 |
then show ?thesis by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1218 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1219 |
from horner_bounds[where lb="lb_sin_cos_aux prec" and ub="ub_sin_cos_aux prec" and j'=0, |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1220 |
OF \<open>0 \<le> real_of_float (x * x)\<close> f_eq lb_sin_cos_aux.simps ub_sin_cos_aux.simps] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1221 |
show ?lb and ?ub |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1222 |
by (auto simp add: power_mult power2_eq_square[of "real_of_float x"]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1223 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1224 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1225 |
lemma lb_sin_cos_aux_zero_le_one: "lb_sin_cos_aux prec n i j 0 \<le> 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1226 |
by (cases j n rule: nat.exhaust[case_product nat.exhaust]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1227 |
(auto intro!: float_plus_down_le order_trans[OF lapprox_rat]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1228 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1229 |
lemma one_le_ub_sin_cos_aux: "odd n \<Longrightarrow> 1 \<le> ub_sin_cos_aux prec n i (Suc 0) 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1230 |
by (cases n) (auto intro!: float_plus_up_le order_trans[OF _ rapprox_rat]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1231 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1232 |
lemma cos_boundaries: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1233 |
assumes "0 \<le> real_of_float x" and "x \<le> pi / 2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1234 |
shows "cos x \<in> {(lb_sin_cos_aux prec (get_even n) 1 1 (x * x)) .. (ub_sin_cos_aux prec (get_odd n) 1 1 (x * x))}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1235 |
proof (cases "real_of_float x = 0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1236 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1237 |
hence "real_of_float x \<noteq> 0" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1238 |
hence "0 < x" and "0 < real_of_float x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1239 |
using \<open>0 \<le> real_of_float x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1240 |
have "0 < x * x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1241 |
using \<open>0 < x\<close> by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1242 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1243 |
have morph_to_if_power: "(\<Sum> i=0..<n. (-1::real) ^ i * (1/(fact (2 * i))) * x ^ (2 * i)) = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1244 |
(\<Sum> i = 0 ..< 2 * n. (if even(i) then ((- 1) ^ (i div 2))/((fact i)) else 0) * x ^ i)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1245 |
(is "?sum = ?ifsum") for x n |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1246 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1247 |
have "?sum = ?sum + (\<Sum> j = 0 ..< n. 0)" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1248 |
also have "\<dots> = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1249 |
(\<Sum> j = 0 ..< n. (- 1) ^ ((2 * j) div 2) / ((fact (2 * j))) * x ^(2 * j)) + (\<Sum> j = 0 ..< n. 0)" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1250 |
also have "\<dots> = (\<Sum> i = 0 ..< 2 * n. if even i then (- 1) ^ (i div 2) / ((fact i)) * x ^ i else 0)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1251 |
unfolding sum_split_even_odd atLeast0LessThan .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1252 |
also have "\<dots> = (\<Sum> i = 0 ..< 2 * n. (if even i then (- 1) ^ (i div 2) / ((fact i)) else 0) * x ^ i)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1253 |
by (rule sum.cong) auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1254 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1255 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1256 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1257 |
{ fix n :: nat assume "0 < n" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1258 |
hence "0 < 2 * n" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1259 |
obtain t where "0 < t" and "t < real_of_float x" and |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1260 |
cos_eq: "cos x = (\<Sum> i = 0 ..< 2 * n. (if even(i) then ((- 1) ^ (i div 2))/((fact i)) else 0) * (real_of_float x) ^ i) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1261 |
+ (cos (t + 1/2 * (2 * n) * pi) / (fact (2*n))) * (real_of_float x)^(2*n)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1262 |
(is "_ = ?SUM + ?rest / ?fact * ?pow") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1263 |
using Maclaurin_cos_expansion2[OF \<open>0 < real_of_float x\<close> \<open>0 < 2 * n\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1264 |
unfolding cos_coeff_def atLeast0LessThan by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1265 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1266 |
have "cos t * (- 1) ^ n = cos t * cos (n * pi) + sin t * sin (n * pi)" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1267 |
also have "\<dots> = cos (t + n * pi)" by (simp add: cos_add) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1268 |
also have "\<dots> = ?rest" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1269 |
finally have "cos t * (- 1) ^ n = ?rest" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1270 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1271 |
have "t \<le> pi / 2" using \<open>t < real_of_float x\<close> and \<open>x \<le> pi / 2\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1272 |
hence "0 \<le> cos t" using \<open>0 < t\<close> and cos_ge_zero by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1273 |
ultimately have even: "even n \<Longrightarrow> 0 \<le> ?rest" and odd: "odd n \<Longrightarrow> 0 \<le> - ?rest " by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1274 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1275 |
have "0 < ?fact" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1276 |
have "0 < ?pow" using \<open>0 < real_of_float x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1277 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1278 |
{ |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1279 |
assume "even n" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1280 |
have "(lb_sin_cos_aux prec n 1 1 (x * x)) \<le> ?SUM" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1281 |
unfolding morph_to_if_power[symmetric] using cos_aux by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1282 |
also have "\<dots> \<le> cos x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1283 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1284 |
from even[OF \<open>even n\<close>] \<open>0 < ?fact\<close> \<open>0 < ?pow\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1285 |
have "0 \<le> (?rest / ?fact) * ?pow" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1286 |
thus ?thesis unfolding cos_eq by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1287 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1288 |
finally have "(lb_sin_cos_aux prec n 1 1 (x * x)) \<le> cos x" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1289 |
} note lb = this |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1290 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1291 |
{ |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1292 |
assume "odd n" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1293 |
have "cos x \<le> ?SUM" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1294 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1295 |
from \<open>0 < ?fact\<close> and \<open>0 < ?pow\<close> and odd[OF \<open>odd n\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1296 |
have "0 \<le> (- ?rest) / ?fact * ?pow" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1297 |
by (metis mult_nonneg_nonneg divide_nonneg_pos less_imp_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1298 |
thus ?thesis unfolding cos_eq by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1299 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1300 |
also have "\<dots> \<le> (ub_sin_cos_aux prec n 1 1 (x * x))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1301 |
unfolding morph_to_if_power[symmetric] using cos_aux by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1302 |
finally have "cos x \<le> (ub_sin_cos_aux prec n 1 1 (x * x))" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1303 |
} note ub = this and lb |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1304 |
} note ub = this(1) and lb = this(2) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1305 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1306 |
have "cos x \<le> (ub_sin_cos_aux prec (get_odd n) 1 1 (x * x))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1307 |
using ub[OF odd_pos[OF get_odd] get_odd] . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1308 |
moreover have "(lb_sin_cos_aux prec (get_even n) 1 1 (x * x)) \<le> cos x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1309 |
proof (cases "0 < get_even n") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1310 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1311 |
show ?thesis using lb[OF True get_even] . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1312 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1313 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1314 |
hence "get_even n = 0" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1315 |
have "- (pi / 2) \<le> x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1316 |
by (rule order_trans[OF _ \<open>0 < real_of_float x\<close>[THEN less_imp_le]]) auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1317 |
with \<open>x \<le> pi / 2\<close> show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1318 |
unfolding \<open>get_even n = 0\<close> lb_sin_cos_aux.simps minus_float.rep_eq zero_float.rep_eq |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1319 |
using cos_ge_zero by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1320 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1321 |
ultimately show ?thesis by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1322 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1323 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1324 |
hence "x = 0" |
67573 | 1325 |
by (simp add: real_of_float_eq) |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1326 |
thus ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1327 |
using lb_sin_cos_aux_zero_le_one one_le_ub_sin_cos_aux |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1328 |
by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1329 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1330 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1331 |
lemma sin_aux: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1332 |
assumes "0 \<le> real_of_float x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1333 |
shows "(x * lb_sin_cos_aux prec n 2 1 (x * x)) \<le> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1334 |
(\<Sum> i=0..<n. (- 1) ^ i * (1/(fact (2 * i + 1))) * x^(2 * i + 1))" (is "?lb") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1335 |
and "(\<Sum> i=0..<n. (- 1) ^ i * (1/(fact (2 * i + 1))) * x^(2 * i + 1)) \<le> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1336 |
(x * ub_sin_cos_aux prec n 2 1 (x * x))" (is "?ub") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1337 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1338 |
have "0 \<le> real_of_float (x * x)" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1339 |
let "?f n" = "fact (2 * n + 1) :: nat" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1340 |
have f_eq: "?f (Suc n) = ?f n * ((\<lambda>i. i + 2) ^^ n) 2 * (((\<lambda>i. i + 2) ^^ n) 2 + 1)" for n |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1341 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1342 |
have F: "\<And>m. ((\<lambda>i. i + 2) ^^ n) m = m + 2 * n" by (induct n) auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1343 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1344 |
unfolding F by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1345 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1346 |
from horner_bounds[where lb="lb_sin_cos_aux prec" and ub="ub_sin_cos_aux prec" and j'=0, |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1347 |
OF \<open>0 \<le> real_of_float (x * x)\<close> f_eq lb_sin_cos_aux.simps ub_sin_cos_aux.simps] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1348 |
show "?lb" and "?ub" using \<open>0 \<le> real_of_float x\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1349 |
apply (simp_all only: power_add power_one_right mult.assoc[symmetric] sum_distrib_right[symmetric]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1350 |
apply (simp_all only: mult.commute[where 'a=real] of_nat_fact) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1351 |
apply (auto intro!: mult_left_mono simp add: power_mult power2_eq_square[of "real_of_float x"]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1352 |
done |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1353 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1354 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1355 |
lemma sin_boundaries: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1356 |
assumes "0 \<le> real_of_float x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1357 |
and "x \<le> pi / 2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1358 |
shows "sin x \<in> {(x * lb_sin_cos_aux prec (get_even n) 2 1 (x * x)) .. (x * ub_sin_cos_aux prec (get_odd n) 2 1 (x * x))}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1359 |
proof (cases "real_of_float x = 0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1360 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1361 |
hence "real_of_float x \<noteq> 0" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1362 |
hence "0 < x" and "0 < real_of_float x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1363 |
using \<open>0 \<le> real_of_float x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1364 |
have "0 < x * x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1365 |
using \<open>0 < x\<close> by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1366 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1367 |
have sum_morph: "(\<Sum>j = 0 ..< n. (- 1) ^ (((2 * j + 1) - Suc 0) div 2) / ((fact (2 * j + 1))) * x ^(2 * j + 1)) = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1368 |
(\<Sum> i = 0 ..< 2 * n. (if even(i) then 0 else ((- 1) ^ ((i - Suc 0) div 2))/((fact i))) * x ^ i)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1369 |
(is "?SUM = _") for x :: real and n |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1370 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1371 |
have pow: "!!i. x ^ (2 * i + 1) = x * x ^ (2 * i)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1372 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1373 |
have "?SUM = (\<Sum> j = 0 ..< n. 0) + ?SUM" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1374 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1375 |
also have "\<dots> = (\<Sum> i = 0 ..< 2 * n. if even i then 0 else (- 1) ^ ((i - Suc 0) div 2) / ((fact i)) * x ^ i)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1376 |
unfolding sum_split_even_odd atLeast0LessThan .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1377 |
also have "\<dots> = (\<Sum> i = 0 ..< 2 * n. (if even i then 0 else (- 1) ^ ((i - Suc 0) div 2) / ((fact i))) * x ^ i)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1378 |
by (rule sum.cong) auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1379 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1380 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1381 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1382 |
{ fix n :: nat assume "0 < n" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1383 |
hence "0 < 2 * n + 1" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1384 |
obtain t where "0 < t" and "t < real_of_float x" and |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1385 |
sin_eq: "sin x = (\<Sum> i = 0 ..< 2 * n + 1. (if even(i) then 0 else ((- 1) ^ ((i - Suc 0) div 2))/((fact i))) * (real_of_float x) ^ i) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1386 |
+ (sin (t + 1/2 * (2 * n + 1) * pi) / (fact (2*n + 1))) * (real_of_float x)^(2*n + 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1387 |
(is "_ = ?SUM + ?rest / ?fact * ?pow") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1388 |
using Maclaurin_sin_expansion3[OF \<open>0 < 2 * n + 1\<close> \<open>0 < real_of_float x\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1389 |
unfolding sin_coeff_def atLeast0LessThan by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1390 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1391 |
have "?rest = cos t * (- 1) ^ n" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1392 |
unfolding sin_add cos_add of_nat_add distrib_right distrib_left by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1393 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1394 |
have "t \<le> pi / 2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1395 |
using \<open>t < real_of_float x\<close> and \<open>x \<le> pi / 2\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1396 |
hence "0 \<le> cos t" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1397 |
using \<open>0 < t\<close> and cos_ge_zero by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1398 |
ultimately have even: "even n \<Longrightarrow> 0 \<le> ?rest" and odd: "odd n \<Longrightarrow> 0 \<le> - ?rest" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1399 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1400 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1401 |
have "0 < ?fact" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1402 |
by (simp del: fact_Suc) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1403 |
have "0 < ?pow" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1404 |
using \<open>0 < real_of_float x\<close> by (rule zero_less_power) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1405 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1406 |
{ |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1407 |
assume "even n" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1408 |
have "(x * lb_sin_cos_aux prec n 2 1 (x * x)) \<le> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1409 |
(\<Sum> i = 0 ..< 2 * n. (if even(i) then 0 else ((- 1) ^ ((i - Suc 0) div 2))/((fact i))) * (real_of_float x) ^ i)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1410 |
using sin_aux[OF \<open>0 \<le> real_of_float x\<close>] unfolding sum_morph[symmetric] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1411 |
also have "\<dots> \<le> ?SUM" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1412 |
also have "\<dots> \<le> sin x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1413 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1414 |
from even[OF \<open>even n\<close>] \<open>0 < ?fact\<close> \<open>0 < ?pow\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1415 |
have "0 \<le> (?rest / ?fact) * ?pow" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1416 |
thus ?thesis unfolding sin_eq by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1417 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1418 |
finally have "(x * lb_sin_cos_aux prec n 2 1 (x * x)) \<le> sin x" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1419 |
} note lb = this |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1420 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1421 |
{ |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1422 |
assume "odd n" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1423 |
have "sin x \<le> ?SUM" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1424 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1425 |
from \<open>0 < ?fact\<close> and \<open>0 < ?pow\<close> and odd[OF \<open>odd n\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1426 |
have "0 \<le> (- ?rest) / ?fact * ?pow" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1427 |
by (metis mult_nonneg_nonneg divide_nonneg_pos less_imp_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1428 |
thus ?thesis unfolding sin_eq by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1429 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1430 |
also have "\<dots> \<le> (\<Sum> i = 0 ..< 2 * n. (if even(i) then 0 else ((- 1) ^ ((i - Suc 0) div 2))/((fact i))) * (real_of_float x) ^ i)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1431 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1432 |
also have "\<dots> \<le> (x * ub_sin_cos_aux prec n 2 1 (x * x))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1433 |
using sin_aux[OF \<open>0 \<le> real_of_float x\<close>] unfolding sum_morph[symmetric] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1434 |
finally have "sin x \<le> (x * ub_sin_cos_aux prec n 2 1 (x * x))" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1435 |
} note ub = this and lb |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1436 |
} note ub = this(1) and lb = this(2) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1437 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1438 |
have "sin x \<le> (x * ub_sin_cos_aux prec (get_odd n) 2 1 (x * x))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1439 |
using ub[OF odd_pos[OF get_odd] get_odd] . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1440 |
moreover have "(x * lb_sin_cos_aux prec (get_even n) 2 1 (x * x)) \<le> sin x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1441 |
proof (cases "0 < get_even n") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1442 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1443 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1444 |
using lb[OF True get_even] . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1445 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1446 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1447 |
hence "get_even n = 0" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1448 |
with \<open>x \<le> pi / 2\<close> \<open>0 \<le> real_of_float x\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1449 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1450 |
unfolding \<open>get_even n = 0\<close> ub_sin_cos_aux.simps minus_float.rep_eq |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1451 |
using sin_ge_zero by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1452 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1453 |
ultimately show ?thesis by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1454 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1455 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1456 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1457 |
proof (cases "n = 0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1458 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1459 |
thus ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1460 |
unfolding \<open>n = 0\<close> get_even_def get_odd_def |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1461 |
using \<open>real_of_float x = 0\<close> lapprox_rat[where x="-1" and y=1] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1462 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1463 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1464 |
with not0_implies_Suc obtain m where "n = Suc m" by blast |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1465 |
thus ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1466 |
unfolding \<open>n = Suc m\<close> get_even_def get_odd_def |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1467 |
using \<open>real_of_float x = 0\<close> rapprox_rat[where x=1 and y=1] lapprox_rat[where x=1 and y=1] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1468 |
by (cases "even (Suc m)") auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1469 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1470 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1471 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1472 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1473 |
subsection "Compute the cosinus in the entire domain" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1474 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1475 |
definition lb_cos :: "nat \<Rightarrow> float \<Rightarrow> float" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1476 |
"lb_cos prec x = (let |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1477 |
horner = \<lambda> x. lb_sin_cos_aux prec (get_even (prec div 4 + 1)) 1 1 (x * x) ; |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1478 |
half = \<lambda> x. if x < 0 then - 1 else float_plus_down prec (Float 1 1 * x * x) (- 1) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1479 |
in if x < Float 1 (- 1) then horner x |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1480 |
else if x < 1 then half (horner (x * Float 1 (- 1))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1481 |
else half (half (horner (x * Float 1 (- 2)))))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1482 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1483 |
definition ub_cos :: "nat \<Rightarrow> float \<Rightarrow> float" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1484 |
"ub_cos prec x = (let |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1485 |
horner = \<lambda> x. ub_sin_cos_aux prec (get_odd (prec div 4 + 1)) 1 1 (x * x) ; |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1486 |
half = \<lambda> x. float_plus_up prec (Float 1 1 * x * x) (- 1) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1487 |
in if x < Float 1 (- 1) then horner x |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1488 |
else if x < 1 then half (horner (x * Float 1 (- 1))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1489 |
else half (half (horner (x * Float 1 (- 2)))))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1490 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1491 |
lemma lb_cos: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1492 |
assumes "0 \<le> real_of_float x" and "x \<le> pi" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1493 |
shows "cos x \<in> {(lb_cos prec x) .. (ub_cos prec x)}" (is "?cos x \<in> {(?lb x) .. (?ub x) }") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1494 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1495 |
have x_half[symmetric]: "cos x = 2 * cos (x / 2) * cos (x / 2) - 1" for x :: real |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1496 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1497 |
have "cos x = cos (x / 2 + x / 2)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1498 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1499 |
also have "\<dots> = cos (x / 2) * cos (x / 2) + sin (x / 2) * sin (x / 2) - sin (x / 2) * sin (x / 2) + cos (x / 2) * cos (x / 2) - 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1500 |
unfolding cos_add by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1501 |
also have "\<dots> = 2 * cos (x / 2) * cos (x / 2) - 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1502 |
by algebra |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1503 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1504 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1505 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1506 |
have "\<not> x < 0" using \<open>0 \<le> real_of_float x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1507 |
let "?ub_horner x" = "ub_sin_cos_aux prec (get_odd (prec div 4 + 1)) 1 1 (x * x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1508 |
let "?lb_horner x" = "lb_sin_cos_aux prec (get_even (prec div 4 + 1)) 1 1 (x * x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1509 |
let "?ub_half x" = "float_plus_up prec (Float 1 1 * x * x) (- 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1510 |
let "?lb_half x" = "if x < 0 then - 1 else float_plus_down prec (Float 1 1 * x * x) (- 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1511 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1512 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1513 |
proof (cases "x < Float 1 (- 1)") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1514 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1515 |
hence "x \<le> pi / 2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1516 |
using pi_ge_two by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1517 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1518 |
unfolding lb_cos_def[where x=x] ub_cos_def[where x=x] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1519 |
if_not_P[OF \<open>\<not> x < 0\<close>] if_P[OF \<open>x < Float 1 (- 1)\<close>] Let_def |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1520 |
using cos_boundaries[OF \<open>0 \<le> real_of_float x\<close> \<open>x \<le> pi / 2\<close>] . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1521 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1522 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1523 |
{ fix y x :: float let ?x2 = "(x * Float 1 (- 1))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1524 |
assume "y \<le> cos ?x2" and "-pi \<le> x" and "x \<le> pi" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1525 |
hence "- (pi / 2) \<le> ?x2" and "?x2 \<le> pi / 2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1526 |
using pi_ge_two unfolding Float_num by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1527 |
hence "0 \<le> cos ?x2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1528 |
by (rule cos_ge_zero) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1529 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1530 |
have "(?lb_half y) \<le> cos x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1531 |
proof (cases "y < 0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1532 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1533 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1534 |
using cos_ge_minus_one unfolding if_P[OF True] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1535 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1536 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1537 |
hence "0 \<le> real_of_float y" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1538 |
from mult_mono[OF \<open>y \<le> cos ?x2\<close> \<open>y \<le> cos ?x2\<close> \<open>0 \<le> cos ?x2\<close> this] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1539 |
have "real_of_float y * real_of_float y \<le> cos ?x2 * cos ?x2" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1540 |
hence "2 * real_of_float y * real_of_float y \<le> 2 * cos ?x2 * cos ?x2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1541 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1542 |
hence "2 * real_of_float y * real_of_float y - 1 \<le> 2 * cos (x / 2) * cos (x / 2) - 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1543 |
unfolding Float_num by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1544 |
thus ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1545 |
unfolding if_not_P[OF False] x_half Float_num |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1546 |
by (auto intro!: float_plus_down_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1547 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1548 |
} note lb_half = this |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1549 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1550 |
{ fix y x :: float let ?x2 = "(x * Float 1 (- 1))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1551 |
assume ub: "cos ?x2 \<le> y" and "- pi \<le> x" and "x \<le> pi" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1552 |
hence "- (pi / 2) \<le> ?x2" and "?x2 \<le> pi / 2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1553 |
using pi_ge_two unfolding Float_num by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1554 |
hence "0 \<le> cos ?x2" by (rule cos_ge_zero) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1555 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1556 |
have "cos x \<le> (?ub_half y)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1557 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1558 |
have "0 \<le> real_of_float y" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1559 |
using \<open>0 \<le> cos ?x2\<close> ub by (rule order_trans) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1560 |
from mult_mono[OF ub ub this \<open>0 \<le> cos ?x2\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1561 |
have "cos ?x2 * cos ?x2 \<le> real_of_float y * real_of_float y" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1562 |
hence "2 * cos ?x2 * cos ?x2 \<le> 2 * real_of_float y * real_of_float y" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1563 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1564 |
hence "2 * cos (x / 2) * cos (x / 2) - 1 \<le> 2 * real_of_float y * real_of_float y - 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1565 |
unfolding Float_num by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1566 |
thus ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1567 |
unfolding x_half Float_num |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1568 |
by (auto intro!: float_plus_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1569 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1570 |
} note ub_half = this |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1571 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1572 |
let ?x2 = "x * Float 1 (- 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1573 |
let ?x4 = "x * Float 1 (- 1) * Float 1 (- 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1574 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1575 |
have "-pi \<le> x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1576 |
using pi_ge_zero[THEN le_imp_neg_le, unfolded minus_zero] \<open>0 \<le> real_of_float x\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1577 |
by (rule order_trans) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1578 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1579 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1580 |
proof (cases "x < 1") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1581 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1582 |
hence "real_of_float x \<le> 1" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1583 |
have "0 \<le> real_of_float ?x2" and "?x2 \<le> pi / 2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1584 |
using pi_ge_two \<open>0 \<le> real_of_float x\<close> using assms by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1585 |
from cos_boundaries[OF this] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1586 |
have lb: "(?lb_horner ?x2) \<le> ?cos ?x2" and ub: "?cos ?x2 \<le> (?ub_horner ?x2)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1587 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1588 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1589 |
have "(?lb x) \<le> ?cos x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1590 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1591 |
from lb_half[OF lb \<open>-pi \<le> x\<close> \<open>x \<le> pi\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1592 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1593 |
unfolding lb_cos_def[where x=x] Let_def |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1594 |
using \<open>\<not> x < 0\<close> \<open>\<not> x < Float 1 (- 1)\<close> \<open>x < 1\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1595 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1596 |
moreover have "?cos x \<le> (?ub x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1597 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1598 |
from ub_half[OF ub \<open>-pi \<le> x\<close> \<open>x \<le> pi\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1599 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1600 |
unfolding ub_cos_def[where x=x] Let_def |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1601 |
using \<open>\<not> x < 0\<close> \<open>\<not> x < Float 1 (- 1)\<close> \<open>x < 1\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1602 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1603 |
ultimately show ?thesis by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1604 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1605 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1606 |
have "0 \<le> real_of_float ?x4" and "?x4 \<le> pi / 2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1607 |
using pi_ge_two \<open>0 \<le> real_of_float x\<close> \<open>x \<le> pi\<close> unfolding Float_num by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1608 |
from cos_boundaries[OF this] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1609 |
have lb: "(?lb_horner ?x4) \<le> ?cos ?x4" and ub: "?cos ?x4 \<le> (?ub_horner ?x4)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1610 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1611 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1612 |
have eq_4: "?x2 * Float 1 (- 1) = x * Float 1 (- 2)" |
67573 | 1613 |
by (auto simp: real_of_float_eq) |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1614 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1615 |
have "(?lb x) \<le> ?cos x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1616 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1617 |
have "-pi \<le> ?x2" and "?x2 \<le> pi" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1618 |
using pi_ge_two \<open>0 \<le> real_of_float x\<close> \<open>x \<le> pi\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1619 |
from lb_half[OF lb_half[OF lb this] \<open>-pi \<le> x\<close> \<open>x \<le> pi\<close>, unfolded eq_4] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1620 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1621 |
unfolding lb_cos_def[where x=x] if_not_P[OF \<open>\<not> x < 0\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1622 |
if_not_P[OF \<open>\<not> x < Float 1 (- 1)\<close>] if_not_P[OF \<open>\<not> x < 1\<close>] Let_def . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1623 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1624 |
moreover have "?cos x \<le> (?ub x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1625 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1626 |
have "-pi \<le> ?x2" and "?x2 \<le> pi" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1627 |
using pi_ge_two \<open>0 \<le> real_of_float x\<close> \<open> x \<le> pi\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1628 |
from ub_half[OF ub_half[OF ub this] \<open>-pi \<le> x\<close> \<open>x \<le> pi\<close>, unfolded eq_4] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1629 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1630 |
unfolding ub_cos_def[where x=x] if_not_P[OF \<open>\<not> x < 0\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1631 |
if_not_P[OF \<open>\<not> x < Float 1 (- 1)\<close>] if_not_P[OF \<open>\<not> x < 1\<close>] Let_def . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1632 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1633 |
ultimately show ?thesis by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1634 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1635 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1636 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1637 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1638 |
lemma lb_cos_minus: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1639 |
assumes "-pi \<le> x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1640 |
and "real_of_float x \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1641 |
shows "cos (real_of_float(-x)) \<in> {(lb_cos prec (-x)) .. (ub_cos prec (-x))}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1642 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1643 |
have "0 \<le> real_of_float (-x)" and "(-x) \<le> pi" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1644 |
using \<open>-pi \<le> x\<close> \<open>real_of_float x \<le> 0\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1645 |
from lb_cos[OF this] show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1646 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1647 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1648 |
definition bnds_cos :: "nat \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float * float" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1649 |
"bnds_cos prec lx ux = (let |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1650 |
lpi = float_round_down prec (lb_pi prec) ; |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1651 |
upi = float_round_up prec (ub_pi prec) ; |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1652 |
k = floor_fl (float_divr prec (lx + lpi) (2 * lpi)) ; |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1653 |
lx = float_plus_down prec lx (- k * 2 * (if k < 0 then lpi else upi)) ; |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1654 |
ux = float_plus_up prec ux (- k * 2 * (if k < 0 then upi else lpi)) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1655 |
in if - lpi \<le> lx \<and> ux \<le> 0 then (lb_cos prec (-lx), ub_cos prec (-ux)) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1656 |
else if 0 \<le> lx \<and> ux \<le> lpi then (lb_cos prec ux, ub_cos prec lx) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1657 |
else if - lpi \<le> lx \<and> ux \<le> lpi then (min (lb_cos prec (-lx)) (lb_cos prec ux), Float 1 0) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1658 |
else if 0 \<le> lx \<and> ux \<le> 2 * lpi then (Float (- 1) 0, max (ub_cos prec lx) (ub_cos prec (- (ux - 2 * lpi)))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1659 |
else if -2 * lpi \<le> lx \<and> ux \<le> 0 then (Float (- 1) 0, max (ub_cos prec (lx + 2 * lpi)) (ub_cos prec (-ux))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1660 |
else (Float (- 1) 0, Float 1 0))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1661 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1662 |
lemma floor_int: obtains k :: int where "real_of_int k = (floor_fl f)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1663 |
by (simp add: floor_fl_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1664 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1665 |
lemma cos_periodic_nat[simp]: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1666 |
fixes n :: nat |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1667 |
shows "cos (x + n * (2 * pi)) = cos x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1668 |
proof (induct n arbitrary: x) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1669 |
case 0 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1670 |
then show ?case by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1671 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1672 |
case (Suc n) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1673 |
have split_pi_off: "x + (Suc n) * (2 * pi) = (x + n * (2 * pi)) + 2 * pi" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1674 |
unfolding Suc_eq_plus1 of_nat_add of_int_1 distrib_right by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1675 |
show ?case |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1676 |
unfolding split_pi_off using Suc by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1677 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1678 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1679 |
lemma cos_periodic_int[simp]: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1680 |
fixes i :: int |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1681 |
shows "cos (x + i * (2 * pi)) = cos x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1682 |
proof (cases "0 \<le> i") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1683 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1684 |
hence i_nat: "real_of_int i = nat i" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1685 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1686 |
unfolding i_nat by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1687 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1688 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1689 |
hence i_nat: "i = - real (nat (-i))" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1690 |
have "cos x = cos (x + i * (2 * pi) - i * (2 * pi))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1691 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1692 |
also have "\<dots> = cos (x + i * (2 * pi))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1693 |
unfolding i_nat mult_minus_left diff_minus_eq_add by (rule cos_periodic_nat) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1694 |
finally show ?thesis by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1695 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1696 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1697 |
lemma bnds_cos: "\<forall>(x::real) lx ux. (l, u) = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1698 |
bnds_cos prec lx ux \<and> x \<in> {lx .. ux} \<longrightarrow> l \<le> cos x \<and> cos x \<le> u" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1699 |
proof (rule allI | rule impI | erule conjE)+ |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1700 |
fix x :: real |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1701 |
fix lx ux |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1702 |
assume bnds: "(l, u) = bnds_cos prec lx ux" and x: "x \<in> {lx .. ux}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1703 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1704 |
let ?lpi = "float_round_down prec (lb_pi prec)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1705 |
let ?upi = "float_round_up prec (ub_pi prec)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1706 |
let ?k = "floor_fl (float_divr prec (lx + ?lpi) (2 * ?lpi))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1707 |
let ?lx2 = "(- ?k * 2 * (if ?k < 0 then ?lpi else ?upi))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1708 |
let ?ux2 = "(- ?k * 2 * (if ?k < 0 then ?upi else ?lpi))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1709 |
let ?lx = "float_plus_down prec lx ?lx2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1710 |
let ?ux = "float_plus_up prec ux ?ux2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1711 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1712 |
obtain k :: int where k: "k = real_of_float ?k" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1713 |
by (rule floor_int) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1714 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1715 |
have upi: "pi \<le> ?upi" and lpi: "?lpi \<le> pi" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1716 |
using float_round_up[of "ub_pi prec" prec] pi_boundaries[of prec] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1717 |
float_round_down[of prec "lb_pi prec"] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1718 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1719 |
hence "lx + ?lx2 \<le> x - k * (2 * pi) \<and> x - k * (2 * pi) \<le> ux + ?ux2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1720 |
using x |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1721 |
by (cases "k = 0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1722 |
(auto intro!: add_mono |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1723 |
simp add: k [symmetric] uminus_add_conv_diff [symmetric] |
70347 | 1724 |
simp del: uminus_add_conv_diff) |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1725 |
hence "?lx \<le> x - k * (2 * pi) \<and> x - k * (2 * pi) \<le> ?ux" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1726 |
by (auto intro!: float_plus_down_le float_plus_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1727 |
note lx = this[THEN conjunct1] and ux = this[THEN conjunct2] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1728 |
hence lx_less_ux: "?lx \<le> real_of_float ?ux" by (rule order_trans) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1729 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1730 |
{ assume "- ?lpi \<le> ?lx" and x_le_0: "x - k * (2 * pi) \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1731 |
with lpi[THEN le_imp_neg_le] lx |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1732 |
have pi_lx: "- pi \<le> ?lx" and lx_0: "real_of_float ?lx \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1733 |
by simp_all |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1734 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1735 |
have "(lb_cos prec (- ?lx)) \<le> cos (real_of_float (- ?lx))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1736 |
using lb_cos_minus[OF pi_lx lx_0] by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1737 |
also have "\<dots> \<le> cos (x + (-k) * (2 * pi))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1738 |
using cos_monotone_minus_pi_0'[OF pi_lx lx x_le_0] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1739 |
by (simp only: uminus_float.rep_eq of_int_minus |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1740 |
cos_minus mult_minus_left) simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1741 |
finally have "(lb_cos prec (- ?lx)) \<le> cos x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1742 |
unfolding cos_periodic_int . } |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1743 |
note negative_lx = this |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1744 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1745 |
{ assume "0 \<le> ?lx" and pi_x: "x - k * (2 * pi) \<le> pi" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1746 |
with lx |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1747 |
have pi_lx: "?lx \<le> pi" and lx_0: "0 \<le> real_of_float ?lx" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1748 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1749 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1750 |
have "cos (x + (-k) * (2 * pi)) \<le> cos ?lx" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1751 |
using cos_monotone_0_pi_le[OF lx_0 lx pi_x] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1752 |
by (simp only: of_int_minus |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1753 |
cos_minus mult_minus_left) simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1754 |
also have "\<dots> \<le> (ub_cos prec ?lx)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1755 |
using lb_cos[OF lx_0 pi_lx] by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1756 |
finally have "cos x \<le> (ub_cos prec ?lx)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1757 |
unfolding cos_periodic_int . } |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1758 |
note positive_lx = this |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1759 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1760 |
{ assume pi_x: "- pi \<le> x - k * (2 * pi)" and "?ux \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1761 |
with ux |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1762 |
have pi_ux: "- pi \<le> ?ux" and ux_0: "real_of_float ?ux \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1763 |
by simp_all |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1764 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1765 |
have "cos (x + (-k) * (2 * pi)) \<le> cos (real_of_float (- ?ux))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1766 |
using cos_monotone_minus_pi_0'[OF pi_x ux ux_0] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1767 |
by (simp only: uminus_float.rep_eq of_int_minus |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1768 |
cos_minus mult_minus_left) simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1769 |
also have "\<dots> \<le> (ub_cos prec (- ?ux))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1770 |
using lb_cos_minus[OF pi_ux ux_0, of prec] by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1771 |
finally have "cos x \<le> (ub_cos prec (- ?ux))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1772 |
unfolding cos_periodic_int . } |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1773 |
note negative_ux = this |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1774 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1775 |
{ assume "?ux \<le> ?lpi" and x_ge_0: "0 \<le> x - k * (2 * pi)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1776 |
with lpi ux |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1777 |
have pi_ux: "?ux \<le> pi" and ux_0: "0 \<le> real_of_float ?ux" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1778 |
by simp_all |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1779 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1780 |
have "(lb_cos prec ?ux) \<le> cos ?ux" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1781 |
using lb_cos[OF ux_0 pi_ux] by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1782 |
also have "\<dots> \<le> cos (x + (-k) * (2 * pi))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1783 |
using cos_monotone_0_pi_le[OF x_ge_0 ux pi_ux] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1784 |
by (simp only: of_int_minus |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1785 |
cos_minus mult_minus_left) simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1786 |
finally have "(lb_cos prec ?ux) \<le> cos x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1787 |
unfolding cos_periodic_int . } |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1788 |
note positive_ux = this |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1789 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1790 |
show "l \<le> cos x \<and> cos x \<le> u" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1791 |
proof (cases "- ?lpi \<le> ?lx \<and> ?ux \<le> 0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1792 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1793 |
with bnds have l: "l = lb_cos prec (-?lx)" and u: "u = ub_cos prec (-?ux)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1794 |
by (auto simp add: bnds_cos_def Let_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1795 |
from True lpi[THEN le_imp_neg_le] lx ux |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1796 |
have "- pi \<le> x - k * (2 * pi)" and "x - k * (2 * pi) \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1797 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1798 |
with True negative_ux negative_lx show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1799 |
unfolding l u by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1800 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1801 |
case 1: False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1802 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1803 |
proof (cases "0 \<le> ?lx \<and> ?ux \<le> ?lpi") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1804 |
case True with bnds 1 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1805 |
have l: "l = lb_cos prec ?ux" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1806 |
and u: "u = ub_cos prec ?lx" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1807 |
by (auto simp add: bnds_cos_def Let_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1808 |
from True lpi lx ux |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1809 |
have "0 \<le> x - k * (2 * pi)" and "x - k * (2 * pi) \<le> pi" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1810 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1811 |
with True positive_ux positive_lx show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1812 |
unfolding l u by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1813 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1814 |
case 2: False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1815 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1816 |
proof (cases "- ?lpi \<le> ?lx \<and> ?ux \<le> ?lpi") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1817 |
case Cond: True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1818 |
with bnds 1 2 have l: "l = min (lb_cos prec (-?lx)) (lb_cos prec ?ux)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1819 |
and u: "u = Float 1 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1820 |
by (auto simp add: bnds_cos_def Let_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1821 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1822 |
unfolding u l using negative_lx positive_ux Cond |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1823 |
by (cases "x - k * (2 * pi) < 0") (auto simp add: real_of_float_min) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1824 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1825 |
case 3: False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1826 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1827 |
proof (cases "0 \<le> ?lx \<and> ?ux \<le> 2 * ?lpi") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1828 |
case Cond: True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1829 |
with bnds 1 2 3 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1830 |
have l: "l = Float (- 1) 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1831 |
and u: "u = max (ub_cos prec ?lx) (ub_cos prec (- (?ux - 2 * ?lpi)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1832 |
by (auto simp add: bnds_cos_def Let_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1833 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1834 |
have "cos x \<le> real_of_float u" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1835 |
proof (cases "x - k * (2 * pi) < pi") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1836 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1837 |
hence "x - k * (2 * pi) \<le> pi" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1838 |
from positive_lx[OF Cond[THEN conjunct1] this] show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1839 |
unfolding u by (simp add: real_of_float_max) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1840 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1841 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1842 |
hence "pi \<le> x - k * (2 * pi)" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1843 |
hence pi_x: "- pi \<le> x - k * (2 * pi) - 2 * pi" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1844 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1845 |
have "?ux \<le> 2 * pi" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1846 |
using Cond lpi by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1847 |
hence "x - k * (2 * pi) - 2 * pi \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1848 |
using ux by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1849 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1850 |
have ux_0: "real_of_float (?ux - 2 * ?lpi) \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1851 |
using Cond by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1852 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1853 |
from 2 and Cond have "\<not> ?ux \<le> ?lpi" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1854 |
hence "- ?lpi \<le> ?ux - 2 * ?lpi" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1855 |
hence pi_ux: "- pi \<le> (?ux - 2 * ?lpi)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1856 |
using lpi[THEN le_imp_neg_le] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1857 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1858 |
have x_le_ux: "x - k * (2 * pi) - 2 * pi \<le> (?ux - 2 * ?lpi)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1859 |
using ux lpi by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1860 |
have "cos x = cos (x + (-k) * (2 * pi) + (-1::int) * (2 * pi))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1861 |
unfolding cos_periodic_int .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1862 |
also have "\<dots> \<le> cos ((?ux - 2 * ?lpi))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1863 |
using cos_monotone_minus_pi_0'[OF pi_x x_le_ux ux_0] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1864 |
by (simp only: minus_float.rep_eq of_int_minus of_int_1 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1865 |
mult_minus_left mult_1_left) simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1866 |
also have "\<dots> = cos ((- (?ux - 2 * ?lpi)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1867 |
unfolding uminus_float.rep_eq cos_minus .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1868 |
also have "\<dots> \<le> (ub_cos prec (- (?ux - 2 * ?lpi)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1869 |
using lb_cos_minus[OF pi_ux ux_0] by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1870 |
finally show ?thesis unfolding u by (simp add: real_of_float_max) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1871 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1872 |
thus ?thesis unfolding l by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1873 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1874 |
case 4: False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1875 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1876 |
proof (cases "-2 * ?lpi \<le> ?lx \<and> ?ux \<le> 0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1877 |
case Cond: True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1878 |
with bnds 1 2 3 4 have l: "l = Float (- 1) 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1879 |
and u: "u = max (ub_cos prec (?lx + 2 * ?lpi)) (ub_cos prec (-?ux))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1880 |
by (auto simp add: bnds_cos_def Let_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1881 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1882 |
have "cos x \<le> u" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1883 |
proof (cases "-pi < x - k * (2 * pi)") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1884 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1885 |
hence "-pi \<le> x - k * (2 * pi)" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1886 |
from negative_ux[OF this Cond[THEN conjunct2]] show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1887 |
unfolding u by (simp add: real_of_float_max) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1888 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1889 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1890 |
hence "x - k * (2 * pi) \<le> -pi" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1891 |
hence pi_x: "x - k * (2 * pi) + 2 * pi \<le> pi" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1892 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1893 |
have "-2 * pi \<le> ?lx" using Cond lpi by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1894 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1895 |
hence "0 \<le> x - k * (2 * pi) + 2 * pi" using lx by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1896 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1897 |
have lx_0: "0 \<le> real_of_float (?lx + 2 * ?lpi)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1898 |
using Cond lpi by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1899 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1900 |
from 1 and Cond have "\<not> -?lpi \<le> ?lx" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1901 |
hence "?lx + 2 * ?lpi \<le> ?lpi" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1902 |
hence pi_lx: "(?lx + 2 * ?lpi) \<le> pi" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1903 |
using lpi[THEN le_imp_neg_le] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1904 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1905 |
have lx_le_x: "(?lx + 2 * ?lpi) \<le> x - k * (2 * pi) + 2 * pi" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1906 |
using lx lpi by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1907 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1908 |
have "cos x = cos (x + (-k) * (2 * pi) + (1 :: int) * (2 * pi))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1909 |
unfolding cos_periodic_int .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1910 |
also have "\<dots> \<le> cos ((?lx + 2 * ?lpi))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1911 |
using cos_monotone_0_pi_le[OF lx_0 lx_le_x pi_x] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1912 |
by (simp only: minus_float.rep_eq of_int_minus of_int_1 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1913 |
mult_minus_left mult_1_left) simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1914 |
also have "\<dots> \<le> (ub_cos prec (?lx + 2 * ?lpi))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1915 |
using lb_cos[OF lx_0 pi_lx] by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1916 |
finally show ?thesis unfolding u by (simp add: real_of_float_max) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1917 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1918 |
thus ?thesis unfolding l by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1919 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1920 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1921 |
with bnds 1 2 3 4 show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1922 |
by (auto simp add: bnds_cos_def Let_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1923 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1924 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1925 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1926 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1927 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1928 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1929 |
|
71036 | 1930 |
lemma bnds_cos_lower: "\<And>x. real_of_float xl \<le> x \<Longrightarrow> x \<le> real_of_float xu \<Longrightarrow> cos x \<le> y \<Longrightarrow> real_of_float (fst (bnds_cos prec xl xu)) \<le> y" |
1931 |
and bnds_cos_upper: "\<And>x. real_of_float xl \<le> x \<Longrightarrow> x \<le> real_of_float xu \<Longrightarrow> y \<le> cos x \<Longrightarrow> y \<le> real_of_float (snd (bnds_cos prec xl xu))" |
|
1932 |
for xl xu::float and y::real |
|
1933 |
using bnds_cos[of "fst (bnds_cos prec xl xu)" "snd (bnds_cos prec xl xu)" prec] |
|
1934 |
by force+ |
|
1935 |
||
1936 |
lift_definition cos_float_interval :: "nat \<Rightarrow> float interval \<Rightarrow> float interval" |
|
1937 |
is "\<lambda>prec. \<lambda>(lx, ux). bnds_cos prec lx ux" |
|
1938 |
using bnds_cos |
|
1939 |
by auto (metis (full_types) order_refl order_trans) |
|
1940 |
||
1941 |
lemma lower_cos_float_interval: "lower (cos_float_interval p x) = fst (bnds_cos p (lower x) (upper x))" |
|
1942 |
by transfer auto |
|
1943 |
lemma upper_cos_float_interval: "upper (cos_float_interval p x) = snd (bnds_cos p (lower x) (upper x))" |
|
1944 |
by transfer auto |
|
1945 |
||
1946 |
lemma cos_float_interval: |
|
1947 |
"cos ` set_of (real_interval x) \<subseteq> set_of (real_interval (cos_float_interval p x))" |
|
1948 |
by (auto simp: set_of_eq bnds_cos_lower bnds_cos_upper lower_cos_float_interval |
|
1949 |
upper_cos_float_interval) |
|
1950 |
||
1951 |
lemma cos_float_intervalI: "cos x \<in>\<^sub>r cos_float_interval p X" if "x \<in>\<^sub>r X" |
|
1952 |
using cos_float_interval[of X p] that |
|
1953 |
by auto |
|
1954 |
||
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1955 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1956 |
section "Exponential function" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1957 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1958 |
subsection "Compute the series of the exponential function" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1959 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1960 |
fun ub_exp_horner :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1961 |
and lb_exp_horner :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1962 |
where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1963 |
"ub_exp_horner prec 0 i k x = 0" | |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1964 |
"ub_exp_horner prec (Suc n) i k x = float_plus_up prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1965 |
(rapprox_rat prec 1 (int k)) (float_round_up prec (x * lb_exp_horner prec n (i + 1) (k * i) x))" | |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1966 |
"lb_exp_horner prec 0 i k x = 0" | |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1967 |
"lb_exp_horner prec (Suc n) i k x = float_plus_down prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1968 |
(lapprox_rat prec 1 (int k)) (float_round_down prec (x * ub_exp_horner prec n (i + 1) (k * i) x))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1969 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1970 |
lemma bnds_exp_horner: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1971 |
assumes "real_of_float x \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1972 |
shows "exp x \<in> {lb_exp_horner prec (get_even n) 1 1 x .. ub_exp_horner prec (get_odd n) 1 1 x}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1973 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1974 |
have f_eq: "fact (Suc n) = fact n * ((\<lambda>i::nat. i + 1) ^^ n) 1" for n |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1975 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1976 |
have F: "\<And> m. ((\<lambda>i. i + 1) ^^ n) m = n + m" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1977 |
by (induct n) auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1978 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1979 |
unfolding F by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1980 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1981 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1982 |
note bounds = horner_bounds_nonpos[where f="fact" and lb="lb_exp_horner prec" and ub="ub_exp_horner prec" and j'=0 and s=1, |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1983 |
OF assms f_eq lb_exp_horner.simps ub_exp_horner.simps] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1984 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1985 |
have "lb_exp_horner prec (get_even n) 1 1 x \<le> exp x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1986 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1987 |
have "lb_exp_horner prec (get_even n) 1 1 x \<le> (\<Sum>j = 0..<get_even n. 1 / (fact j) * real_of_float x ^ j)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1988 |
using bounds(1) by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1989 |
also have "\<dots> \<le> exp x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1990 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1991 |
obtain t where "\<bar>t\<bar> \<le> \<bar>real_of_float x\<bar>" and "exp x = (\<Sum>m = 0..<get_even n. real_of_float x ^ m / (fact m)) + exp t / (fact (get_even n)) * (real_of_float x) ^ (get_even n)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1992 |
using Maclaurin_exp_le unfolding atLeast0LessThan by blast |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1993 |
moreover have "0 \<le> exp t / (fact (get_even n)) * (real_of_float x) ^ (get_even n)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1994 |
by (auto simp: zero_le_even_power) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1995 |
ultimately show ?thesis using get_odd exp_gt_zero by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1996 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1997 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1998 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
1999 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2000 |
have "exp x \<le> ub_exp_horner prec (get_odd n) 1 1 x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2001 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2002 |
have x_less_zero: "real_of_float x ^ get_odd n \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2003 |
proof (cases "real_of_float x = 0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2004 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2005 |
have "(get_odd n) \<noteq> 0" using get_odd[THEN odd_pos] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2006 |
thus ?thesis unfolding True power_0_left by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2007 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2008 |
case False hence "real_of_float x < 0" using \<open>real_of_float x \<le> 0\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2009 |
show ?thesis by (rule less_imp_le, auto simp add: \<open>real_of_float x < 0\<close>) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2010 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2011 |
obtain t where "\<bar>t\<bar> \<le> \<bar>real_of_float x\<bar>" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2012 |
and "exp x = (\<Sum>m = 0..<get_odd n. (real_of_float x) ^ m / (fact m)) + exp t / (fact (get_odd n)) * (real_of_float x) ^ (get_odd n)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2013 |
using Maclaurin_exp_le unfolding atLeast0LessThan by blast |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2014 |
moreover have "exp t / (fact (get_odd n)) * (real_of_float x) ^ (get_odd n) \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2015 |
by (auto intro!: mult_nonneg_nonpos divide_nonpos_pos simp add: x_less_zero) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2016 |
ultimately have "exp x \<le> (\<Sum>j = 0..<get_odd n. 1 / (fact j) * real_of_float x ^ j)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2017 |
using get_odd exp_gt_zero by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2018 |
also have "\<dots> \<le> ub_exp_horner prec (get_odd n) 1 1 x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2019 |
using bounds(2) by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2020 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2021 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2022 |
ultimately show ?thesis by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2023 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2024 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2025 |
lemma ub_exp_horner_nonneg: "real_of_float x \<le> 0 \<Longrightarrow> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2026 |
0 \<le> real_of_float (ub_exp_horner prec (get_odd n) (Suc 0) (Suc 0) x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2027 |
using bnds_exp_horner[of x prec n] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2028 |
by (intro order_trans[OF exp_ge_zero]) auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2029 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2030 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2031 |
subsection "Compute the exponential function on the entire domain" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2032 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2033 |
function ub_exp :: "nat \<Rightarrow> float \<Rightarrow> float" and lb_exp :: "nat \<Rightarrow> float \<Rightarrow> float" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2034 |
"lb_exp prec x = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2035 |
(if 0 < x then float_divl prec 1 (ub_exp prec (-x)) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2036 |
else |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2037 |
let |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2038 |
horner = (\<lambda> x. let y = lb_exp_horner prec (get_even (prec + 2)) 1 1 x in |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2039 |
if y \<le> 0 then Float 1 (- 2) else y) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2040 |
in |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2041 |
if x < - 1 then |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2042 |
power_down_fl prec (horner (float_divl prec x (- floor_fl x))) (nat (- int_floor_fl x)) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2043 |
else horner x)" | |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2044 |
"ub_exp prec x = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2045 |
(if 0 < x then float_divr prec 1 (lb_exp prec (-x)) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2046 |
else if x < - 1 then |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2047 |
power_up_fl prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2048 |
(ub_exp_horner prec (get_odd (prec + 2)) 1 1 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2049 |
(float_divr prec x (- floor_fl x))) (nat (- int_floor_fl x)) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2050 |
else ub_exp_horner prec (get_odd (prec + 2)) 1 1 x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2051 |
by pat_completeness auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2052 |
termination |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2053 |
by (relation "measure (\<lambda> v. let (prec, x) = case_sum id id v in (if 0 < x then 1 else 0))") auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2054 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2055 |
lemma exp_m1_ge_quarter: "(1 / 4 :: real) \<le> exp (- 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2056 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2057 |
have eq4: "4 = Suc (Suc (Suc (Suc 0)))" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2058 |
have "1 / 4 = (Float 1 (- 2))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2059 |
unfolding Float_num by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2060 |
also have "\<dots> \<le> lb_exp_horner 3 (get_even 3) 1 1 (- 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2061 |
by (subst less_eq_float.rep_eq [symmetric]) code_simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2062 |
also have "\<dots> \<le> exp (- 1 :: float)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2063 |
using bnds_exp_horner[where x="- 1"] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2064 |
finally show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2065 |
by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2066 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2067 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2068 |
lemma lb_exp_pos: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2069 |
assumes "\<not> 0 < x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2070 |
shows "0 < lb_exp prec x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2071 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2072 |
let "?lb_horner x" = "lb_exp_horner prec (get_even (prec + 2)) 1 1 x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2073 |
let "?horner x" = "let y = ?lb_horner x in if y \<le> 0 then Float 1 (- 2) else y" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2074 |
have pos_horner: "0 < ?horner x" for x |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2075 |
unfolding Let_def by (cases "?lb_horner x \<le> 0") auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2076 |
moreover have "0 < real_of_float ((?horner x) ^ num)" for x :: float and num :: nat |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2077 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2078 |
have "0 < real_of_float (?horner x) ^ num" using \<open>0 < ?horner x\<close> by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2079 |
also have "\<dots> = (?horner x) ^ num" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2080 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2081 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2082 |
ultimately show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2083 |
unfolding lb_exp.simps if_not_P[OF \<open>\<not> 0 < x\<close>] Let_def |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2084 |
by (cases "floor_fl x", cases "x < - 1") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2085 |
(auto simp: real_power_up_fl real_power_down_fl intro!: power_up_less power_down_pos) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2086 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2087 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2088 |
lemma exp_boundaries': |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2089 |
assumes "x \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2090 |
shows "exp x \<in> { (lb_exp prec x) .. (ub_exp prec x)}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2091 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2092 |
let "?lb_exp_horner x" = "lb_exp_horner prec (get_even (prec + 2)) 1 1 x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2093 |
let "?ub_exp_horner x" = "ub_exp_horner prec (get_odd (prec + 2)) 1 1 x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2094 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2095 |
have "real_of_float x \<le> 0" and "\<not> x > 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2096 |
using \<open>x \<le> 0\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2097 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2098 |
proof (cases "x < - 1") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2099 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2100 |
hence "- 1 \<le> real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2101 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2102 |
proof (cases "?lb_exp_horner x \<le> 0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2103 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2104 |
from \<open>\<not> x < - 1\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2105 |
have "- 1 \<le> real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2106 |
hence "exp (- 1) \<le> exp x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2107 |
unfolding exp_le_cancel_iff . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2108 |
from order_trans[OF exp_m1_ge_quarter this] have "Float 1 (- 2) \<le> exp x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2109 |
unfolding Float_num . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2110 |
with True show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2111 |
using bnds_exp_horner \<open>real_of_float x \<le> 0\<close> \<open>\<not> x > 0\<close> \<open>\<not> x < - 1\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2112 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2113 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2114 |
thus ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2115 |
using bnds_exp_horner \<open>real_of_float x \<le> 0\<close> \<open>\<not> x > 0\<close> \<open>\<not> x < - 1\<close> by (auto simp add: Let_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2116 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2117 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2118 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2119 |
let ?num = "nat (- int_floor_fl x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2120 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2121 |
have "real_of_int (int_floor_fl x) < - 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2122 |
using int_floor_fl[of x] \<open>x < - 1\<close> by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2123 |
hence "real_of_int (int_floor_fl x) < 0" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2124 |
hence "int_floor_fl x < 0" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2125 |
hence "1 \<le> - int_floor_fl x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2126 |
hence "0 < nat (- int_floor_fl x)" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2127 |
hence "0 < ?num" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2128 |
hence "real ?num \<noteq> 0" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2129 |
have num_eq: "real ?num = - int_floor_fl x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2130 |
using \<open>0 < nat (- int_floor_fl x)\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2131 |
have "0 < - int_floor_fl x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2132 |
using \<open>0 < ?num\<close>[unfolded of_nat_less_iff[symmetric]] by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2133 |
hence "real_of_int (int_floor_fl x) < 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2134 |
unfolding less_float_def by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2135 |
have fl_eq: "real_of_int (- int_floor_fl x) = real_of_float (- floor_fl x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2136 |
by (simp add: floor_fl_def int_floor_fl_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2137 |
from \<open>0 < - int_floor_fl x\<close> have "0 \<le> real_of_float (- floor_fl x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2138 |
by (simp add: floor_fl_def int_floor_fl_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2139 |
from \<open>real_of_int (int_floor_fl x) < 0\<close> have "real_of_float (floor_fl x) < 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2140 |
by (simp add: floor_fl_def int_floor_fl_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2141 |
have "exp x \<le> ub_exp prec x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2142 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2143 |
have div_less_zero: "real_of_float (float_divr prec x (- floor_fl x)) \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2144 |
using float_divr_nonpos_pos_upper_bound[OF \<open>real_of_float x \<le> 0\<close> \<open>0 \<le> real_of_float (- floor_fl x)\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2145 |
unfolding less_eq_float_def zero_float.rep_eq . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2146 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2147 |
have "exp x = exp (?num * (x / ?num))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2148 |
using \<open>real ?num \<noteq> 0\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2149 |
also have "\<dots> = exp (x / ?num) ^ ?num" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2150 |
unfolding exp_of_nat_mult .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2151 |
also have "\<dots> \<le> exp (float_divr prec x (- floor_fl x)) ^ ?num" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2152 |
unfolding num_eq fl_eq |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2153 |
by (rule power_mono, rule exp_le_cancel_iff[THEN iffD2], rule float_divr) auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2154 |
also have "\<dots> \<le> (?ub_exp_horner (float_divr prec x (- floor_fl x))) ^ ?num" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2155 |
unfolding real_of_float_power |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2156 |
by (rule power_mono, rule bnds_exp_horner[OF div_less_zero, unfolded atLeastAtMost_iff, THEN conjunct2], auto) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2157 |
also have "\<dots> \<le> real_of_float (power_up_fl prec (?ub_exp_horner (float_divr prec x (- floor_fl x))) ?num)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2158 |
by (auto simp add: real_power_up_fl intro!: power_up ub_exp_horner_nonneg div_less_zero) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2159 |
finally show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2160 |
unfolding ub_exp.simps if_not_P[OF \<open>\<not> 0 < x\<close>] if_P[OF \<open>x < - 1\<close>] floor_fl_def Let_def . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2161 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2162 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2163 |
have "lb_exp prec x \<le> exp x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2164 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2165 |
let ?divl = "float_divl prec x (- floor_fl x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2166 |
let ?horner = "?lb_exp_horner ?divl" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2167 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2168 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2169 |
proof (cases "?horner \<le> 0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2170 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2171 |
hence "0 \<le> real_of_float ?horner" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2172 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2173 |
have div_less_zero: "real_of_float (float_divl prec x (- floor_fl x)) \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2174 |
using \<open>real_of_float (floor_fl x) < 0\<close> \<open>real_of_float x \<le> 0\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2175 |
by (auto intro!: order_trans[OF float_divl] divide_nonpos_neg) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2176 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2177 |
have "(?lb_exp_horner (float_divl prec x (- floor_fl x))) ^ ?num \<le> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2178 |
exp (float_divl prec x (- floor_fl x)) ^ ?num" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2179 |
using \<open>0 \<le> real_of_float ?horner\<close>[unfolded floor_fl_def[symmetric]] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2180 |
bnds_exp_horner[OF div_less_zero, unfolded atLeastAtMost_iff, THEN conjunct1] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2181 |
by (auto intro!: power_mono) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2182 |
also have "\<dots> \<le> exp (x / ?num) ^ ?num" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2183 |
unfolding num_eq fl_eq |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2184 |
using float_divl by (auto intro!: power_mono simp del: uminus_float.rep_eq) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2185 |
also have "\<dots> = exp (?num * (x / ?num))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2186 |
unfolding exp_of_nat_mult .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2187 |
also have "\<dots> = exp x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2188 |
using \<open>real ?num \<noteq> 0\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2189 |
finally show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2190 |
using False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2191 |
unfolding lb_exp.simps if_not_P[OF \<open>\<not> 0 < x\<close>] if_P[OF \<open>x < - 1\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2192 |
int_floor_fl_def Let_def if_not_P[OF False] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2193 |
by (auto simp: real_power_down_fl intro!: power_down_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2194 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2195 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2196 |
have "power_down_fl prec (Float 1 (- 2)) ?num \<le> (Float 1 (- 2)) ^ ?num" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2197 |
by (metis Float_le_zero_iff less_imp_le linorder_not_less |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2198 |
not_numeral_le_zero numeral_One power_down_fl) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2199 |
then have "power_down_fl prec (Float 1 (- 2)) ?num \<le> real_of_float (Float 1 (- 2)) ^ ?num" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2200 |
by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2201 |
also |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2202 |
have "real_of_float (floor_fl x) \<noteq> 0" and "real_of_float (floor_fl x) \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2203 |
using \<open>real_of_float (floor_fl x) < 0\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2204 |
from divide_right_mono_neg[OF floor_fl[of x] \<open>real_of_float (floor_fl x) \<le> 0\<close>, unfolded divide_self[OF \<open>real_of_float (floor_fl x) \<noteq> 0\<close>]] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2205 |
have "- 1 \<le> x / (- floor_fl x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2206 |
unfolding minus_float.rep_eq by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2207 |
from order_trans[OF exp_m1_ge_quarter this[unfolded exp_le_cancel_iff[where x="- 1", symmetric]]] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2208 |
have "Float 1 (- 2) \<le> exp (x / (- floor_fl x))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2209 |
unfolding Float_num . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2210 |
hence "real_of_float (Float 1 (- 2)) ^ ?num \<le> exp (x / (- floor_fl x)) ^ ?num" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2211 |
by (metis Float_num(5) power_mono zero_le_divide_1_iff zero_le_numeral) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2212 |
also have "\<dots> = exp x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2213 |
unfolding num_eq fl_eq exp_of_nat_mult[symmetric] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2214 |
using \<open>real_of_float (floor_fl x) \<noteq> 0\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2215 |
finally show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2216 |
unfolding lb_exp.simps if_not_P[OF \<open>\<not> 0 < x\<close>] if_P[OF \<open>x < - 1\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2217 |
int_floor_fl_def Let_def if_P[OF True] real_of_float_power . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2218 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2219 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2220 |
ultimately show ?thesis by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2221 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2222 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2223 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2224 |
lemma exp_boundaries: "exp x \<in> { lb_exp prec x .. ub_exp prec x }" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2225 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2226 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2227 |
proof (cases "0 < x") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2228 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2229 |
hence "x \<le> 0" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2230 |
from exp_boundaries'[OF this] show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2231 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2232 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2233 |
hence "-x \<le> 0" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2234 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2235 |
have "lb_exp prec x \<le> exp x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2236 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2237 |
from exp_boundaries'[OF \<open>-x \<le> 0\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2238 |
have ub_exp: "exp (- real_of_float x) \<le> ub_exp prec (-x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2239 |
unfolding atLeastAtMost_iff minus_float.rep_eq by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2240 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2241 |
have "float_divl prec 1 (ub_exp prec (-x)) \<le> 1 / ub_exp prec (-x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2242 |
using float_divl[where x=1] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2243 |
also have "\<dots> \<le> exp x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2244 |
using ub_exp[unfolded inverse_le_iff_le[OF order_less_le_trans[OF exp_gt_zero ub_exp] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2245 |
exp_gt_zero, symmetric]] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2246 |
unfolding exp_minus nonzero_inverse_inverse_eq[OF exp_not_eq_zero] inverse_eq_divide |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2247 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2248 |
finally show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2249 |
unfolding lb_exp.simps if_P[OF True] . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2250 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2251 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2252 |
have "exp x \<le> ub_exp prec x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2253 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2254 |
have "\<not> 0 < -x" using \<open>0 < x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2255 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2256 |
from exp_boundaries'[OF \<open>-x \<le> 0\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2257 |
have lb_exp: "lb_exp prec (-x) \<le> exp (- real_of_float x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2258 |
unfolding atLeastAtMost_iff minus_float.rep_eq by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2259 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2260 |
have "exp x \<le> (1 :: float) / lb_exp prec (-x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2261 |
using lb_exp lb_exp_pos[OF \<open>\<not> 0 < -x\<close>, of prec] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2262 |
by (simp del: lb_exp.simps add: exp_minus field_simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2263 |
also have "\<dots> \<le> float_divr prec 1 (lb_exp prec (-x))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2264 |
using float_divr . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2265 |
finally show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2266 |
unfolding ub_exp.simps if_P[OF True] . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2267 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2268 |
ultimately show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2269 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2270 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2271 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2272 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2273 |
lemma bnds_exp: "\<forall>(x::real) lx ux. (l, u) = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2274 |
(lb_exp prec lx, ub_exp prec ux) \<and> x \<in> {lx .. ux} \<longrightarrow> l \<le> exp x \<and> exp x \<le> u" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2275 |
proof (rule allI, rule allI, rule allI, rule impI) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2276 |
fix x :: real and lx ux |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2277 |
assume "(l, u) = (lb_exp prec lx, ub_exp prec ux) \<and> x \<in> {lx .. ux}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2278 |
hence l: "lb_exp prec lx = l " and u: "ub_exp prec ux = u" and x: "x \<in> {lx .. ux}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2279 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2280 |
show "l \<le> exp x \<and> exp x \<le> u" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2281 |
proof |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2282 |
show "l \<le> exp x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2283 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2284 |
from exp_boundaries[of lx prec, unfolded l] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2285 |
have "l \<le> exp lx" by (auto simp del: lb_exp.simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2286 |
also have "\<dots> \<le> exp x" using x by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2287 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2288 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2289 |
show "exp x \<le> u" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2290 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2291 |
have "exp x \<le> exp ux" using x by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2292 |
also have "\<dots> \<le> u" using exp_boundaries[of ux prec, unfolded u] by (auto simp del: ub_exp.simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2293 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2294 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2295 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2296 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2297 |
|
71036 | 2298 |
lemmas [simp del] = lb_exp.simps ub_exp.simps |
2299 |
||
2300 |
lemma lb_exp: "exp x \<le> y \<Longrightarrow> lb_exp prec x \<le> y" |
|
2301 |
and ub_exp: "y \<le> exp x \<Longrightarrow> y \<le> ub_exp prec x" |
|
2302 |
for x::float and y::real using exp_boundaries[of x prec] by auto |
|
2303 |
||
2304 |
lift_definition exp_float_interval :: "nat \<Rightarrow> float interval \<Rightarrow> float interval" |
|
2305 |
is "\<lambda>prec. \<lambda>(lx, ux). (lb_exp prec lx, ub_exp prec ux)" |
|
2306 |
by (auto simp: lb_exp ub_exp) |
|
2307 |
||
2308 |
lemma lower_exp_float_interval: "lower (exp_float_interval p x) = lb_exp p (lower x)" |
|
2309 |
by transfer auto |
|
2310 |
lemma upper_exp_float_interval: "upper (exp_float_interval p x) = ub_exp p (upper x)" |
|
2311 |
by transfer auto |
|
2312 |
||
2313 |
lemma exp_float_interval: |
|
2314 |
"exp ` set_of (real_interval x) \<subseteq> set_of (real_interval (exp_float_interval p x))" |
|
2315 |
using exp_boundaries |
|
2316 |
by (auto simp: set_of_eq lower_exp_float_interval upper_exp_float_interval lb_exp ub_exp) |
|
2317 |
||
2318 |
lemma exp_float_intervalI: |
|
2319 |
"exp x \<in>\<^sub>r exp_float_interval p X" if "x \<in>\<^sub>r X" |
|
2320 |
using exp_float_interval[of X p] that |
|
2321 |
by auto |
|
2322 |
||
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2323 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2324 |
section "Logarithm" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2325 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2326 |
subsection "Compute the logarithm series" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2327 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2328 |
fun ub_ln_horner :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2329 |
and lb_ln_horner :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2330 |
"ub_ln_horner prec 0 i x = 0" | |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2331 |
"ub_ln_horner prec (Suc n) i x = float_plus_up prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2332 |
(rapprox_rat prec 1 (int i)) (- float_round_down prec (x * lb_ln_horner prec n (Suc i) x))" | |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2333 |
"lb_ln_horner prec 0 i x = 0" | |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2334 |
"lb_ln_horner prec (Suc n) i x = float_plus_down prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2335 |
(lapprox_rat prec 1 (int i)) (- float_round_up prec (x * ub_ln_horner prec n (Suc i) x))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2336 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2337 |
lemma ln_bounds: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2338 |
assumes "0 \<le> x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2339 |
and "x < 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2340 |
shows "(\<Sum>i=0..<2*n. (- 1) ^ i * (1 / real (i + 1)) * x ^ (Suc i)) \<le> ln (x + 1)" (is "?lb") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2341 |
and "ln (x + 1) \<le> (\<Sum>i=0..<2*n + 1. (- 1) ^ i * (1 / real (i + 1)) * x ^ (Suc i))" (is "?ub") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2342 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2343 |
let "?a n" = "(1/real (n +1)) * x ^ (Suc n)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2344 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2345 |
have ln_eq: "(\<Sum> i. (- 1) ^ i * ?a i) = ln (x + 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2346 |
using ln_series[of "x + 1"] \<open>0 \<le> x\<close> \<open>x < 1\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2347 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2348 |
have "norm x < 1" using assms by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2349 |
have "?a \<longlonglongrightarrow> 0" unfolding Suc_eq_plus1[symmetric] inverse_eq_divide[symmetric] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2350 |
using tendsto_mult[OF LIMSEQ_inverse_real_of_nat LIMSEQ_Suc[OF LIMSEQ_power_zero[OF \<open>norm x < 1\<close>]]] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2351 |
have "0 \<le> ?a n" for n |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2352 |
by (rule mult_nonneg_nonneg) (auto simp: \<open>0 \<le> x\<close>) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2353 |
have "?a (Suc n) \<le> ?a n" for n |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2354 |
unfolding inverse_eq_divide[symmetric] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2355 |
proof (rule mult_mono) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2356 |
show "0 \<le> x ^ Suc (Suc n)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2357 |
by (auto simp add: \<open>0 \<le> x\<close>) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2358 |
have "x ^ Suc (Suc n) \<le> x ^ Suc n * 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2359 |
unfolding power_Suc2 mult.assoc[symmetric] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2360 |
by (rule mult_left_mono, fact less_imp_le[OF \<open>x < 1\<close>]) (auto simp: \<open>0 \<le> x\<close>) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2361 |
thus "x ^ Suc (Suc n) \<le> x ^ Suc n" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2362 |
qed auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2363 |
from summable_Leibniz'(2,4)[OF \<open>?a \<longlonglongrightarrow> 0\<close> \<open>\<And>n. 0 \<le> ?a n\<close>, OF \<open>\<And>n. ?a (Suc n) \<le> ?a n\<close>, unfolded ln_eq] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2364 |
show ?lb and ?ub |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2365 |
unfolding atLeast0LessThan by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2366 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2367 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2368 |
lemma ln_float_bounds: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2369 |
assumes "0 \<le> real_of_float x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2370 |
and "real_of_float x < 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2371 |
shows "x * lb_ln_horner prec (get_even n) 1 x \<le> ln (x + 1)" (is "?lb \<le> ?ln") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2372 |
and "ln (x + 1) \<le> x * ub_ln_horner prec (get_odd n) 1 x" (is "?ln \<le> ?ub") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2373 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2374 |
obtain ev where ev: "get_even n = 2 * ev" using get_even_double .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2375 |
obtain od where od: "get_odd n = 2 * od + 1" using get_odd_double .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2376 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2377 |
let "?s n" = "(- 1) ^ n * (1 / real (1 + n)) * (real_of_float x)^(Suc n)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2378 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2379 |
have "?lb \<le> sum ?s {0 ..< 2 * ev}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2380 |
unfolding power_Suc2 mult.assoc[symmetric] times_float.rep_eq sum_distrib_right[symmetric] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2381 |
unfolding mult.commute[of "real_of_float x"] ev |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2382 |
using horner_bounds(1)[where G="\<lambda> i k. Suc k" and F="\<lambda>x. x" and f="\<lambda>x. x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2383 |
and lb="\<lambda>n i k x. lb_ln_horner prec n k x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2384 |
and ub="\<lambda>n i k x. ub_ln_horner prec n k x" and j'=1 and n="2*ev", |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2385 |
OF \<open>0 \<le> real_of_float x\<close> refl lb_ln_horner.simps ub_ln_horner.simps] \<open>0 \<le> real_of_float x\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2386 |
unfolding real_of_float_power |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2387 |
by (rule mult_right_mono) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2388 |
also have "\<dots> \<le> ?ln" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2389 |
using ln_bounds(1)[OF \<open>0 \<le> real_of_float x\<close> \<open>real_of_float x < 1\<close>] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2390 |
finally show "?lb \<le> ?ln" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2391 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2392 |
have "?ln \<le> sum ?s {0 ..< 2 * od + 1}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2393 |
using ln_bounds(2)[OF \<open>0 \<le> real_of_float x\<close> \<open>real_of_float x < 1\<close>] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2394 |
also have "\<dots> \<le> ?ub" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2395 |
unfolding power_Suc2 mult.assoc[symmetric] times_float.rep_eq sum_distrib_right[symmetric] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2396 |
unfolding mult.commute[of "real_of_float x"] od |
71036 | 2397 |
using horner_bounds(2)[where G="\<lambda> i k. Suc k" and F="\<lambda>x. x" and f="\<lambda>x. x" and lb="\<lambda>n i k x. lb_ln_horner prec n k x" and ub="\<lambda>n i k x. ub_ln_horner prec n k x" and j'=1 and n="2 * od + 1", |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2398 |
OF \<open>0 \<le> real_of_float x\<close> refl lb_ln_horner.simps ub_ln_horner.simps] \<open>0 \<le> real_of_float x\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2399 |
unfolding real_of_float_power |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2400 |
by (rule mult_right_mono) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2401 |
finally show "?ln \<le> ?ub" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2402 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2403 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2404 |
lemma ln_add: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2405 |
fixes x :: real |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2406 |
assumes "0 < x" and "0 < y" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2407 |
shows "ln (x + y) = ln x + ln (1 + y / x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2408 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2409 |
have "x \<noteq> 0" using assms by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2410 |
have "x + y = x * (1 + y / x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2411 |
unfolding distrib_left times_divide_eq_right nonzero_mult_div_cancel_left[OF \<open>x \<noteq> 0\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2412 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2413 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2414 |
have "0 < y / x" using assms by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2415 |
hence "0 < 1 + y / x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2416 |
ultimately show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2417 |
using ln_mult assms by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2418 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2419 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2420 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2421 |
subsection "Compute the logarithm of 2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2422 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2423 |
definition ub_ln2 where "ub_ln2 prec = (let third = rapprox_rat (max prec 1) 1 3 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2424 |
in float_plus_up prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2425 |
((Float 1 (- 1) * ub_ln_horner prec (get_odd prec) 1 (Float 1 (- 1)))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2426 |
(float_round_up prec (third * ub_ln_horner prec (get_odd prec) 1 third)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2427 |
definition lb_ln2 where "lb_ln2 prec = (let third = lapprox_rat prec 1 3 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2428 |
in float_plus_down prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2429 |
((Float 1 (- 1) * lb_ln_horner prec (get_even prec) 1 (Float 1 (- 1)))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2430 |
(float_round_down prec (third * lb_ln_horner prec (get_even prec) 1 third)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2431 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2432 |
lemma ub_ln2: "ln 2 \<le> ub_ln2 prec" (is "?ub_ln2") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2433 |
and lb_ln2: "lb_ln2 prec \<le> ln 2" (is "?lb_ln2") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2434 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2435 |
let ?uthird = "rapprox_rat (max prec 1) 1 3" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2436 |
let ?lthird = "lapprox_rat prec 1 3" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2437 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2438 |
have ln2_sum: "ln 2 = ln (1/2 + 1) + ln (1 / 3 + 1::real)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2439 |
using ln_add[of "3 / 2" "1 / 2"] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2440 |
have lb3: "?lthird \<le> 1 / 3" using lapprox_rat[of prec 1 3] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2441 |
hence lb3_ub: "real_of_float ?lthird < 1" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2442 |
have lb3_lb: "0 \<le> real_of_float ?lthird" using lapprox_rat_nonneg[of 1 3] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2443 |
have ub3: "1 / 3 \<le> ?uthird" using rapprox_rat[of 1 3] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2444 |
hence ub3_lb: "0 \<le> real_of_float ?uthird" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2445 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2446 |
have lb2: "0 \<le> real_of_float (Float 1 (- 1))" and ub2: "real_of_float (Float 1 (- 1)) < 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2447 |
unfolding Float_num by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2448 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2449 |
have "0 \<le> (1::int)" and "0 < (3::int)" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2450 |
have ub3_ub: "real_of_float ?uthird < 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2451 |
by (simp add: Float.compute_rapprox_rat Float.compute_lapprox_rat rapprox_posrat_less1) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2452 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2453 |
have third_gt0: "(0 :: real) < 1 / 3 + 1" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2454 |
have uthird_gt0: "0 < real_of_float ?uthird + 1" using ub3_lb by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2455 |
have lthird_gt0: "0 < real_of_float ?lthird + 1" using lb3_lb by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2456 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2457 |
show ?ub_ln2 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2458 |
unfolding ub_ln2_def Let_def ln2_sum Float_num(4)[symmetric] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2459 |
proof (rule float_plus_up_le, rule add_mono, fact ln_float_bounds(2)[OF lb2 ub2]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2460 |
have "ln (1 / 3 + 1) \<le> ln (real_of_float ?uthird + 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2461 |
unfolding ln_le_cancel_iff[OF third_gt0 uthird_gt0] using ub3 by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2462 |
also have "\<dots> \<le> ?uthird * ub_ln_horner prec (get_odd prec) 1 ?uthird" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2463 |
using ln_float_bounds(2)[OF ub3_lb ub3_ub] . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2464 |
also note float_round_up |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2465 |
finally show "ln (1 / 3 + 1) \<le> float_round_up prec (?uthird * ub_ln_horner prec (get_odd prec) 1 ?uthird)" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2466 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2467 |
show ?lb_ln2 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2468 |
unfolding lb_ln2_def Let_def ln2_sum Float_num(4)[symmetric] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2469 |
proof (rule float_plus_down_le, rule add_mono, fact ln_float_bounds(1)[OF lb2 ub2]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2470 |
have "?lthird * lb_ln_horner prec (get_even prec) 1 ?lthird \<le> ln (real_of_float ?lthird + 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2471 |
using ln_float_bounds(1)[OF lb3_lb lb3_ub] . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2472 |
note float_round_down_le[OF this] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2473 |
also have "\<dots> \<le> ln (1 / 3 + 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2474 |
unfolding ln_le_cancel_iff[OF lthird_gt0 third_gt0] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2475 |
using lb3 by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2476 |
finally show "float_round_down prec (?lthird * lb_ln_horner prec (get_even prec) 1 ?lthird) \<le> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2477 |
ln (1 / 3 + 1)" . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2478 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2479 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2480 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2481 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2482 |
subsection "Compute the logarithm in the entire domain" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2483 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2484 |
function ub_ln :: "nat \<Rightarrow> float \<Rightarrow> float option" and lb_ln :: "nat \<Rightarrow> float \<Rightarrow> float option" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2485 |
"ub_ln prec x = (if x \<le> 0 then None |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2486 |
else if x < 1 then Some (- the (lb_ln prec (float_divl (max prec 1) 1 x))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2487 |
else let horner = \<lambda>x. float_round_up prec (x * ub_ln_horner prec (get_odd prec) 1 x) in |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2488 |
if x \<le> Float 3 (- 1) then Some (horner (x - 1)) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2489 |
else if x < Float 1 1 then Some (float_round_up prec (horner (Float 1 (- 1)) + horner (x * rapprox_rat prec 2 3 - 1))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2490 |
else let l = bitlen (mantissa x) - 1 in |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2491 |
Some (float_plus_up prec (float_round_up prec (ub_ln2 prec * (Float (exponent x + l) 0))) (horner (Float (mantissa x) (- l) - 1))))" | |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2492 |
"lb_ln prec x = (if x \<le> 0 then None |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2493 |
else if x < 1 then Some (- the (ub_ln prec (float_divr prec 1 x))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2494 |
else let horner = \<lambda>x. float_round_down prec (x * lb_ln_horner prec (get_even prec) 1 x) in |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2495 |
if x \<le> Float 3 (- 1) then Some (horner (x - 1)) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2496 |
else if x < Float 1 1 then Some (float_round_down prec (horner (Float 1 (- 1)) + |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2497 |
horner (max (x * lapprox_rat prec 2 3 - 1) 0))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2498 |
else let l = bitlen (mantissa x) - 1 in |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2499 |
Some (float_plus_down prec (float_round_down prec (lb_ln2 prec * (Float (exponent x + l) 0))) (horner (Float (mantissa x) (- l) - 1))))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2500 |
by pat_completeness auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2501 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2502 |
termination |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2503 |
proof (relation "measure (\<lambda> v. let (prec, x) = case_sum id id v in (if x < 1 then 1 else 0))", auto) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2504 |
fix prec and x :: float |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2505 |
assume "\<not> real_of_float x \<le> 0" and "real_of_float x < 1" and "real_of_float (float_divl (max prec (Suc 0)) 1 x) < 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2506 |
hence "0 < real_of_float x" "1 \<le> max prec (Suc 0)" "real_of_float x < 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2507 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2508 |
from float_divl_pos_less1_bound[OF \<open>0 < real_of_float x\<close> \<open>real_of_float x < 1\<close>[THEN less_imp_le] \<open>1 \<le> max prec (Suc 0)\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2509 |
show False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2510 |
using \<open>real_of_float (float_divl (max prec (Suc 0)) 1 x) < 1\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2511 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2512 |
fix prec x |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2513 |
assume "\<not> real_of_float x \<le> 0" and "real_of_float x < 1" and "real_of_float (float_divr prec 1 x) < 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2514 |
hence "0 < x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2515 |
from float_divr_pos_less1_lower_bound[OF \<open>0 < x\<close>, of prec] \<open>real_of_float x < 1\<close> show False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2516 |
using \<open>real_of_float (float_divr prec 1 x) < 1\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2517 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2518 |
|
67573 | 2519 |
lemmas float_pos_eq_mantissa_pos = mantissa_pos_iff[symmetric] |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2520 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2521 |
lemma Float_pos_eq_mantissa_pos: "Float m e > 0 \<longleftrightarrow> m > 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2522 |
using powr_gt_zero[of 2 "e"] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2523 |
by (auto simp add: zero_less_mult_iff zero_float_def simp del: powr_gt_zero dest: less_zeroE) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2524 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2525 |
lemma Float_representation_aux: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2526 |
fixes m e |
67573 | 2527 |
defines [THEN meta_eq_to_obj_eq]: "x \<equiv> Float m e" |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2528 |
assumes "x > 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2529 |
shows "Float (exponent x + (bitlen (mantissa x) - 1)) 0 = Float (e + (bitlen m - 1)) 0" (is ?th1) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2530 |
and "Float (mantissa x) (- (bitlen (mantissa x) - 1)) = Float m ( - (bitlen m - 1))" (is ?th2) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2531 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2532 |
from assms have mantissa_pos: "m > 0" "mantissa x > 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2533 |
using Float_pos_eq_mantissa_pos[of m e] float_pos_eq_mantissa_pos[of x] by simp_all |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2534 |
thus ?th1 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2535 |
using bitlen_Float[of m e] assms |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2536 |
by (auto simp add: zero_less_mult_iff intro!: arg_cong2[where f=Float]) |
67573 | 2537 |
have "x \<noteq> 0" |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2538 |
unfolding zero_float_def[symmetric] using \<open>0 < x\<close> by auto |
67573 | 2539 |
from denormalize_shift[OF x_def this] obtain i where |
2540 |
i: "m = mantissa x * 2 ^ i" "e = exponent x - int i" . |
|
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2541 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2542 |
have "2 powr (1 - (real_of_int (bitlen (mantissa x)) + real_of_int i)) = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2543 |
2 powr (1 - (real_of_int (bitlen (mantissa x)))) * inverse (2 powr (real i))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2544 |
by (simp add: powr_minus[symmetric] powr_add[symmetric] field_simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2545 |
hence "real_of_int (mantissa x) * 2 powr (1 - real_of_int (bitlen (mantissa x))) = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2546 |
(real_of_int (mantissa x) * 2 ^ i) * 2 powr (1 - real_of_int (bitlen (mantissa x * 2 ^ i)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2547 |
using \<open>mantissa x > 0\<close> by (simp add: powr_realpow) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2548 |
then show ?th2 |
67573 | 2549 |
unfolding i |
2550 |
by (auto simp: real_of_float_eq) |
|
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2551 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2552 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2553 |
lemma compute_ln[code]: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2554 |
fixes m e |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2555 |
defines "x \<equiv> Float m e" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2556 |
shows "ub_ln prec x = (if x \<le> 0 then None |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2557 |
else if x < 1 then Some (- the (lb_ln prec (float_divl (max prec 1) 1 x))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2558 |
else let horner = \<lambda>x. float_round_up prec (x * ub_ln_horner prec (get_odd prec) 1 x) in |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2559 |
if x \<le> Float 3 (- 1) then Some (horner (x - 1)) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2560 |
else if x < Float 1 1 then Some (float_round_up prec (horner (Float 1 (- 1)) + horner (x * rapprox_rat prec 2 3 - 1))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2561 |
else let l = bitlen m - 1 in |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2562 |
Some (float_plus_up prec (float_round_up prec (ub_ln2 prec * (Float (e + l) 0))) (horner (Float m (- l) - 1))))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2563 |
(is ?th1) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2564 |
and "lb_ln prec x = (if x \<le> 0 then None |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2565 |
else if x < 1 then Some (- the (ub_ln prec (float_divr prec 1 x))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2566 |
else let horner = \<lambda>x. float_round_down prec (x * lb_ln_horner prec (get_even prec) 1 x) in |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2567 |
if x \<le> Float 3 (- 1) then Some (horner (x - 1)) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2568 |
else if x < Float 1 1 then Some (float_round_down prec (horner (Float 1 (- 1)) + |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2569 |
horner (max (x * lapprox_rat prec 2 3 - 1) 0))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2570 |
else let l = bitlen m - 1 in |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2571 |
Some (float_plus_down prec (float_round_down prec (lb_ln2 prec * (Float (e + l) 0))) (horner (Float m (- l) - 1))))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2572 |
(is ?th2) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2573 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2574 |
from assms Float_pos_eq_mantissa_pos have "x > 0 \<Longrightarrow> m > 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2575 |
by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2576 |
thus ?th1 ?th2 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2577 |
using Float_representation_aux[of m e] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2578 |
unfolding x_def[symmetric] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2579 |
by (auto dest: not_le_imp_less) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2580 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2581 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2582 |
lemma ln_shifted_float: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2583 |
assumes "0 < m" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2584 |
shows "ln (Float m e) = ln 2 * (e + (bitlen m - 1)) + ln (Float m (- (bitlen m - 1)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2585 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2586 |
let ?B = "2^nat (bitlen m - 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2587 |
define bl where "bl = bitlen m - 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2588 |
have "0 < real_of_int m" and "\<And>X. (0 :: real) < 2^X" and "0 < (2 :: real)" and "m \<noteq> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2589 |
using assms by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2590 |
hence "0 \<le> bl" by (simp add: bitlen_alt_def bl_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2591 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2592 |
proof (cases "0 \<le> e") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2593 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2594 |
thus ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2595 |
unfolding bl_def[symmetric] using \<open>0 < real_of_int m\<close> \<open>0 \<le> bl\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2596 |
apply (simp add: ln_mult) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2597 |
apply (cases "e=0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2598 |
apply (cases "bl = 0", simp_all add: powr_minus ln_inverse ln_powr) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2599 |
apply (cases "bl = 0", simp_all add: powr_minus ln_inverse ln_powr field_simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2600 |
done |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2601 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2602 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2603 |
hence "0 < -e" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2604 |
have lne: "ln (2 powr real_of_int e) = ln (inverse (2 powr - e))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2605 |
by (simp add: powr_minus) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2606 |
hence pow_gt0: "(0::real) < 2^nat (-e)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2607 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2608 |
hence inv_gt0: "(0::real) < inverse (2^nat (-e))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2609 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2610 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2611 |
using False unfolding bl_def[symmetric] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2612 |
using \<open>0 < real_of_int m\<close> \<open>0 \<le> bl\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2613 |
by (auto simp add: lne ln_mult ln_powr ln_div field_simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2614 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2615 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2616 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2617 |
lemma ub_ln_lb_ln_bounds': |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2618 |
assumes "1 \<le> x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2619 |
shows "the (lb_ln prec x) \<le> ln x \<and> ln x \<le> the (ub_ln prec x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2620 |
(is "?lb \<le> ?ln \<and> ?ln \<le> ?ub") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2621 |
proof (cases "x < Float 1 1") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2622 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2623 |
hence "real_of_float (x - 1) < 1" and "real_of_float x < 2" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2624 |
have "\<not> x \<le> 0" and "\<not> x < 1" using \<open>1 \<le> x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2625 |
hence "0 \<le> real_of_float (x - 1)" using \<open>1 \<le> x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2626 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2627 |
have [simp]: "(Float 3 (- 1)) = 3 / 2" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2628 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2629 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2630 |
proof (cases "x \<le> Float 3 (- 1)") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2631 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2632 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2633 |
unfolding lb_ln.simps |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2634 |
unfolding ub_ln.simps Let_def |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2635 |
using ln_float_bounds[OF \<open>0 \<le> real_of_float (x - 1)\<close> \<open>real_of_float (x - 1) < 1\<close>, of prec] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2636 |
\<open>\<not> x \<le> 0\<close> \<open>\<not> x < 1\<close> True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2637 |
by (auto intro!: float_round_down_le float_round_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2638 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2639 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2640 |
hence *: "3 / 2 < x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2641 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2642 |
with ln_add[of "3 / 2" "x - 3 / 2"] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2643 |
have add: "ln x = ln (3 / 2) + ln (real_of_float x * 2 / 3)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2644 |
by (auto simp add: algebra_simps diff_divide_distrib) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2645 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2646 |
let "?ub_horner x" = "float_round_up prec (x * ub_ln_horner prec (get_odd prec) 1 x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2647 |
let "?lb_horner x" = "float_round_down prec (x * lb_ln_horner prec (get_even prec) 1 x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2648 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2649 |
{ have up: "real_of_float (rapprox_rat prec 2 3) \<le> 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2650 |
by (rule rapprox_rat_le1) simp_all |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2651 |
have low: "2 / 3 \<le> rapprox_rat prec 2 3" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2652 |
by (rule order_trans[OF _ rapprox_rat]) simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2653 |
from mult_less_le_imp_less[OF * low] * |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2654 |
have pos: "0 < real_of_float (x * rapprox_rat prec 2 3 - 1)" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2655 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2656 |
have "ln (real_of_float x * 2/3) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2657 |
\<le> ln (real_of_float (x * rapprox_rat prec 2 3 - 1) + 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2658 |
proof (rule ln_le_cancel_iff[symmetric, THEN iffD1]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2659 |
show "real_of_float x * 2 / 3 \<le> real_of_float (x * rapprox_rat prec 2 3 - 1) + 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2660 |
using * low by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2661 |
show "0 < real_of_float x * 2 / 3" using * by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2662 |
show "0 < real_of_float (x * rapprox_rat prec 2 3 - 1) + 1" using pos by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2663 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2664 |
also have "\<dots> \<le> ?ub_horner (x * rapprox_rat prec 2 3 - 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2665 |
proof (rule float_round_up_le, rule ln_float_bounds(2)) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2666 |
from mult_less_le_imp_less[OF \<open>real_of_float x < 2\<close> up] low * |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2667 |
show "real_of_float (x * rapprox_rat prec 2 3 - 1) < 1" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2668 |
show "0 \<le> real_of_float (x * rapprox_rat prec 2 3 - 1)" using pos by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2669 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2670 |
finally have "ln x \<le> ?ub_horner (Float 1 (-1)) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2671 |
+ ?ub_horner ((x * rapprox_rat prec 2 3 - 1))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2672 |
using ln_float_bounds(2)[of "Float 1 (- 1)" prec prec] add |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2673 |
by (auto intro!: add_mono float_round_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2674 |
note float_round_up_le[OF this, of prec] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2675 |
} |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2676 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2677 |
{ let ?max = "max (x * lapprox_rat prec 2 3 - 1) 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2678 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2679 |
have up: "lapprox_rat prec 2 3 \<le> 2/3" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2680 |
by (rule order_trans[OF lapprox_rat], simp) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2681 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2682 |
have low: "0 \<le> real_of_float (lapprox_rat prec 2 3)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2683 |
using lapprox_rat_nonneg[of 2 3 prec] by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2684 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2685 |
have "?lb_horner ?max |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2686 |
\<le> ln (real_of_float ?max + 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2687 |
proof (rule float_round_down_le, rule ln_float_bounds(1)) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2688 |
from mult_less_le_imp_less[OF \<open>real_of_float x < 2\<close> up] * low |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2689 |
show "real_of_float ?max < 1" by (cases "real_of_float (lapprox_rat prec 2 3) = 0", |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2690 |
auto simp add: real_of_float_max) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2691 |
show "0 \<le> real_of_float ?max" by (auto simp add: real_of_float_max) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2692 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2693 |
also have "\<dots> \<le> ln (real_of_float x * 2/3)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2694 |
proof (rule ln_le_cancel_iff[symmetric, THEN iffD1]) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2695 |
show "0 < real_of_float ?max + 1" by (auto simp add: real_of_float_max) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2696 |
show "0 < real_of_float x * 2/3" using * by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2697 |
show "real_of_float ?max + 1 \<le> real_of_float x * 2/3" using * up |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2698 |
by (cases "0 < real_of_float x * real_of_float (lapprox_posrat prec 2 3) - 1", |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2699 |
auto simp add: max_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2700 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2701 |
finally have "?lb_horner (Float 1 (- 1)) + ?lb_horner ?max \<le> ln x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2702 |
using ln_float_bounds(1)[of "Float 1 (- 1)" prec prec] add |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2703 |
by (auto intro!: add_mono float_round_down_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2704 |
note float_round_down_le[OF this, of prec] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2705 |
} |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2706 |
ultimately |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2707 |
show ?thesis unfolding lb_ln.simps unfolding ub_ln.simps Let_def |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2708 |
using \<open>\<not> x \<le> 0\<close> \<open>\<not> x < 1\<close> True False by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2709 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2710 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2711 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2712 |
hence "\<not> x \<le> 0" and "\<not> x < 1" "0 < x" "\<not> x \<le> Float 3 (- 1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2713 |
using \<open>1 \<le> x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2714 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2715 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2716 |
define m where "m = mantissa x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2717 |
define e where "e = exponent x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2718 |
from Float_mantissa_exponent[of x] have Float: "x = Float m e" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2719 |
by (simp add: m_def e_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2720 |
let ?s = "Float (e + (bitlen m - 1)) 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2721 |
let ?x = "Float m (- (bitlen m - 1))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2722 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2723 |
have "0 < m" and "m \<noteq> 0" using \<open>0 < x\<close> Float powr_gt_zero[of 2 e] |
67573 | 2724 |
by (auto simp add: zero_less_mult_iff) |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2725 |
define bl where "bl = bitlen m - 1" |
70350 | 2726 |
then have bitlen: "bitlen m = bl + 1" |
2727 |
by simp |
|
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2728 |
hence "bl \<ge> 0" |
70350 | 2729 |
using \<open>m > 0\<close> by (auto simp add: bitlen_alt_def) |
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2730 |
have "1 \<le> Float m e" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2731 |
using \<open>1 \<le> x\<close> Float unfolding less_eq_float_def by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2732 |
from bitlen_div[OF \<open>0 < m\<close>] float_gt1_scale[OF \<open>1 \<le> Float m e\<close>] \<open>bl \<ge> 0\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2733 |
have x_bnds: "0 \<le> real_of_float (?x - 1)" "real_of_float (?x - 1) < 1" |
70350 | 2734 |
using abs_real_le_2_powr_bitlen [of m] \<open>m > 0\<close> |
2735 |
by (simp_all add: bitlen powr_realpow [symmetric] powr_minus powr_add field_simps) |
|
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2736 |
{ |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2737 |
have "float_round_down prec (lb_ln2 prec * ?s) \<le> ln 2 * (e + (bitlen m - 1))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2738 |
(is "real_of_float ?lb2 \<le> _") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2739 |
apply (rule float_round_down_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2740 |
unfolding nat_0 power_0 mult_1_right times_float.rep_eq |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2741 |
using lb_ln2[of prec] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2742 |
proof (rule mult_mono) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2743 |
from float_gt1_scale[OF \<open>1 \<le> Float m e\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2744 |
show "0 \<le> real_of_float (Float (e + (bitlen m - 1)) 0)" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2745 |
qed auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2746 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2747 |
from ln_float_bounds(1)[OF x_bnds] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2748 |
have "float_round_down prec ((?x - 1) * lb_ln_horner prec (get_even prec) 1 (?x - 1)) \<le> ln ?x" (is "real_of_float ?lb_horner \<le> _") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2749 |
by (auto intro!: float_round_down_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2750 |
ultimately have "float_plus_down prec ?lb2 ?lb_horner \<le> ln x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2751 |
unfolding Float ln_shifted_float[OF \<open>0 < m\<close>, of e] by (auto intro!: float_plus_down_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2752 |
} |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2753 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2754 |
{ |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2755 |
from ln_float_bounds(2)[OF x_bnds] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2756 |
have "ln ?x \<le> float_round_up prec ((?x - 1) * ub_ln_horner prec (get_odd prec) 1 (?x - 1))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2757 |
(is "_ \<le> real_of_float ?ub_horner") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2758 |
by (auto intro!: float_round_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2759 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2760 |
have "ln 2 * (e + (bitlen m - 1)) \<le> float_round_up prec (ub_ln2 prec * ?s)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2761 |
(is "_ \<le> real_of_float ?ub2") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2762 |
apply (rule float_round_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2763 |
unfolding nat_0 power_0 mult_1_right times_float.rep_eq |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2764 |
using ub_ln2[of prec] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2765 |
proof (rule mult_mono) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2766 |
from float_gt1_scale[OF \<open>1 \<le> Float m e\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2767 |
show "0 \<le> real_of_int (e + (bitlen m - 1))" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2768 |
have "0 \<le> ln (2 :: real)" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2769 |
thus "0 \<le> real_of_float (ub_ln2 prec)" using ub_ln2[of prec] by arith |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2770 |
qed auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2771 |
ultimately have "ln x \<le> float_plus_up prec ?ub2 ?ub_horner" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2772 |
unfolding Float ln_shifted_float[OF \<open>0 < m\<close>, of e] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2773 |
by (auto intro!: float_plus_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2774 |
} |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2775 |
ultimately show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2776 |
unfolding lb_ln.simps |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2777 |
unfolding ub_ln.simps |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2778 |
unfolding if_not_P[OF \<open>\<not> x \<le> 0\<close>] if_not_P[OF \<open>\<not> x < 1\<close>] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2779 |
if_not_P[OF False] if_not_P[OF \<open>\<not> x \<le> Float 3 (- 1)\<close>] Let_def |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2780 |
unfolding plus_float.rep_eq e_def[symmetric] m_def[symmetric] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2781 |
by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2782 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2783 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2784 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2785 |
lemma ub_ln_lb_ln_bounds: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2786 |
assumes "0 < x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2787 |
shows "the (lb_ln prec x) \<le> ln x \<and> ln x \<le> the (ub_ln prec x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2788 |
(is "?lb \<le> ?ln \<and> ?ln \<le> ?ub") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2789 |
proof (cases "x < 1") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2790 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2791 |
hence "1 \<le> x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2792 |
unfolding less_float_def less_eq_float_def by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2793 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2794 |
using ub_ln_lb_ln_bounds'[OF \<open>1 \<le> x\<close>] . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2795 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2796 |
case True |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2797 |
have "\<not> x \<le> 0" using \<open>0 < x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2798 |
from True have "real_of_float x \<le> 1" "x \<le> 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2799 |
by simp_all |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2800 |
have "0 < real_of_float x" and "real_of_float x \<noteq> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2801 |
using \<open>0 < x\<close> by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2802 |
hence A: "0 < 1 / real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2803 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2804 |
{ |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2805 |
let ?divl = "float_divl (max prec 1) 1 x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2806 |
have A': "1 \<le> ?divl" using float_divl_pos_less1_bound[OF \<open>0 < real_of_float x\<close> \<open>real_of_float x \<le> 1\<close>] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2807 |
hence B: "0 < real_of_float ?divl" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2808 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2809 |
have "ln ?divl \<le> ln (1 / x)" unfolding ln_le_cancel_iff[OF B A] using float_divl[of _ 1 x] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2810 |
hence "ln x \<le> - ln ?divl" unfolding nonzero_inverse_eq_divide[OF \<open>real_of_float x \<noteq> 0\<close>, symmetric] ln_inverse[OF \<open>0 < real_of_float x\<close>] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2811 |
from this ub_ln_lb_ln_bounds'[OF A', THEN conjunct1, THEN le_imp_neg_le] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2812 |
have "?ln \<le> - the (lb_ln prec ?divl)" unfolding uminus_float.rep_eq by (rule order_trans) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2813 |
} moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2814 |
{ |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2815 |
let ?divr = "float_divr prec 1 x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2816 |
have A': "1 \<le> ?divr" using float_divr_pos_less1_lower_bound[OF \<open>0 < x\<close> \<open>x \<le> 1\<close>] unfolding less_eq_float_def less_float_def by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2817 |
hence B: "0 < real_of_float ?divr" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2818 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2819 |
have "ln (1 / x) \<le> ln ?divr" unfolding ln_le_cancel_iff[OF A B] using float_divr[of 1 x] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2820 |
hence "- ln ?divr \<le> ln x" unfolding nonzero_inverse_eq_divide[OF \<open>real_of_float x \<noteq> 0\<close>, symmetric] ln_inverse[OF \<open>0 < real_of_float x\<close>] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2821 |
from ub_ln_lb_ln_bounds'[OF A', THEN conjunct2, THEN le_imp_neg_le] this |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2822 |
have "- the (ub_ln prec ?divr) \<le> ?ln" unfolding uminus_float.rep_eq by (rule order_trans) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2823 |
} |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2824 |
ultimately show ?thesis unfolding lb_ln.simps[where x=x] ub_ln.simps[where x=x] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2825 |
unfolding if_not_P[OF \<open>\<not> x \<le> 0\<close>] if_P[OF True] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2826 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2827 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2828 |
lemma lb_ln: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2829 |
assumes "Some y = lb_ln prec x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2830 |
shows "y \<le> ln x" and "0 < real_of_float x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2831 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2832 |
have "0 < x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2833 |
proof (rule ccontr) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2834 |
assume "\<not> 0 < x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2835 |
hence "x \<le> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2836 |
unfolding less_eq_float_def less_float_def by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2837 |
thus False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2838 |
using assms by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2839 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2840 |
thus "0 < real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2841 |
have "the (lb_ln prec x) \<le> ln x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2842 |
using ub_ln_lb_ln_bounds[OF \<open>0 < x\<close>] .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2843 |
thus "y \<le> ln x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2844 |
unfolding assms[symmetric] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2845 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2846 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2847 |
lemma ub_ln: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2848 |
assumes "Some y = ub_ln prec x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2849 |
shows "ln x \<le> y" and "0 < real_of_float x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2850 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2851 |
have "0 < x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2852 |
proof (rule ccontr) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2853 |
assume "\<not> 0 < x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2854 |
hence "x \<le> 0" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2855 |
thus False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2856 |
using assms by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2857 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2858 |
thus "0 < real_of_float x" by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2859 |
have "ln x \<le> the (ub_ln prec x)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2860 |
using ub_ln_lb_ln_bounds[OF \<open>0 < x\<close>] .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2861 |
thus "ln x \<le> y" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2862 |
unfolding assms[symmetric] by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2863 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2864 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2865 |
lemma bnds_ln: "\<forall>(x::real) lx ux. (Some l, Some u) = |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2866 |
(lb_ln prec lx, ub_ln prec ux) \<and> x \<in> {lx .. ux} \<longrightarrow> l \<le> ln x \<and> ln x \<le> u" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2867 |
proof (rule allI, rule allI, rule allI, rule impI) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2868 |
fix x :: real |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2869 |
fix lx ux |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2870 |
assume "(Some l, Some u) = (lb_ln prec lx, ub_ln prec ux) \<and> x \<in> {lx .. ux}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2871 |
hence l: "Some l = lb_ln prec lx " and u: "Some u = ub_ln prec ux" and x: "x \<in> {lx .. ux}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2872 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2873 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2874 |
have "ln ux \<le> u" and "0 < real_of_float ux" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2875 |
using ub_ln u by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2876 |
have "l \<le> ln lx" and "0 < real_of_float lx" and "0 < x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2877 |
using lb_ln[OF l] x by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2878 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2879 |
from ln_le_cancel_iff[OF \<open>0 < real_of_float lx\<close> \<open>0 < x\<close>] \<open>l \<le> ln lx\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2880 |
have "l \<le> ln x" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2881 |
using x unfolding atLeastAtMost_iff by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2882 |
moreover |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2883 |
from ln_le_cancel_iff[OF \<open>0 < x\<close> \<open>0 < real_of_float ux\<close>] \<open>ln ux \<le> real_of_float u\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2884 |
have "ln x \<le> u" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2885 |
using x unfolding atLeastAtMost_iff by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2886 |
ultimately show "l \<le> ln x \<and> ln x \<le> u" .. |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2887 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2888 |
|
71036 | 2889 |
lemmas [simp del] = lb_ln.simps ub_ln.simps |
2890 |
||
2891 |
lemma lb_lnD: |
|
2892 |
"y \<le> ln x \<and> 0 < real_of_float x" if "lb_ln prec x = Some y" |
|
2893 |
using lb_ln[OF that[symmetric]] by auto |
|
2894 |
||
2895 |
lemma ub_lnD: |
|
2896 |
"ln x \<le> y\<and> 0 < real_of_float x" if "ub_ln prec x = Some y" |
|
2897 |
using ub_ln[OF that[symmetric]] by auto |
|
2898 |
||
2899 |
lift_definition(code_dt) ln_float_interval :: "nat \<Rightarrow> float interval \<Rightarrow> float interval option" |
|
2900 |
is "\<lambda>prec. \<lambda>(lx, ux). |
|
2901 |
Option.bind (lb_ln prec lx) (\<lambda>l. |
|
2902 |
Option.bind (ub_ln prec ux) (\<lambda>u. Some (l, u)))" |
|
2903 |
by (auto simp: pred_option_def bind_eq_Some_conv ln_le_cancel_iff[symmetric] |
|
2904 |
simp del: ln_le_cancel_iff dest!: lb_lnD ub_lnD) |
|
2905 |
||
2906 |
lemma ln_float_interval_eq_Some_conv: |
|
2907 |
"ln_float_interval p x = Some y \<longleftrightarrow> |
|
2908 |
lb_ln p (lower x) = Some (lower y) \<and> ub_ln p (upper x) = Some (upper y)" |
|
2909 |
by transfer (auto simp: bind_eq_Some_conv) |
|
2910 |
||
2911 |
lemma ln_float_interval: "ln ` set_of (real_interval x) \<subseteq> set_of (real_interval y)" |
|
2912 |
if "ln_float_interval p x = Some y" |
|
2913 |
using that lb_ln[of "lower y" p "lower x"] |
|
2914 |
ub_ln[of "lower y" p "lower x"] |
|
2915 |
apply (auto simp add: set_of_eq ln_float_interval_eq_Some_conv ln_le_cancel_iff) |
|
2916 |
apply (meson less_le_trans ln_less_cancel_iff not_le) |
|
2917 |
by (meson less_le_trans ln_less_cancel_iff not_le ub_lnD) |
|
2918 |
||
2919 |
lemma ln_float_intervalI: |
|
2920 |
"ln x \<in> set_of' (ln_float_interval p X)" if "x \<in>\<^sub>r X" |
|
2921 |
using ln_float_interval[of p X] that |
|
2922 |
by (auto simp: set_of'_def split: option.splits) |
|
2923 |
||
71037
f630f2e707a6
refactor Approximation.thy to use more abstract type of intervals
immler
parents:
71036
diff
changeset
|
2924 |
lemma ln_float_interval_eqI: |
f630f2e707a6
refactor Approximation.thy to use more abstract type of intervals
immler
parents:
71036
diff
changeset
|
2925 |
"ln x \<in>\<^sub>r IVL" if "ln_float_interval p X = Some IVL" "x \<in>\<^sub>r X" |
f630f2e707a6
refactor Approximation.thy to use more abstract type of intervals
immler
parents:
71036
diff
changeset
|
2926 |
using ln_float_intervalI[of x X p] that |
f630f2e707a6
refactor Approximation.thy to use more abstract type of intervals
immler
parents:
71036
diff
changeset
|
2927 |
by (auto simp: set_of'_def split: option.splits) |
f630f2e707a6
refactor Approximation.thy to use more abstract type of intervals
immler
parents:
71036
diff
changeset
|
2928 |
|
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2929 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2930 |
section \<open>Real power function\<close> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2931 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2932 |
definition bnds_powr :: "nat \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float \<Rightarrow> (float \<times> float) option" where |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2933 |
"bnds_powr prec l1 u1 l2 u2 = ( |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2934 |
if l1 = 0 \<and> u1 = 0 then |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2935 |
Some (0, 0) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2936 |
else if l1 = 0 \<and> l2 \<ge> 1 then |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2937 |
let uln = the (ub_ln prec u1) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2938 |
in Some (0, ub_exp prec (float_round_up prec (uln * (if uln \<ge> 0 then u2 else l2)))) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2939 |
else if l1 \<le> 0 then |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2940 |
None |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2941 |
else |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2942 |
Some (map_bnds lb_exp ub_exp prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2943 |
(bnds_mult prec (the (lb_ln prec l1)) (the (ub_ln prec u1)) l2 u2)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2944 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2945 |
lemma mono_exp_real: "mono (exp :: real \<Rightarrow> real)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2946 |
by (auto simp: mono_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2947 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2948 |
lemma ub_exp_nonneg: "real_of_float (ub_exp prec x) \<ge> 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2949 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2950 |
have "0 \<le> exp (real_of_float x)" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2951 |
also from exp_boundaries[of x prec] |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2952 |
have "\<dots> \<le> real_of_float (ub_exp prec x)" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2953 |
finally show ?thesis . |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2954 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2955 |
|
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2956 |
lemma bnds_powr: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2957 |
assumes lu: "Some (l, u) = bnds_powr prec l1 u1 l2 u2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2958 |
assumes x: "x \<in> {real_of_float l1..real_of_float u1}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2959 |
assumes y: "y \<in> {real_of_float l2..real_of_float u2}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2960 |
shows "x powr y \<in> {real_of_float l..real_of_float u}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2961 |
proof - |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2962 |
consider "l1 = 0" "u1 = 0" | "l1 = 0" "u1 \<noteq> 0" "l2 \<ge> 1" | |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2963 |
"l1 \<le> 0" "\<not>(l1 = 0 \<and> (u1 = 0 \<or> l2 \<ge> 1))" | "l1 > 0" by force |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2964 |
thus ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2965 |
proof cases |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2966 |
assume "l1 = 0" "u1 = 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2967 |
with x lu show ?thesis by (auto simp: bnds_powr_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2968 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2969 |
assume A: "l1 = 0" "u1 \<noteq> 0" "l2 \<ge> 1" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2970 |
define uln where "uln = the (ub_ln prec u1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2971 |
show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2972 |
proof (cases "x = 0") |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2973 |
case False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2974 |
with A x y have "x powr y = exp (ln x * y)" by (simp add: powr_def) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2975 |
also { |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2976 |
from A x False have "ln x \<le> ln (real_of_float u1)" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2977 |
also from ub_ln_lb_ln_bounds[of u1 prec] A y x False |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2978 |
have "ln (real_of_float u1) \<le> real_of_float uln" by (simp add: uln_def del: lb_ln.simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2979 |
also from A x y have "\<dots> * y \<le> real_of_float uln * (if uln \<ge> 0 then u2 else l2)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2980 |
by (auto intro: mult_left_mono mult_left_mono_neg) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2981 |
also have "\<dots> \<le> real_of_float (float_round_up prec (uln * (if uln \<ge> 0 then u2 else l2)))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2982 |
by (simp add: float_round_up_le) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2983 |
finally have "ln x * y \<le> \<dots>" using A y by - simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2984 |
} |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2985 |
also have "exp (real_of_float (float_round_up prec (uln * (if uln \<ge> 0 then u2 else l2)))) \<le> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2986 |
real_of_float (ub_exp prec (float_round_up prec |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2987 |
(uln * (if uln \<ge> 0 then u2 else l2))))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2988 |
using exp_boundaries by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2989 |
finally show ?thesis using A x y lu |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2990 |
by (simp add: bnds_powr_def uln_def Let_def del: lb_ln.simps ub_ln.simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2991 |
qed (insert x y lu A, simp_all add: bnds_powr_def Let_def ub_exp_nonneg |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2992 |
del: lb_ln.simps ub_ln.simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2993 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2994 |
assume "l1 \<le> 0" "\<not>(l1 = 0 \<and> (u1 = 0 \<or> l2 \<ge> 1))" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2995 |
with lu show ?thesis by (simp add: bnds_powr_def split: if_split_asm) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2996 |
next |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2997 |
assume l1: "l1 > 0" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2998 |
obtain lm um where lmum: |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
2999 |
"(lm, um) = bnds_mult prec (the (lb_ln prec l1)) (the (ub_ln prec u1)) l2 u2" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3000 |
by (cases "bnds_mult prec (the (lb_ln prec l1)) (the (ub_ln prec u1)) l2 u2") simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3001 |
with l1 have "(l, u) = map_bnds lb_exp ub_exp prec (lm, um)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3002 |
using lu by (simp add: bnds_powr_def del: lb_ln.simps ub_ln.simps split: if_split_asm) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3003 |
hence "exp (ln x * y) \<in> {real_of_float l..real_of_float u}" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3004 |
proof (rule map_bnds[OF _ mono_exp_real], goal_cases) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3005 |
case 1 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3006 |
let ?lln = "the (lb_ln prec l1)" and ?uln = "the (ub_ln prec u1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3007 |
from ub_ln_lb_ln_bounds[of l1 prec] ub_ln_lb_ln_bounds[of u1 prec] x l1 |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3008 |
have "real_of_float ?lln \<le> ln (real_of_float l1) \<and> |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3009 |
ln (real_of_float u1) \<le> real_of_float ?uln" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3010 |
by (auto simp del: lb_ln.simps ub_ln.simps) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3011 |
moreover from l1 x have "ln (real_of_float l1) \<le> ln x \<and> ln x \<le> ln (real_of_float u1)" |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3012 |
by auto |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3013 |
ultimately have ln: "real_of_float ?lln \<le> ln x \<and> ln x \<le> real_of_float ?uln" by simp |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3014 |
from lmum show ?case |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3015 |
by (rule bnds_mult) (insert y ln, simp_all) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3016 |
qed (insert exp_boundaries[of lm prec] exp_boundaries[of um prec], simp_all) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3017 |
with x l1 show ?thesis |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3018 |
by (simp add: powr_def mult_ac) |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3019 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3020 |
qed |
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3021 |
|
71036 | 3022 |
lift_definition(code_dt) powr_float_interval :: "nat \<Rightarrow> float interval \<Rightarrow> float interval \<Rightarrow> float interval option" |
3023 |
is "\<lambda>prec. \<lambda>(l1, u1). \<lambda>(l2, u2). bnds_powr prec l1 u1 l2 u2" |
|
3024 |
by (auto simp: pred_option_def dest!: bnds_powr[OF sym]) |
|
3025 |
||
3026 |
lemma powr_float_interval: |
|
3027 |
"{x powr y | x y. x \<in> set_of (real_interval X) \<and> y \<in> set_of (real_interval Y)} |
|
3028 |
\<subseteq> set_of (real_interval R)" |
|
3029 |
if "powr_float_interval prec X Y = Some R" |
|
3030 |
using that |
|
3031 |
by transfer (auto dest!: bnds_powr[OF sym]) |
|
3032 |
||
3033 |
lemma powr_float_intervalI: |
|
3034 |
"x powr y \<in> set_of' (powr_float_interval p X Y)" |
|
3035 |
if "x \<in>\<^sub>r X" "y \<in>\<^sub>r Y" |
|
3036 |
using powr_float_interval[of p X Y] that |
|
3037 |
by (auto simp: set_of'_def split: option.splits) |
|
3038 |
||
71037
f630f2e707a6
refactor Approximation.thy to use more abstract type of intervals
immler
parents:
71036
diff
changeset
|
3039 |
lemma powr_float_interval_eqI: |
f630f2e707a6
refactor Approximation.thy to use more abstract type of intervals
immler
parents:
71036
diff
changeset
|
3040 |
"x powr y \<in>\<^sub>r IVL" |
f630f2e707a6
refactor Approximation.thy to use more abstract type of intervals
immler
parents:
71036
diff
changeset
|
3041 |
if "powr_float_interval p X Y = Some IVL" "x \<in>\<^sub>r X" "y \<in>\<^sub>r Y" |
f630f2e707a6
refactor Approximation.thy to use more abstract type of intervals
immler
parents:
71036
diff
changeset
|
3042 |
using powr_float_intervalI[of x X y Y p] that |
f630f2e707a6
refactor Approximation.thy to use more abstract type of intervals
immler
parents:
71036
diff
changeset
|
3043 |
by (auto simp: set_of'_def split: option.splits) |
f630f2e707a6
refactor Approximation.thy to use more abstract type of intervals
immler
parents:
71036
diff
changeset
|
3044 |
|
65582
a1bc1b020cf2
tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff
changeset
|
3045 |
end |
71036 | 3046 |
|
3047 |
end |