src/HOL/Ln.thy
changeset 40864 4abaaadfdaf2
parent 36777 be5461582d0f
child 41550 efa734d9b221
equal deleted inserted replaced
40854:f2c9ebbe04aa 40864:4abaaadfdaf2
     7 theory Ln
     7 theory Ln
     8 imports Transcendental
     8 imports Transcendental
     9 begin
     9 begin
    10 
    10 
    11 lemma exp_first_two_terms: "exp x = 1 + x + suminf (%n. 
    11 lemma exp_first_two_terms: "exp x = 1 + x + suminf (%n. 
    12   inverse(real (fact (n+2))) * (x ^ (n+2)))"
    12   inverse(fact (n+2)) * (x ^ (n+2)))"
    13 proof -
    13 proof -
    14   have "exp x = suminf (%n. inverse(real (fact n)) * (x ^ n))"
    14   have "exp x = suminf (%n. inverse(fact n) * (x ^ n))"
    15     by (simp add: exp_def)
    15     by (simp add: exp_def)
    16   also from summable_exp have "... = (SUM n : {0..<2}. 
    16   also from summable_exp have "... = (SUM n::nat : {0..<2}. 
    17       inverse(real (fact n)) * (x ^ n)) + suminf (%n.
    17       inverse(fact n) * (x ^ n)) + suminf (%n.
    18       inverse(real (fact (n+2))) * (x ^ (n+2)))" (is "_ = ?a + _")
    18       inverse(fact(n+2)) * (x ^ (n+2)))" (is "_ = ?a + _")
    19     by (rule suminf_split_initial_segment)
    19     by (rule suminf_split_initial_segment)
    20   also have "?a = 1 + x"
    20   also have "?a = 1 + x"
    21     by (simp add: numerals)
    21     by (simp add: numerals)
    22   finally show ?thesis .
    22   finally show ?thesis .
    23 qed
    23 qed
    24 
    24 
    25 lemma exp_tail_after_first_two_terms_summable: 
    25 lemma exp_tail_after_first_two_terms_summable: 
    26   "summable (%n. inverse(real (fact (n+2))) * (x ^ (n+2)))"
    26   "summable (%n. inverse(fact (n+2)) * (x ^ (n+2)))"
    27 proof -
    27 proof -
    28   note summable_exp
    28   note summable_exp
    29   thus ?thesis
    29   thus ?thesis
    30     by (frule summable_ignore_initial_segment)
    30     by (frule summable_ignore_initial_segment)
    31 qed
    31 qed
    32 
    32 
    33 lemma aux1: assumes a: "0 <= x" and b: "x <= 1"
    33 lemma aux1: assumes a: "0 <= x" and b: "x <= 1"
    34     shows "inverse (real (fact ((n::nat) + 2))) * x ^ (n + 2) <= (x^2/2) * ((1/2)^n)"
    34     shows "inverse (fact ((n::nat) + 2)) * x ^ (n + 2) <= (x^2/2) * ((1/2)^n)"
    35 proof (induct n)
    35 proof (induct n)
    36   show "inverse (real (fact ((0::nat) + 2))) * x ^ (0 + 2) <= 
    36   show "inverse (fact ((0::nat) + 2)) * x ^ (0 + 2) <= 
    37       x ^ 2 / 2 * (1 / 2) ^ 0"
    37       x ^ 2 / 2 * (1 / 2) ^ 0"
    38     by (simp add: real_of_nat_Suc power2_eq_square)
    38     by (simp add: real_of_nat_Suc power2_eq_square)
    39 next
    39 next
    40   fix n :: nat
    40   fix n :: nat
    41   assume c: "inverse (real (fact (n + 2))) * x ^ (n + 2)
    41   assume c: "inverse (fact (n + 2)) * x ^ (n + 2)
    42        <= x ^ 2 / 2 * (1 / 2) ^ n"
    42        <= x ^ 2 / 2 * (1 / 2) ^ n"
    43   show "inverse (real (fact (Suc n + 2))) * x ^ (Suc n + 2)
    43   show "inverse (fact (Suc n + 2)) * x ^ (Suc n + 2)
    44            <= x ^ 2 / 2 * (1 / 2) ^ Suc n"
    44            <= x ^ 2 / 2 * (1 / 2) ^ Suc n"
    45   proof -
    45   proof -
    46     have "inverse(real (fact (Suc n + 2))) <= 
    46     have "inverse(fact (Suc n + 2)) <= (1/2) * inverse (fact (n+2))"
    47         (1 / 2) *inverse (real (fact (n+2)))"
       
    48     proof -
    47     proof -
    49       have "Suc n + 2 = Suc (n + 2)" by simp
    48       have "Suc n + 2 = Suc (n + 2)" by simp
    50       then have "fact (Suc n + 2) = Suc (n + 2) * fact (n + 2)" 
    49       then have "fact (Suc n + 2) = Suc (n + 2) * fact (n + 2)" 
    51         by simp
    50         by simp
    52       then have "real(fact (Suc n + 2)) = real(Suc (n + 2) * fact (n + 2))" 
    51       then have "real(fact (Suc n + 2)) = real(Suc (n + 2) * fact (n + 2))" 
    55         done
    54         done
    56       also have "... = real(Suc (n + 2)) * real(fact (n + 2))"
    55       also have "... = real(Suc (n + 2)) * real(fact (n + 2))"
    57         by (rule real_of_nat_mult)
    56         by (rule real_of_nat_mult)
    58       finally have "real (fact (Suc n + 2)) = 
    57       finally have "real (fact (Suc n + 2)) = 
    59          real (Suc (n + 2)) * real (fact (n + 2))" .
    58          real (Suc (n + 2)) * real (fact (n + 2))" .
    60       then have "inverse(real (fact (Suc n + 2))) = 
    59       then have "inverse(fact (Suc n + 2)) = 
    61          inverse(real (Suc (n + 2))) * inverse(real (fact (n + 2)))"
    60          inverse(Suc (n + 2)) * inverse(fact (n + 2))"
    62         apply (rule ssubst)
    61         apply (rule ssubst)
    63         apply (rule inverse_mult_distrib)
    62         apply (rule inverse_mult_distrib)
    64         done
    63         done
    65       also have "... <= (1/2) * inverse(real (fact (n + 2)))"
    64       also have "... <= (1/2) * inverse(fact (n + 2))"
    66         apply (rule mult_right_mono)
    65         apply (rule mult_right_mono)
    67         apply (subst inverse_eq_divide)
    66         apply (subst inverse_eq_divide)
    68         apply simp
    67         apply simp
    69         apply (rule inv_real_of_nat_fact_ge_zero)
    68         apply (rule inv_real_of_nat_fact_ge_zero)
    70         done
    69         done
    76       apply (subgoal_tac "0 <= x * (x * x^n)")
    75       apply (subgoal_tac "0 <= x * (x * x^n)")
    77       apply force
    76       apply force
    78       apply (rule mult_nonneg_nonneg, rule a)+
    77       apply (rule mult_nonneg_nonneg, rule a)+
    79       apply (rule zero_le_power, rule a)
    78       apply (rule zero_le_power, rule a)
    80       done
    79       done
    81     ultimately have "inverse (real (fact (Suc n + 2))) *  x ^ (Suc n + 2) <=
    80     ultimately have "inverse (fact (Suc n + 2)) *  x ^ (Suc n + 2) <=
    82         (1 / 2 * inverse (real (fact (n + 2)))) * x ^ (n + 2)"
    81         (1 / 2 * inverse (fact (n + 2))) * x ^ (n + 2)"
    83       apply (rule mult_mono)
    82       apply (rule mult_mono)
    84       apply (rule mult_nonneg_nonneg)
    83       apply (rule mult_nonneg_nonneg)
    85       apply simp
    84       apply simp
    86       apply (subst inverse_nonnegative_iff_nonnegative)
    85       apply (subst inverse_nonnegative_iff_nonnegative)
    87       apply (rule real_of_nat_ge_zero)
    86       apply (rule real_of_nat_ge_zero)
    88       apply (rule zero_le_power)
    87       apply (rule zero_le_power)
    89       apply (rule a)
    88       apply (rule a)
    90       done
    89       done
    91     also have "... = 1 / 2 * (inverse (real (fact (n + 2))) * x ^ (n + 2))"
    90     also have "... = 1 / 2 * (inverse (fact (n + 2)) * x ^ (n + 2))"
    92       by simp
    91       by simp
    93     also have "... <= 1 / 2 * (x ^ 2 / 2 * (1 / 2) ^ n)"
    92     also have "... <= 1 / 2 * (x ^ 2 / 2 * (1 / 2) ^ n)"
    94       apply (rule mult_left_mono)
    93       apply (rule mult_left_mono)
    95       apply (rule prems)
    94       apply (rule prems)
    96       apply simp
    95       apply simp
   120 
   119 
   121 lemma exp_bound: "0 <= (x::real) ==> x <= 1 ==> exp x <= 1 + x + x^2"
   120 lemma exp_bound: "0 <= (x::real) ==> x <= 1 ==> exp x <= 1 + x + x^2"
   122 proof -
   121 proof -
   123   assume a: "0 <= x"
   122   assume a: "0 <= x"
   124   assume b: "x <= 1"
   123   assume b: "x <= 1"
   125   have c: "exp x = 1 + x + suminf (%n. inverse(real (fact (n+2))) * 
   124   have c: "exp x = 1 + x + suminf (%n. inverse(fact (n+2)) * 
   126       (x ^ (n+2)))"
   125       (x ^ (n+2)))"
   127     by (rule exp_first_two_terms)
   126     by (rule exp_first_two_terms)
   128   moreover have "suminf (%n. inverse(real (fact (n+2))) * (x ^ (n+2))) <= x^2"
   127   moreover have "suminf (%n. inverse(fact (n+2)) * (x ^ (n+2))) <= x^2"
   129   proof -
   128   proof -
   130     have "suminf (%n. inverse(real (fact (n+2))) * (x ^ (n+2))) <=
   129     have "suminf (%n. inverse(fact (n+2)) * (x ^ (n+2))) <=
   131         suminf (%n. (x^2/2) * ((1/2)^n))"
   130         suminf (%n. (x^2/2) * ((1/2)^n))"
   132       apply (rule summable_le)
   131       apply (rule summable_le)
   133       apply (auto simp only: aux1 prems)
   132       apply (auto simp only: aux1 prems)
   134       apply (rule exp_tail_after_first_two_terms_summable)
   133       apply (rule exp_tail_after_first_two_terms_summable)
   135       by (rule sums_summable, rule aux2)  
   134       by (rule sums_summable, rule aux2)