5 header {* Properties of ln *}
11 lemma exp_first_two_terms: "exp x = 1 + x + suminf (%n.
12 inverse(real (fact (n+2))) * (x ^ (n+2)))"
14 have "exp x = suminf (%n. inverse(real (fact n)) * (x ^ n))"
15 by (simp add: exp_def)
16 also from summable_exp have "... = (SUM n : {0..<2}.
17 inverse(real (fact n)) * (x ^ n)) + suminf (%n.
18 inverse(real (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(real (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 (real (fact (n + 2))) * x ^ (n + 2) <= (x^2/2) * ((1/2)^n)"
36 show "inverse (real (fact (0 + 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 (real (fact (n + 2))) * x ^ (n + 2)
42 <= x ^ 2 / 2 * (1 / 2) ^ n"
43 show "inverse (real (fact (Suc n + 2))) * x ^ (Suc n + 2)
44 <= x ^ 2 / 2 * (1 / 2) ^ Suc n"
46 have "inverse(real (fact (Suc n + 2))) <=
47 (1 / 2) *inverse (real (fact (n+2)))"
49 have "Suc n + 2 = Suc (n + 2)" by simp
50 then have "fact (Suc n + 2) = Suc (n + 2) * fact (n + 2)"
52 then have "real(fact (Suc n + 2)) = real(Suc (n + 2) * fact (n + 2))"
56 also have "... = real(Suc (n + 2)) * real(fact (n + 2))"
57 by (rule real_of_nat_mult)
58 finally have "real (fact (Suc n + 2)) =
59 real (Suc (n + 2)) * real (fact (n + 2))" .
60 then have "inverse(real (fact (Suc n + 2))) =
61 inverse(real (Suc (n + 2))) * inverse(real (fact (n + 2)))"
63 apply (rule inverse_mult_distrib)
65 also have "... <= (1/2) * inverse(real (fact (n + 2)))"
66 apply (rule mult_right_mono)
67 apply (subst inverse_eq_divide)
69 apply (rule inv_real_of_nat_fact_ge_zero)
71 finally show ?thesis .
73 moreover have "x ^ (Suc n + 2) <= x ^ (n + 2)"
74 apply (simp add: mult_compare_simps)
75 apply (simp add: prems)
76 apply (subgoal_tac "0 <= x * (x * x^n)")
78 apply (rule mult_nonneg_nonneg, rule a)+
79 apply (rule zero_le_power, rule a)
81 ultimately have "inverse (real (fact (Suc n + 2))) * x ^ (Suc n + 2) <=
82 (1 / 2 * inverse (real (fact (n + 2)))) * x ^ (n + 2)"
83 apply (rule mult_mono)
84 apply (rule mult_nonneg_nonneg)
86 apply (subst inverse_nonnegative_iff_nonnegative)
87 apply (rule real_of_nat_ge_zero)
88 apply (rule zero_le_power)
91 also have "... = 1 / 2 * (inverse (real (fact (n + 2))) * x ^ (n + 2))"
93 also have "... <= 1 / 2 * (x ^ 2 / 2 * (1 / 2) ^ n)"
94 apply (rule mult_left_mono)
98 also have "... = x ^ 2 / 2 * (1 / 2 * (1 / 2) ^ n)"
100 also have "(1::real) / 2 * (1 / 2) ^ n = (1 / 2) ^ (Suc n)"
101 by (rule power_Suc [THEN sym])
102 finally show ?thesis .
106 lemma aux2: "(%n. (x::real) ^ 2 / 2 * (1 / 2) ^ n) sums x^2"
108 have "(%n. (1 / 2::real)^n) sums (1 / (1 - (1/2)))"
109 apply (rule geometric_sums)
110 by (simp add: abs_less_iff)
111 also have "(1::real) / (1 - 1/2) = 2"
113 finally have "(%n. (1 / 2::real)^n) sums 2" .
114 then have "(%n. x ^ 2 / 2 * (1 / 2) ^ n) sums (x^2 / 2 * 2)"
116 also have "x^2 / 2 * 2 = x^2"
118 finally show ?thesis .
121 lemma exp_bound: "0 <= (x::real) ==> x <= 1 ==> exp x <= 1 + x + x^2"
125 have c: "exp x = 1 + x + suminf (%n. inverse(real (fact (n+2))) *
127 by (rule exp_first_two_terms)
128 moreover have "suminf (%n. inverse(real (fact (n+2))) * (x ^ (n+2))) <= x^2"
130 have "suminf (%n. inverse(real (fact (n+2))) * (x ^ (n+2))) <=
131 suminf (%n. (x^2/2) * ((1/2)^n))"
132 apply (rule summable_le)
133 apply (auto simp only: aux1 prems)
134 apply (rule exp_tail_after_first_two_terms_summable)
135 by (rule sums_summable, rule aux2)
136 also have "... = x^2"
137 by (rule sums_unique [THEN sym], rule aux2)
138 finally show ?thesis .
140 ultimately show ?thesis
144 lemma aux4: "0 <= (x::real) ==> x <= 1 ==> exp (x - x^2) <= 1 + x"
146 assume a: "0 <= x" and b: "x <= 1"
147 have "exp (x - x^2) = exp x / exp (x^2)"
149 also have "... <= (1 + x + x^2) / exp (x ^2)"
150 apply (rule divide_right_mono)
151 apply (rule exp_bound)
152 apply (rule a, rule b)
155 also have "... <= (1 + x + x^2) / (1 + x^2)"
156 apply (rule divide_left_mono)
157 apply (auto simp add: exp_ge_add_one_self_aux)
158 apply (rule add_nonneg_nonneg)
159 apply (insert prems, auto)
160 apply (rule mult_pos_pos)
162 apply (rule add_pos_nonneg)
165 also from a have "... <= 1 + x"
166 by(simp add:field_simps zero_compare_simps)
167 finally show ?thesis .
170 lemma ln_one_plus_pos_lower_bound: "0 <= x ==> x <= 1 ==>
171 x - x^2 <= ln (1 + x)"
173 assume a: "0 <= x" and b: "x <= 1"
174 then have "exp (x - x^2) <= 1 + x"
176 also have "... = exp (ln (1 + x))"
178 from a have "0 < 1 + x" by auto
180 by (auto simp only: exp_ln_iff [THEN sym])
182 finally have "exp (x - x ^ 2) <= exp (ln (1 + x))" .
183 thus ?thesis by (auto simp only: exp_le_cancel_iff)
186 lemma ln_one_minus_pos_upper_bound: "0 <= x ==> x < 1 ==> ln (1 - x) <= - x"
188 assume a: "0 <= (x::real)" and b: "x < 1"
189 have "(1 - x) * (1 + x + x^2) = (1 - x^3)"
190 by (simp add: algebra_simps power2_eq_square power3_eq_cube)
192 by (auto simp add: a)
193 finally have "(1 - x) * (1 + x + x ^ 2) <= 1" .
194 moreover have "0 < 1 + x + x^2"
195 apply (rule add_pos_nonneg)
196 apply (insert a, auto)
198 ultimately have "1 - x <= 1 / (1 + x + x^2)"
199 by (elim mult_imp_le_div_pos)
200 also have "... <= 1 / exp x"
201 apply (rule divide_left_mono)
202 apply (rule exp_bound, rule a)
203 apply (insert prems, auto)
204 apply (rule mult_pos_pos)
205 apply (rule add_pos_nonneg)
208 also have "... = exp (-x)"
209 by (auto simp add: exp_minus real_divide_def)
210 finally have "1 - x <= exp (- x)" .
211 also have "1 - x = exp (ln (1 - x))"
216 by (auto simp only: exp_ln_iff [THEN sym])
218 finally have "exp (ln (1 - x)) <= exp (- x)" .
219 thus ?thesis by (auto simp only: exp_le_cancel_iff)
222 lemma aux5: "x < 1 ==> ln(1 - x) = - ln(1 + x / (1 - x))"
225 have "ln(1 - x) = - ln(1 / (1 - x))"
227 have "ln(1 - x) = - (- ln (1 - x))"
229 also have "- ln(1 - x) = ln 1 - ln(1 - x)"
231 also have "... = ln(1 / (1 - x))"
232 apply (rule ln_div [THEN sym])
234 finally show ?thesis .
236 also have " 1 / (1 - x) = 1 + x / (1 - x)" using a by(simp add:field_simps)
237 finally show ?thesis .
240 lemma ln_one_minus_pos_lower_bound: "0 <= x ==> x <= (1 / 2) ==>
241 - x - 2 * x^2 <= ln (1 - x)"
243 assume a: "0 <= x" and b: "x <= (1 / 2)"
244 from b have c: "x < 1"
246 then have "ln (1 - x) = - ln (1 + x / (1 - x))"
248 also have "- (x / (1 - x)) <= ..."
250 have "ln (1 + x / (1 - x)) <= x / (1 - x)"
251 apply (rule ln_add_one_self_le_self)
252 apply (rule divide_nonneg_pos)
253 by (insert a c, auto)
257 also have "- (x / (1 - x)) = -x / (1 - x)"
259 finally have d: "- x / (1 - x) <= ln (1 - x)" .
260 have "0 < 1 - x" using prems by simp
261 hence e: "-x - 2 * x^2 <= - x / (1 - x)"
262 using mult_right_le_one_le[of "x*x" "2*x"] prems
263 by(simp add:field_simps power2_eq_square)
264 from e d show "- x - 2 * x^2 <= ln (1 - x)"
265 by (rule order_trans)
268 lemma exp_ge_add_one_self [simp]: "1 + (x::real) <= exp x"
269 apply (case_tac "0 <= x")
270 apply (erule exp_ge_add_one_self_aux)
271 apply (case_tac "x <= -1")
272 apply (subgoal_tac "1 + x <= 0")
273 apply (erule order_trans)
276 apply (subgoal_tac "1 + x = exp(ln (1 + x))")
278 apply (subst exp_le_cancel_iff)
279 apply (subgoal_tac "ln (1 - (- x)) <= - (- x)")
281 apply (rule ln_one_minus_pos_upper_bound)
285 lemma ln_add_one_self_le_self2: "-1 < x ==> ln(1 + x) <= x"
286 apply (subgoal_tac "x = ln (exp x)")
287 apply (erule ssubst)back
288 apply (subst ln_le_cancel_iff)
292 lemma abs_ln_one_plus_x_minus_x_bound_nonneg:
293 "0 <= x ==> x <= 1 ==> abs(ln (1 + x) - x) <= x^2"
297 from x have "ln (1 + x) <= x"
298 by (rule ln_add_one_self_le_self)
299 then have "ln (1 + x) - x <= 0"
301 then have "abs(ln(1 + x) - x) = - (ln(1 + x) - x)"
302 by (rule abs_of_nonpos)
303 also have "... = x - ln (1 + x)"
305 also have "... <= x^2"
307 from prems have "x - x^2 <= ln (1 + x)"
308 by (intro ln_one_plus_pos_lower_bound)
312 finally show ?thesis .
315 lemma abs_ln_one_plus_x_minus_x_bound_nonpos:
316 "-(1 / 2) <= x ==> x <= 0 ==> abs(ln (1 + x) - x) <= 2 * x^2"
318 assume "-(1 / 2) <= x"
320 have "abs(ln (1 + x) - x) = x - ln(1 - (-x))"
321 apply (subst abs_of_nonpos)
323 apply (rule ln_add_one_self_le_self2)
324 apply (insert prems, auto)
326 also have "... <= 2 * x^2"
327 apply (subgoal_tac "- (-x) - 2 * (-x)^2 <= ln (1 - (-x))")
328 apply (simp add: algebra_simps)
329 apply (rule ln_one_minus_pos_lower_bound)
330 apply (insert prems, auto)
332 finally show ?thesis .
335 lemma abs_ln_one_plus_x_minus_x_bound:
336 "abs x <= 1 / 2 ==> abs(ln (1 + x) - x) <= 2 * x^2"
337 apply (case_tac "0 <= x")
338 apply (rule order_trans)
339 apply (rule abs_ln_one_plus_x_minus_x_bound_nonneg)
341 apply (rule abs_ln_one_plus_x_minus_x_bound_nonpos)
345 lemma DERIV_ln: "0 < x ==> DERIV ln x :> 1 / x"
346 apply (unfold deriv_def, unfold LIM_def, clarsimp)
351 apply (subgoal_tac "(ln (x + xa) - ln x) / xa - (1 / x) =
352 (ln (1 + xa / x) - xa / x) / xa")
354 apply (subst abs_divide)
355 apply (rule mult_imp_div_pos_less)
357 apply (rule order_le_less_trans)
358 apply (rule abs_ln_one_plus_x_minus_x_bound)
359 apply (subst abs_divide)
360 apply (subst abs_of_pos, assumption)
361 apply (erule mult_imp_div_pos_le)
362 apply (subgoal_tac "abs xa < min (x / 2) (r * x^2 / 2)")
365 apply (simp add: power2_eq_square mult_compare_simps)
366 apply (rule mult_imp_div_pos_less)
367 apply (rule mult_pos_pos, assumption, assumption)
368 apply (subgoal_tac "xa * xa = abs xa * abs xa")
370 apply (subgoal_tac "abs xa * (abs xa * 2) < abs xa * (r * (x * x))")
371 apply (simp only: mult_ac)
372 apply (rule mult_strict_left_mono)
373 apply (erule conjE, assumption)
376 apply (subst ln_div [THEN sym])
378 apply (auto simp add: algebra_simps add_frac_eq frac_eq_eq
379 add_divide_distrib power2_eq_square)
380 apply (rule mult_pos_pos, assumption)+
384 lemma ln_x_over_x_mono: "exp 1 <= x ==> x <= y ==> (ln y / y) <= (ln x / x)"
386 assume "exp 1 <= x" and "x <= y"
387 have a: "0 < x" and b: "0 < y"
389 apply (subgoal_tac "0 < exp (1::real)")
392 apply (subgoal_tac "0 < exp (1::real)")
396 have "x * ln y - x * ln x = x * (ln y - ln x)"
397 by (simp add: algebra_simps)
398 also have "... = x * ln(y / x)"
400 apply (rule b, rule a, rule refl)
402 also have "y / x = (x + (y - x)) / x"
404 also have "... = 1 + (y - x) / x" using a prems by(simp add:field_simps)
405 also have "x * ln(1 + (y - x) / x) <= x * ((y - x) / x)"
406 apply (rule mult_left_mono)
407 apply (rule ln_add_one_self_le_self)
408 apply (rule divide_nonneg_pos)
409 apply (insert prems a, simp_all)
411 also have "... = y - x" using a by simp
412 also have "... = (y - x) * ln (exp 1)" by simp
413 also have "... <= (y - x) * ln x"
414 apply (rule mult_left_mono)
415 apply (subst ln_le_cancel_iff)
419 apply (insert prems, simp)
421 also have "... = y * ln x - x * ln x"
422 by (rule left_diff_distrib)
423 finally have "x * ln y <= y * ln x"
425 then have "ln y <= (y * ln x) / x" using a by(simp add:field_simps)
426 also have "... = y * (ln x / x)" by simp
427 finally show ?thesis using b by(simp add:field_simps)