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: numeral_2_eq_2)
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 (simp del: fact_Suc)
70 finally show ?thesis .
72 moreover have "x ^ (Suc n + 2) <= x ^ (n + 2)"
73 by (simp add: mult_left_le_one_le mult_nonneg_nonneg a b)
74 ultimately have "inverse (fact (Suc n + 2)) * x ^ (Suc n + 2) <=
75 (1 / 2 * inverse (fact (n + 2))) * x ^ (n + 2)"
76 apply (rule mult_mono)
77 apply (rule mult_nonneg_nonneg)
79 apply (subst inverse_nonnegative_iff_nonnegative)
80 apply (rule real_of_nat_ge_zero)
81 apply (rule zero_le_power)
84 also have "... = 1 / 2 * (inverse (fact (n + 2)) * x ^ (n + 2))"
86 also have "... <= 1 / 2 * (x ^ 2 / 2 * (1 / 2) ^ n)"
87 apply (rule mult_left_mono)
91 also have "... = x ^ 2 / 2 * (1 / 2 * (1 / 2) ^ n)"
93 also have "(1::real) / 2 * (1 / 2) ^ n = (1 / 2) ^ (Suc n)"
94 by (rule power_Suc [THEN sym])
95 finally show ?thesis .
99 lemma aux2: "(%n. (x::real) ^ 2 / 2 * (1 / 2) ^ n) sums x^2"
101 have "(%n. (1 / 2::real)^n) sums (1 / (1 - (1/2)))"
102 apply (rule geometric_sums)
103 by (simp add: abs_less_iff)
104 also have "(1::real) / (1 - 1/2) = 2"
106 finally have "(%n. (1 / 2::real)^n) sums 2" .
107 then have "(%n. x ^ 2 / 2 * (1 / 2) ^ n) sums (x^2 / 2 * 2)"
109 also have "x^2 / 2 * 2 = x^2"
111 finally show ?thesis .
114 lemma exp_bound: "0 <= (x::real) ==> x <= 1 ==> exp x <= 1 + x + x^2"
118 have c: "exp x = 1 + x + suminf (%n. inverse(fact (n+2)) *
120 by (rule exp_first_two_terms)
121 moreover have "suminf (%n. inverse(fact (n+2)) * (x ^ (n+2))) <= x^2"
123 have "suminf (%n. inverse(fact (n+2)) * (x ^ (n+2))) <=
124 suminf (%n. (x^2/2) * ((1/2)^n))"
125 apply (rule summable_le)
126 apply (auto simp only: aux1 a b)
127 apply (rule exp_tail_after_first_two_terms_summable)
128 by (rule sums_summable, rule aux2)
129 also have "... = x^2"
130 by (rule sums_unique [THEN sym], rule aux2)
131 finally show ?thesis .
133 ultimately show ?thesis
137 lemma aux4: "0 <= (x::real) ==> x <= 1 ==> exp (x - x^2) <= 1 + x"
139 assume a: "0 <= x" and b: "x <= 1"
140 have "exp (x - x^2) = exp x / exp (x^2)"
142 also have "... <= (1 + x + x^2) / exp (x ^2)"
143 apply (rule divide_right_mono)
144 apply (rule exp_bound)
145 apply (rule a, rule b)
148 also have "... <= (1 + x + x^2) / (1 + x^2)"
149 apply (rule divide_left_mono)
150 apply (auto simp add: exp_ge_add_one_self_aux)
151 apply (rule add_nonneg_nonneg)
153 apply (rule mult_pos_pos)
155 apply (rule add_pos_nonneg)
158 also from a have "... <= 1 + x"
159 by (simp add: field_simps add_strict_increasing zero_le_mult_iff)
160 finally show ?thesis .
163 lemma ln_one_plus_pos_lower_bound: "0 <= x ==> x <= 1 ==>
164 x - x^2 <= ln (1 + x)"
166 assume a: "0 <= x" and b: "x <= 1"
167 then have "exp (x - x^2) <= 1 + x"
169 also have "... = exp (ln (1 + x))"
171 from a have "0 < 1 + x" by auto
173 by (auto simp only: exp_ln_iff [THEN sym])
175 finally have "exp (x - x ^ 2) <= exp (ln (1 + x))" .
176 thus ?thesis by (auto simp only: exp_le_cancel_iff)
179 lemma ln_one_minus_pos_upper_bound: "0 <= x ==> x < 1 ==> ln (1 - x) <= - x"
181 assume a: "0 <= (x::real)" and b: "x < 1"
182 have "(1 - x) * (1 + x + x^2) = (1 - x^3)"
183 by (simp add: algebra_simps power2_eq_square power3_eq_cube)
185 by (auto simp add: a)
186 finally have "(1 - x) * (1 + x + x ^ 2) <= 1" .
187 moreover have "0 < 1 + x + x^2"
188 apply (rule add_pos_nonneg)
191 ultimately have "1 - x <= 1 / (1 + x + x^2)"
192 by (elim mult_imp_le_div_pos)
193 also have "... <= 1 / exp x"
194 apply (rule divide_left_mono)
195 apply (rule exp_bound, rule a)
197 apply (rule mult_pos_pos)
198 apply (rule add_pos_nonneg)
201 also have "... = exp (-x)"
202 by (auto simp add: exp_minus divide_inverse)
203 finally have "1 - x <= exp (- x)" .
204 also have "1 - x = exp (ln (1 - x))"
209 by (auto simp only: exp_ln_iff [THEN sym])
211 finally have "exp (ln (1 - x)) <= exp (- x)" .
212 thus ?thesis by (auto simp only: exp_le_cancel_iff)
215 lemma aux5: "x < 1 ==> ln(1 - x) = - ln(1 + x / (1 - x))"
218 have "ln(1 - x) = - ln(1 / (1 - x))"
220 have "ln(1 - x) = - (- ln (1 - x))"
222 also have "- ln(1 - x) = ln 1 - ln(1 - x)"
224 also have "... = ln(1 / (1 - x))"
225 apply (rule ln_div [THEN sym])
227 finally show ?thesis .
229 also have " 1 / (1 - x) = 1 + x / (1 - x)" using a by(simp add:field_simps)
230 finally show ?thesis .
233 lemma ln_one_minus_pos_lower_bound: "0 <= x ==> x <= (1 / 2) ==>
234 - x - 2 * x^2 <= ln (1 - x)"
236 assume a: "0 <= x" and b: "x <= (1 / 2)"
237 from b have c: "x < 1"
239 then have "ln (1 - x) = - ln (1 + x / (1 - x))"
241 also have "- (x / (1 - x)) <= ..."
243 have "ln (1 + x / (1 - x)) <= x / (1 - x)"
244 apply (rule ln_add_one_self_le_self)
245 apply (rule divide_nonneg_pos)
246 by (insert a c, auto)
250 also have "- (x / (1 - x)) = -x / (1 - x)"
252 finally have d: "- x / (1 - x) <= ln (1 - x)" .
253 have "0 < 1 - x" using a b by simp
254 hence e: "-x - 2 * x^2 <= - x / (1 - x)"
255 using mult_right_le_one_le[of "x*x" "2*x"] a b
256 by (simp add:field_simps power2_eq_square)
257 from e d show "- x - 2 * x^2 <= ln (1 - x)"
258 by (rule order_trans)
261 lemma exp_ge_add_one_self [simp]: "1 + (x::real) <= exp x"
262 apply (case_tac "0 <= x")
263 apply (erule exp_ge_add_one_self_aux)
264 apply (case_tac "x <= -1")
265 apply (subgoal_tac "1 + x <= 0")
266 apply (erule order_trans)
269 apply (subgoal_tac "1 + x = exp(ln (1 + x))")
271 apply (subst exp_le_cancel_iff)
272 apply (subgoal_tac "ln (1 - (- x)) <= - (- x)")
274 apply (rule ln_one_minus_pos_upper_bound)
278 lemma ln_add_one_self_le_self2: "-1 < x ==> ln(1 + x) <= x"
279 apply (subgoal_tac "x = ln (exp x)")
280 apply (erule ssubst)back
281 apply (subst ln_le_cancel_iff)
285 lemma abs_ln_one_plus_x_minus_x_bound_nonneg:
286 "0 <= x ==> x <= 1 ==> abs(ln (1 + x) - x) <= x^2"
290 from x have "ln (1 + x) <= x"
291 by (rule ln_add_one_self_le_self)
292 then have "ln (1 + x) - x <= 0"
294 then have "abs(ln(1 + x) - x) = - (ln(1 + x) - x)"
295 by (rule abs_of_nonpos)
296 also have "... = x - ln (1 + x)"
298 also have "... <= x^2"
300 from x x1 have "x - x^2 <= ln (1 + x)"
301 by (intro ln_one_plus_pos_lower_bound)
305 finally show ?thesis .
308 lemma abs_ln_one_plus_x_minus_x_bound_nonpos:
309 "-(1 / 2) <= x ==> x <= 0 ==> abs(ln (1 + x) - x) <= 2 * x^2"
311 assume a: "-(1 / 2) <= x"
313 have "abs(ln (1 + x) - x) = x - ln(1 - (-x))"
314 apply (subst abs_of_nonpos)
316 apply (rule ln_add_one_self_le_self2)
319 also have "... <= 2 * x^2"
320 apply (subgoal_tac "- (-x) - 2 * (-x)^2 <= ln (1 - (-x))")
321 apply (simp add: algebra_simps)
322 apply (rule ln_one_minus_pos_lower_bound)
325 finally show ?thesis .
328 lemma abs_ln_one_plus_x_minus_x_bound:
329 "abs x <= 1 / 2 ==> abs(ln (1 + x) - x) <= 2 * x^2"
330 apply (case_tac "0 <= x")
331 apply (rule order_trans)
332 apply (rule abs_ln_one_plus_x_minus_x_bound_nonneg)
334 apply (rule abs_ln_one_plus_x_minus_x_bound_nonpos)
338 lemma ln_x_over_x_mono: "exp 1 <= x ==> x <= y ==> (ln y / y) <= (ln x / x)"
340 assume x: "exp 1 <= x" "x <= y"
341 moreover have "0 < exp (1::real)" by simp
342 ultimately have a: "0 < x" and b: "0 < y"
343 by (fast intro: less_le_trans order_trans)+
344 have "x * ln y - x * ln x = x * (ln y - ln x)"
345 by (simp add: algebra_simps)
346 also have "... = x * ln(y / x)"
347 by (simp only: ln_div a b)
348 also have "y / x = (x + (y - x)) / x"
350 also have "... = 1 + (y - x) / x"
351 using x a by (simp add: field_simps)
352 also have "x * ln(1 + (y - x) / x) <= x * ((y - x) / x)"
353 apply (rule mult_left_mono)
354 apply (rule ln_add_one_self_le_self)
355 apply (rule divide_nonneg_pos)
356 using x a apply simp_all
358 also have "... = y - x" using a by simp
359 also have "... = (y - x) * ln (exp 1)" by simp
360 also have "... <= (y - x) * ln x"
361 apply (rule mult_left_mono)
362 apply (subst ln_le_cancel_iff)
368 also have "... = y * ln x - x * ln x"
369 by (rule left_diff_distrib)
370 finally have "x * ln y <= y * ln x"
372 then have "ln y <= (y * ln x) / x" using a by (simp add: field_simps)
373 also have "... = y * (ln x / x)" by simp
374 finally show ?thesis using b by (simp add: field_simps)
377 lemma ln_le_minus_one:
378 "0 < x \<Longrightarrow> ln x \<le> x - 1"
379 using exp_ge_add_one_self[of "ln x"] by simp
381 lemma ln_eq_minus_one:
382 assumes "0 < x" "ln x = x - 1" shows "x = 1"
384 let "?l y" = "ln y - y + 1"
385 have D: "\<And>x. 0 < x \<Longrightarrow> DERIV ?l x :> (1 / x - 1)"
386 by (auto intro!: DERIV_intros)
389 proof (cases rule: linorder_cases)
391 from dense[OF `x < 1`] obtain a where "x < a" "a < 1" by blast
392 from `x < a` have "?l x < ?l a"
393 proof (rule DERIV_pos_imp_increasing, safe)
394 fix y assume "x \<le> y" "y \<le> a"
395 with `0 < x` `a < 1` have "0 < 1 / y - 1" "0 < y"
396 by (auto simp: field_simps)
397 with D show "\<exists>z. DERIV ?l y :> z \<and> 0 < z"
400 also have "\<dots> \<le> 0"
401 using ln_le_minus_one `0 < x` `x < a` by (auto simp: field_simps)
402 finally show "x = 1" using assms by auto
405 from dense[OF `1 < x`] obtain a where "1 < a" "a < x" by blast
406 from `a < x` have "?l x < ?l a"
407 proof (rule DERIV_neg_imp_decreasing, safe)
408 fix y assume "a \<le> y" "y \<le> x"
409 with `1 < a` have "1 / y - 1 < 0" "0 < y"
410 by (auto simp: field_simps)
411 with D show "\<exists>z. DERIV ?l y :> z \<and> z < 0"
414 also have "\<dots> \<le> 0"
415 using ln_le_minus_one `1 < a` by (auto simp: field_simps)
416 finally show "x = 1" using assms by auto