moved activation of coercion inference into RealDef and declared function real a coercion.
Made use of it in theory Ln.
5 header {* Properties of ln *}
11 lemma exp_first_two_terms: "exp x = 1 + x + suminf (%n.
12 inverse(fact (n+2)) * (x ^ (n+2)))"
14 have "exp x = suminf (%n. inverse(fact n) * (x ^ n))"
15 by (simp add: exp_def)
16 also from summable_exp have "... = (SUM n::nat : {0..<2}.
17 inverse(fact n) * (x ^ n)) + suminf (%n.
18 inverse(fact(n+2)) * (x ^ (n+2)))" (is "_ = ?a + _")
19 by (rule suminf_split_initial_segment)
20 also have "?a = 1 + x"
21 by (simp add: numerals)
22 finally show ?thesis .
25 lemma exp_tail_after_first_two_terms_summable:
26 "summable (%n. inverse(fact (n+2)) * (x ^ (n+2)))"
30 by (frule summable_ignore_initial_segment)
33 lemma aux1: assumes a: "0 <= x" and b: "x <= 1"
34 shows "inverse (fact ((n::nat) + 2)) * x ^ (n + 2) <= (x^2/2) * ((1/2)^n)"
36 show "inverse (fact ((0::nat) + 2)) * x ^ (0 + 2) <=
37 x ^ 2 / 2 * (1 / 2) ^ 0"
38 by (simp add: real_of_nat_Suc power2_eq_square)
41 assume c: "inverse (fact (n + 2)) * x ^ (n + 2)
42 <= x ^ 2 / 2 * (1 / 2) ^ n"
43 show "inverse (fact (Suc n + 2)) * x ^ (Suc n + 2)
44 <= x ^ 2 / 2 * (1 / 2) ^ Suc n"
46 have "inverse(fact (Suc n + 2)) <= (1/2) * inverse (fact (n+2))"
48 have "Suc n + 2 = Suc (n + 2)" by simp
49 then have "fact (Suc n + 2) = Suc (n + 2) * fact (n + 2)"
51 then have "real(fact (Suc n + 2)) = real(Suc (n + 2) * fact (n + 2))"
55 also have "... = real(Suc (n + 2)) * real(fact (n + 2))"
56 by (rule real_of_nat_mult)
57 finally have "real (fact (Suc n + 2)) =
58 real (Suc (n + 2)) * real (fact (n + 2))" .
59 then have "inverse(fact (Suc n + 2)) =
60 inverse(Suc (n + 2)) * inverse(fact (n + 2))"
62 apply (rule inverse_mult_distrib)
64 also have "... <= (1/2) * inverse(fact (n + 2))"
65 apply (rule mult_right_mono)
66 apply (subst inverse_eq_divide)
68 apply (rule inv_real_of_nat_fact_ge_zero)
70 finally show ?thesis .
72 moreover have "x ^ (Suc n + 2) <= x ^ (n + 2)"
73 apply (simp add: mult_compare_simps)
74 apply (simp add: prems)
75 apply (subgoal_tac "0 <= x * (x * x^n)")
77 apply (rule mult_nonneg_nonneg, rule a)+
78 apply (rule zero_le_power, rule a)
80 ultimately have "inverse (fact (Suc n + 2)) * x ^ (Suc n + 2) <=
81 (1 / 2 * inverse (fact (n + 2))) * x ^ (n + 2)"
82 apply (rule mult_mono)
83 apply (rule mult_nonneg_nonneg)
85 apply (subst inverse_nonnegative_iff_nonnegative)
86 apply (rule real_of_nat_ge_zero)
87 apply (rule zero_le_power)
90 also have "... = 1 / 2 * (inverse (fact (n + 2)) * x ^ (n + 2))"
92 also have "... <= 1 / 2 * (x ^ 2 / 2 * (1 / 2) ^ n)"
93 apply (rule mult_left_mono)
97 also have "... = x ^ 2 / 2 * (1 / 2 * (1 / 2) ^ n)"
99 also have "(1::real) / 2 * (1 / 2) ^ n = (1 / 2) ^ (Suc n)"
100 by (rule power_Suc [THEN sym])
101 finally show ?thesis .
105 lemma aux2: "(%n. (x::real) ^ 2 / 2 * (1 / 2) ^ n) sums x^2"
107 have "(%n. (1 / 2::real)^n) sums (1 / (1 - (1/2)))"
108 apply (rule geometric_sums)
109 by (simp add: abs_less_iff)
110 also have "(1::real) / (1 - 1/2) = 2"
112 finally have "(%n. (1 / 2::real)^n) sums 2" .
113 then have "(%n. x ^ 2 / 2 * (1 / 2) ^ n) sums (x^2 / 2 * 2)"
115 also have "x^2 / 2 * 2 = x^2"
117 finally show ?thesis .
120 lemma exp_bound: "0 <= (x::real) ==> x <= 1 ==> exp x <= 1 + x + x^2"
124 have c: "exp x = 1 + x + suminf (%n. inverse(fact (n+2)) *
126 by (rule exp_first_two_terms)
127 moreover have "suminf (%n. inverse(fact (n+2)) * (x ^ (n+2))) <= x^2"
129 have "suminf (%n. inverse(fact (n+2)) * (x ^ (n+2))) <=
130 suminf (%n. (x^2/2) * ((1/2)^n))"
131 apply (rule summable_le)
132 apply (auto simp only: aux1 prems)
133 apply (rule exp_tail_after_first_two_terms_summable)
134 by (rule sums_summable, rule aux2)
135 also have "... = x^2"
136 by (rule sums_unique [THEN sym], rule aux2)
137 finally show ?thesis .
139 ultimately show ?thesis
143 lemma aux4: "0 <= (x::real) ==> x <= 1 ==> exp (x - x^2) <= 1 + x"
145 assume a: "0 <= x" and b: "x <= 1"
146 have "exp (x - x^2) = exp x / exp (x^2)"
148 also have "... <= (1 + x + x^2) / exp (x ^2)"
149 apply (rule divide_right_mono)
150 apply (rule exp_bound)
151 apply (rule a, rule b)
154 also have "... <= (1 + x + x^2) / (1 + x^2)"
155 apply (rule divide_left_mono)
156 apply (auto simp add: exp_ge_add_one_self_aux)
157 apply (rule add_nonneg_nonneg)
158 apply (insert prems, auto)
159 apply (rule mult_pos_pos)
161 apply (rule add_pos_nonneg)
164 also from a have "... <= 1 + x"
165 by(simp add:field_simps zero_compare_simps)
166 finally show ?thesis .
169 lemma ln_one_plus_pos_lower_bound: "0 <= x ==> x <= 1 ==>
170 x - x^2 <= ln (1 + x)"
172 assume a: "0 <= x" and b: "x <= 1"
173 then have "exp (x - x^2) <= 1 + x"
175 also have "... = exp (ln (1 + x))"
177 from a have "0 < 1 + x" by auto
179 by (auto simp only: exp_ln_iff [THEN sym])
181 finally have "exp (x - x ^ 2) <= exp (ln (1 + x))" .
182 thus ?thesis by (auto simp only: exp_le_cancel_iff)
185 lemma ln_one_minus_pos_upper_bound: "0 <= x ==> x < 1 ==> ln (1 - x) <= - x"
187 assume a: "0 <= (x::real)" and b: "x < 1"
188 have "(1 - x) * (1 + x + x^2) = (1 - x^3)"
189 by (simp add: algebra_simps power2_eq_square power3_eq_cube)
191 by (auto simp add: a)
192 finally have "(1 - x) * (1 + x + x ^ 2) <= 1" .
193 moreover have "0 < 1 + x + x^2"
194 apply (rule add_pos_nonneg)
195 apply (insert a, auto)
197 ultimately have "1 - x <= 1 / (1 + x + x^2)"
198 by (elim mult_imp_le_div_pos)
199 also have "... <= 1 / exp x"
200 apply (rule divide_left_mono)
201 apply (rule exp_bound, rule a)
202 apply (insert prems, auto)
203 apply (rule mult_pos_pos)
204 apply (rule add_pos_nonneg)
207 also have "... = exp (-x)"
208 by (auto simp add: exp_minus divide_inverse)
209 finally have "1 - x <= exp (- x)" .
210 also have "1 - x = exp (ln (1 - x))"
215 by (auto simp only: exp_ln_iff [THEN sym])
217 finally have "exp (ln (1 - x)) <= exp (- x)" .
218 thus ?thesis by (auto simp only: exp_le_cancel_iff)
221 lemma aux5: "x < 1 ==> ln(1 - x) = - ln(1 + x / (1 - x))"
224 have "ln(1 - x) = - ln(1 / (1 - x))"
226 have "ln(1 - x) = - (- ln (1 - x))"
228 also have "- ln(1 - x) = ln 1 - ln(1 - x)"
230 also have "... = ln(1 / (1 - x))"
231 apply (rule ln_div [THEN sym])
233 finally show ?thesis .
235 also have " 1 / (1 - x) = 1 + x / (1 - x)" using a by(simp add:field_simps)
236 finally show ?thesis .
239 lemma ln_one_minus_pos_lower_bound: "0 <= x ==> x <= (1 / 2) ==>
240 - x - 2 * x^2 <= ln (1 - x)"
242 assume a: "0 <= x" and b: "x <= (1 / 2)"
243 from b have c: "x < 1"
245 then have "ln (1 - x) = - ln (1 + x / (1 - x))"
247 also have "- (x / (1 - x)) <= ..."
249 have "ln (1 + x / (1 - x)) <= x / (1 - x)"
250 apply (rule ln_add_one_self_le_self)
251 apply (rule divide_nonneg_pos)
252 by (insert a c, auto)
256 also have "- (x / (1 - x)) = -x / (1 - x)"
258 finally have d: "- x / (1 - x) <= ln (1 - x)" .
259 have "0 < 1 - x" using prems by simp
260 hence e: "-x - 2 * x^2 <= - x / (1 - x)"
261 using mult_right_le_one_le[of "x*x" "2*x"] prems
262 by(simp add:field_simps power2_eq_square)
263 from e d show "- x - 2 * x^2 <= ln (1 - x)"
264 by (rule order_trans)
267 lemma exp_ge_add_one_self [simp]: "1 + (x::real) <= exp x"
268 apply (case_tac "0 <= x")
269 apply (erule exp_ge_add_one_self_aux)
270 apply (case_tac "x <= -1")
271 apply (subgoal_tac "1 + x <= 0")
272 apply (erule order_trans)
275 apply (subgoal_tac "1 + x = exp(ln (1 + x))")
277 apply (subst exp_le_cancel_iff)
278 apply (subgoal_tac "ln (1 - (- x)) <= - (- x)")
280 apply (rule ln_one_minus_pos_upper_bound)
284 lemma ln_add_one_self_le_self2: "-1 < x ==> ln(1 + x) <= x"
285 apply (subgoal_tac "x = ln (exp x)")
286 apply (erule ssubst)back
287 apply (subst ln_le_cancel_iff)
291 lemma abs_ln_one_plus_x_minus_x_bound_nonneg:
292 "0 <= x ==> x <= 1 ==> abs(ln (1 + x) - x) <= x^2"
296 from x have "ln (1 + x) <= x"
297 by (rule ln_add_one_self_le_self)
298 then have "ln (1 + x) - x <= 0"
300 then have "abs(ln(1 + x) - x) = - (ln(1 + x) - x)"
301 by (rule abs_of_nonpos)
302 also have "... = x - ln (1 + x)"
304 also have "... <= x^2"
306 from prems have "x - x^2 <= ln (1 + x)"
307 by (intro ln_one_plus_pos_lower_bound)
311 finally show ?thesis .
314 lemma abs_ln_one_plus_x_minus_x_bound_nonpos:
315 "-(1 / 2) <= x ==> x <= 0 ==> abs(ln (1 + x) - x) <= 2 * x^2"
317 assume "-(1 / 2) <= x"
319 have "abs(ln (1 + x) - x) = x - ln(1 - (-x))"
320 apply (subst abs_of_nonpos)
322 apply (rule ln_add_one_self_le_self2)
323 apply (insert prems, auto)
325 also have "... <= 2 * x^2"
326 apply (subgoal_tac "- (-x) - 2 * (-x)^2 <= ln (1 - (-x))")
327 apply (simp add: algebra_simps)
328 apply (rule ln_one_minus_pos_lower_bound)
329 apply (insert prems, auto)
331 finally show ?thesis .
334 lemma abs_ln_one_plus_x_minus_x_bound:
335 "abs x <= 1 / 2 ==> abs(ln (1 + x) - x) <= 2 * x^2"
336 apply (case_tac "0 <= x")
337 apply (rule order_trans)
338 apply (rule abs_ln_one_plus_x_minus_x_bound_nonneg)
340 apply (rule abs_ln_one_plus_x_minus_x_bound_nonpos)
344 lemma ln_x_over_x_mono: "exp 1 <= x ==> x <= y ==> (ln y / y) <= (ln x / x)"
346 assume "exp 1 <= x" and "x <= y"
347 have a: "0 < x" and b: "0 < y"
349 apply (subgoal_tac "0 < exp (1::real)")
352 apply (subgoal_tac "0 < exp (1::real)")
356 have "x * ln y - x * ln x = x * (ln y - ln x)"
357 by (simp add: algebra_simps)
358 also have "... = x * ln(y / x)"
360 apply (rule b, rule a, rule refl)
362 also have "y / x = (x + (y - x)) / x"
364 also have "... = 1 + (y - x) / x" using a prems by(simp add:field_simps)
365 also have "x * ln(1 + (y - x) / x) <= x * ((y - x) / x)"
366 apply (rule mult_left_mono)
367 apply (rule ln_add_one_self_le_self)
368 apply (rule divide_nonneg_pos)
369 apply (insert prems a, simp_all)
371 also have "... = y - x" using a by simp
372 also have "... = (y - x) * ln (exp 1)" by simp
373 also have "... <= (y - x) * ln x"
374 apply (rule mult_left_mono)
375 apply (subst ln_le_cancel_iff)
379 apply (insert prems, simp)
381 also have "... = y * ln x - x * ln x"
382 by (rule left_diff_distrib)
383 finally have "x * ln y <= y * ln x"
385 then have "ln y <= (y * ln x) / x" using a by(simp add:field_simps)
386 also have "... = y * (ln x / x)" by simp
387 finally show ?thesis using b by(simp add:field_simps)