src/HOL/Ln.thy
author huffman
Fri, 19 Aug 2011 07:45:22 -0700
changeset 45165 3bdc02eb1637
parent 45160 d81d09cdab9c
child 48113 1caeecc72aea
permissions -rw-r--r--
remove some redundant simp rules
     1 (*  Title:      HOL/Ln.thy
     2     Author:     Jeremy Avigad
     3 *)
     4 
     5 header {* Properties of ln *}
     6 
     7 theory Ln
     8 imports Transcendental
     9 begin
    10 
    11 lemma exp_first_two_terms: "exp x = 1 + x + suminf (%n. 
    12   inverse(fact (n+2)) * (x ^ (n+2)))"
    13 proof -
    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 .
    23 qed
    24 
    25 lemma exp_tail_after_first_two_terms_summable: 
    26   "summable (%n. inverse(fact (n+2)) * (x ^ (n+2)))"
    27 proof -
    28   note summable_exp
    29   thus ?thesis
    30     by (frule summable_ignore_initial_segment)
    31 qed
    32 
    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)"
    35 proof (induct 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)
    39 next
    40   fix n :: nat
    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"
    45   proof -
    46     have "inverse(fact (Suc n + 2)) <= (1/2) * inverse (fact (n+2))"
    47     proof -
    48       have "Suc n + 2 = Suc (n + 2)" by simp
    49       then have "fact (Suc n + 2) = Suc (n + 2) * fact (n + 2)" 
    50         by simp
    51       then have "real(fact (Suc n + 2)) = real(Suc (n + 2) * fact (n + 2))" 
    52         apply (rule subst)
    53         apply (rule refl)
    54         done
    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))"
    61         apply (rule ssubst)
    62         apply (rule inverse_mult_distrib)
    63         done
    64       also have "... <= (1/2) * inverse(fact (n + 2))"
    65         apply (rule mult_right_mono)
    66         apply (subst inverse_eq_divide)
    67         apply simp
    68         apply (simp del: fact_Suc)
    69         done
    70       finally show ?thesis .
    71     qed
    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)
    78       apply simp
    79       apply (subst inverse_nonnegative_iff_nonnegative)
    80       apply (rule real_of_nat_ge_zero)
    81       apply (rule zero_le_power)
    82       apply (rule a)
    83       done
    84     also have "... = 1 / 2 * (inverse (fact (n + 2)) * x ^ (n + 2))"
    85       by simp
    86     also have "... <= 1 / 2 * (x ^ 2 / 2 * (1 / 2) ^ n)"
    87       apply (rule mult_left_mono)
    88       apply (rule c)
    89       apply simp
    90       done
    91     also have "... = x ^ 2 / 2 * (1 / 2 * (1 / 2) ^ n)"
    92       by auto
    93     also have "(1::real) / 2 * (1 / 2) ^ n = (1 / 2) ^ (Suc n)"
    94       by (rule power_Suc [THEN sym])
    95     finally show ?thesis .
    96   qed
    97 qed
    98 
    99 lemma aux2: "(%n. (x::real) ^ 2 / 2 * (1 / 2) ^ n) sums x^2"
   100 proof -
   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"
   105     by simp
   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)"
   108     by (rule sums_mult)
   109   also have "x^2 / 2 * 2 = x^2"
   110     by simp
   111   finally show ?thesis .
   112 qed
   113 
   114 lemma exp_bound: "0 <= (x::real) ==> x <= 1 ==> exp x <= 1 + x + x^2"
   115 proof -
   116   assume a: "0 <= x"
   117   assume b: "x <= 1"
   118   have c: "exp x = 1 + x + suminf (%n. inverse(fact (n+2)) * 
   119       (x ^ (n+2)))"
   120     by (rule exp_first_two_terms)
   121   moreover have "suminf (%n. inverse(fact (n+2)) * (x ^ (n+2))) <= x^2"
   122   proof -
   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 .
   132   qed
   133   ultimately show ?thesis
   134     by auto
   135 qed
   136 
   137 lemma aux4: "0 <= (x::real) ==> x <= 1 ==> exp (x - x^2) <= 1 + x" 
   138 proof -
   139   assume a: "0 <= x" and b: "x <= 1"
   140   have "exp (x - x^2) = exp x / exp (x^2)"
   141     by (rule exp_diff)
   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)
   146     apply simp
   147     done
   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)
   152     using a apply auto
   153     apply (rule mult_pos_pos)
   154     apply auto
   155     apply (rule add_pos_nonneg)
   156     apply auto
   157     done
   158   also from a have "... <= 1 + x"
   159     by (simp add: field_simps add_strict_increasing zero_le_mult_iff)
   160   finally show ?thesis .
   161 qed
   162 
   163 lemma ln_one_plus_pos_lower_bound: "0 <= x ==> x <= 1 ==> 
   164     x - x^2 <= ln (1 + x)"
   165 proof -
   166   assume a: "0 <= x" and b: "x <= 1"
   167   then have "exp (x - x^2) <= 1 + x"
   168     by (rule aux4)
   169   also have "... = exp (ln (1 + x))"
   170   proof -
   171     from a have "0 < 1 + x" by auto
   172     thus ?thesis
   173       by (auto simp only: exp_ln_iff [THEN sym])
   174   qed
   175   finally have "exp (x - x ^ 2) <= exp (ln (1 + x))" .
   176   thus ?thesis by (auto simp only: exp_le_cancel_iff)
   177 qed
   178 
   179 lemma ln_one_minus_pos_upper_bound: "0 <= x ==> x < 1 ==> ln (1 - x) <= - x"
   180 proof -
   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)
   184   also have "... <= 1"
   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)
   189     using a apply auto
   190     done
   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)
   196     using a b apply auto
   197     apply (rule mult_pos_pos)
   198     apply (rule add_pos_nonneg)
   199     apply auto
   200     done
   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))"
   205   proof -
   206     have "0 < 1 - x"
   207       by (insert b, auto)
   208     thus ?thesis
   209       by (auto simp only: exp_ln_iff [THEN sym])
   210   qed
   211   finally have "exp (ln (1 - x)) <= exp (- x)" .
   212   thus ?thesis by (auto simp only: exp_le_cancel_iff)
   213 qed
   214 
   215 lemma aux5: "x < 1 ==> ln(1 - x) = - ln(1 + x / (1 - x))"
   216 proof -
   217   assume a: "x < 1"
   218   have "ln(1 - x) = - ln(1 / (1 - x))"
   219   proof -
   220     have "ln(1 - x) = - (- ln (1 - x))"
   221       by auto
   222     also have "- ln(1 - x) = ln 1 - ln(1 - x)"
   223       by simp
   224     also have "... = ln(1 / (1 - x))"
   225       apply (rule ln_div [THEN sym])
   226       by (insert a, auto)
   227     finally show ?thesis .
   228   qed
   229   also have " 1 / (1 - x) = 1 + x / (1 - x)" using a by(simp add:field_simps)
   230   finally show ?thesis .
   231 qed
   232 
   233 lemma ln_one_minus_pos_lower_bound: "0 <= x ==> x <= (1 / 2) ==> 
   234     - x - 2 * x^2 <= ln (1 - x)"
   235 proof -
   236   assume a: "0 <= x" and b: "x <= (1 / 2)"
   237   from b have c: "x < 1"
   238     by auto
   239   then have "ln (1 - x) = - ln (1 + x / (1 - x))"
   240     by (rule aux5)
   241   also have "- (x / (1 - x)) <= ..."
   242   proof - 
   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) 
   247     thus ?thesis
   248       by auto
   249   qed
   250   also have "- (x / (1 - x)) = -x / (1 - x)"
   251     by auto
   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)
   259 qed
   260 
   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)
   267   apply simp
   268   apply simp
   269   apply (subgoal_tac "1 + x = exp(ln (1 + x))")
   270   apply (erule ssubst)
   271   apply (subst exp_le_cancel_iff)
   272   apply (subgoal_tac "ln (1 - (- x)) <= - (- x)")
   273   apply simp
   274   apply (rule ln_one_minus_pos_upper_bound) 
   275   apply auto
   276 done
   277 
   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)
   282   apply auto
   283 done
   284 
   285 lemma abs_ln_one_plus_x_minus_x_bound_nonneg:
   286     "0 <= x ==> x <= 1 ==> abs(ln (1 + x) - x) <= x^2"
   287 proof -
   288   assume x: "0 <= x"
   289   assume x1: "x <= 1"
   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" 
   293     by simp
   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)" 
   297     by simp
   298   also have "... <= x^2"
   299   proof -
   300     from x x1 have "x - x^2 <= ln (1 + x)"
   301       by (intro ln_one_plus_pos_lower_bound)
   302     thus ?thesis
   303       by simp
   304   qed
   305   finally show ?thesis .
   306 qed
   307 
   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"
   310 proof -
   311   assume a: "-(1 / 2) <= x"
   312   assume b: "x <= 0"
   313   have "abs(ln (1 + x) - x) = x - ln(1 - (-x))" 
   314     apply (subst abs_of_nonpos)
   315     apply simp
   316     apply (rule ln_add_one_self_le_self2)
   317     using a apply auto
   318     done
   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)
   323     using a b apply auto
   324     done
   325   finally show ?thesis .
   326 qed
   327 
   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)
   333   apply auto
   334   apply (rule abs_ln_one_plus_x_minus_x_bound_nonpos)
   335   apply auto
   336 done
   337 
   338 lemma ln_x_over_x_mono: "exp 1 <= x ==> x <= y ==> (ln y / y) <= (ln x / x)"  
   339 proof -
   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"
   349     by simp
   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
   357     done
   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)
   363     apply fact
   364     apply (rule a)
   365     apply (rule x)
   366     using x apply simp
   367     done
   368   also have "... = y * ln x - x * ln x"
   369     by (rule left_diff_distrib)
   370   finally have "x * ln y <= y * ln x"
   371     by arith
   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)
   375 qed
   376 
   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
   380 
   381 lemma ln_eq_minus_one:
   382   assumes "0 < x" "ln x = x - 1" shows "x = 1"
   383 proof -
   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)
   387 
   388   show ?thesis
   389   proof (cases rule: linorder_cases)
   390     assume "x < 1"
   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"
   398         by auto
   399     qed
   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
   403   next
   404     assume "1 < x"
   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"
   412         by blast
   413     qed
   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
   417   qed simp
   418 qed
   419 
   420 end