src/HOL/Transcendental.thy
author wenzelm
Sun Aug 18 18:49:45 2013 +0200 (2013-08-18)
changeset 53076 47c9aff07725
parent 53015 a1119cf551e8
child 53079 ade63ccd6f4e
permissions -rw-r--r--
more symbols;
wenzelm@32960
     1
(*  Title:      HOL/Transcendental.thy
wenzelm@32960
     2
    Author:     Jacques D. Fleuriot, University of Cambridge, University of Edinburgh
wenzelm@32960
     3
    Author:     Lawrence C Paulson
hoelzl@51527
     4
    Author:     Jeremy Avigad
hoelzl@51527
     5
paulson@12196
     6
*)
paulson@12196
     7
paulson@15077
     8
header{*Power Series, Transcendental Functions etc.*}
paulson@15077
     9
nipkow@15131
    10
theory Transcendental
haftmann@25600
    11
imports Fact Series Deriv NthRoot
nipkow@15131
    12
begin
paulson@15077
    13
huffman@29164
    14
subsection {* Properties of Power Series *}
paulson@15077
    15
huffman@23082
    16
lemma lemma_realpow_diff:
haftmann@31017
    17
  fixes y :: "'a::monoid_mult"
huffman@23082
    18
  shows "p \<le> n \<Longrightarrow> y ^ (Suc n - p) = (y ^ (n - p)) * y"
huffman@23082
    19
proof -
huffman@23082
    20
  assume "p \<le> n"
huffman@23082
    21
  hence "Suc n - p = Suc (n - p)" by (rule Suc_diff_le)
huffman@30273
    22
  thus ?thesis by (simp add: power_commutes)
huffman@23082
    23
qed
paulson@15077
    24
paulson@15077
    25
lemma lemma_realpow_diff_sumr:
haftmann@31017
    26
  fixes y :: "'a::{comm_semiring_0,monoid_mult}" shows
hoelzl@41970
    27
     "(\<Sum>p=0..<Suc n. (x ^ p) * y ^ (Suc n - p)) =
huffman@23082
    28
      y * (\<Sum>p=0..<Suc n. (x ^ p) * y ^ (n - p))"
huffman@29163
    29
by (simp add: setsum_right_distrib lemma_realpow_diff mult_ac
wenzelm@33549
    30
         del: setsum_op_ivl_Suc)
paulson@15077
    31
paulson@15229
    32
lemma lemma_realpow_diff_sumr2:
haftmann@31017
    33
  fixes y :: "'a::{comm_ring,monoid_mult}" shows
hoelzl@41970
    34
     "x ^ (Suc n) - y ^ (Suc n) =
huffman@23082
    35
      (x - y) * (\<Sum>p=0..<Suc n. (x ^ p) * y ^ (n - p))"
huffman@30273
    36
apply (induct n, simp)
huffman@30273
    37
apply (simp del: setsum_op_ivl_Suc)
nipkow@15561
    38
apply (subst setsum_op_ivl_Suc)
huffman@23082
    39
apply (subst lemma_realpow_diff_sumr)
webertj@49962
    40
apply (simp add: distrib_left del: setsum_op_ivl_Suc)
haftmann@34974
    41
apply (subst mult_left_commute [of "x - y"])
huffman@23082
    42
apply (erule subst)
huffman@30273
    43
apply (simp add: algebra_simps)
paulson@15077
    44
done
paulson@15077
    45
paulson@15229
    46
lemma lemma_realpow_rev_sumr:
hoelzl@41970
    47
     "(\<Sum>p=0..<Suc n. (x ^ p) * (y ^ (n - p))) =
huffman@23082
    48
      (\<Sum>p=0..<Suc n. (x ^ (n - p)) * (y ^ p))"
huffman@23082
    49
apply (rule setsum_reindex_cong [where f="\<lambda>i. n - i"])
huffman@23082
    50
apply (rule inj_onI, simp)
huffman@23082
    51
apply auto
huffman@23082
    52
apply (rule_tac x="n - x" in image_eqI, simp, simp)
paulson@15077
    53
done
paulson@15077
    54
paulson@15077
    55
text{*Power series has a `circle` of convergence, i.e. if it sums for @{term
paulson@15077
    56
x}, then it sums absolutely for @{term z} with @{term "\<bar>z\<bar> < \<bar>x\<bar>"}.*}
paulson@15077
    57
paulson@15077
    58
lemma powser_insidea:
huffman@44726
    59
  fixes x z :: "'a::real_normed_field"
huffman@20849
    60
  assumes 1: "summable (\<lambda>n. f n * x ^ n)"
huffman@23082
    61
  assumes 2: "norm z < norm x"
huffman@23082
    62
  shows "summable (\<lambda>n. norm (f n * z ^ n))"
huffman@20849
    63
proof -
huffman@20849
    64
  from 2 have x_neq_0: "x \<noteq> 0" by clarsimp
huffman@20849
    65
  from 1 have "(\<lambda>n. f n * x ^ n) ----> 0"
huffman@20849
    66
    by (rule summable_LIMSEQ_zero)
huffman@20849
    67
  hence "convergent (\<lambda>n. f n * x ^ n)"
huffman@20849
    68
    by (rule convergentI)
huffman@20849
    69
  hence "Cauchy (\<lambda>n. f n * x ^ n)"
huffman@44726
    70
    by (rule convergent_Cauchy)
huffman@20849
    71
  hence "Bseq (\<lambda>n. f n * x ^ n)"
huffman@20849
    72
    by (rule Cauchy_Bseq)
huffman@23082
    73
  then obtain K where 3: "0 < K" and 4: "\<forall>n. norm (f n * x ^ n) \<le> K"
huffman@20849
    74
    by (simp add: Bseq_def, safe)
huffman@23082
    75
  have "\<exists>N. \<forall>n\<ge>N. norm (norm (f n * z ^ n)) \<le>
huffman@23082
    76
                   K * norm (z ^ n) * inverse (norm (x ^ n))"
huffman@20849
    77
  proof (intro exI allI impI)
huffman@20849
    78
    fix n::nat assume "0 \<le> n"
huffman@23082
    79
    have "norm (norm (f n * z ^ n)) * norm (x ^ n) =
huffman@23082
    80
          norm (f n * x ^ n) * norm (z ^ n)"
huffman@23082
    81
      by (simp add: norm_mult abs_mult)
huffman@23082
    82
    also have "\<dots> \<le> K * norm (z ^ n)"
huffman@23082
    83
      by (simp only: mult_right_mono 4 norm_ge_zero)
huffman@23082
    84
    also have "\<dots> = K * norm (z ^ n) * (inverse (norm (x ^ n)) * norm (x ^ n))"
huffman@20849
    85
      by (simp add: x_neq_0)
huffman@23082
    86
    also have "\<dots> = K * norm (z ^ n) * inverse (norm (x ^ n)) * norm (x ^ n)"
huffman@20849
    87
      by (simp only: mult_assoc)
huffman@23082
    88
    finally show "norm (norm (f n * z ^ n)) \<le>
huffman@23082
    89
                  K * norm (z ^ n) * inverse (norm (x ^ n))"
huffman@20849
    90
      by (simp add: mult_le_cancel_right x_neq_0)
huffman@20849
    91
  qed
huffman@23082
    92
  moreover have "summable (\<lambda>n. K * norm (z ^ n) * inverse (norm (x ^ n)))"
huffman@20849
    93
  proof -
huffman@23082
    94
    from 2 have "norm (norm (z * inverse x)) < 1"
huffman@23082
    95
      using x_neq_0
huffman@23082
    96
      by (simp add: nonzero_norm_divide divide_inverse [symmetric])
huffman@23082
    97
    hence "summable (\<lambda>n. norm (z * inverse x) ^ n)"
huffman@20849
    98
      by (rule summable_geometric)
huffman@23082
    99
    hence "summable (\<lambda>n. K * norm (z * inverse x) ^ n)"
huffman@20849
   100
      by (rule summable_mult)
huffman@23082
   101
    thus "summable (\<lambda>n. K * norm (z ^ n) * inverse (norm (x ^ n)))"
huffman@23082
   102
      using x_neq_0
huffman@23082
   103
      by (simp add: norm_mult nonzero_norm_inverse power_mult_distrib
huffman@23082
   104
                    power_inverse norm_power mult_assoc)
huffman@20849
   105
  qed
huffman@23082
   106
  ultimately show "summable (\<lambda>n. norm (f n * z ^ n))"
huffman@20849
   107
    by (rule summable_comparison_test)
huffman@20849
   108
qed
paulson@15077
   109
paulson@15229
   110
lemma powser_inside:
haftmann@31017
   111
  fixes f :: "nat \<Rightarrow> 'a::{real_normed_field,banach}" shows
hoelzl@41970
   112
     "[| summable (%n. f(n) * (x ^ n)); norm z < norm x |]
paulson@15077
   113
      ==> summable (%n. f(n) * (z ^ n))"
huffman@23082
   114
by (rule powser_insidea [THEN summable_norm_cancel])
paulson@15077
   115
hoelzl@29803
   116
lemma sum_split_even_odd: fixes f :: "nat \<Rightarrow> real" shows
hoelzl@41970
   117
  "(\<Sum> i = 0 ..< 2 * n. if even i then f i else g i) =
hoelzl@29803
   118
   (\<Sum> i = 0 ..< n. f (2 * i)) + (\<Sum> i = 0 ..< n. g (2 * i + 1))"
hoelzl@29803
   119
proof (induct n)
hoelzl@29803
   120
  case (Suc n)
hoelzl@41970
   121
  have "(\<Sum> i = 0 ..< 2 * Suc n. if even i then f i else g i) =
hoelzl@29803
   122
        (\<Sum> i = 0 ..< n. f (2 * i)) + (\<Sum> i = 0 ..< n. g (2 * i + 1)) + (f (2 * n) + g (2 * n + 1))"
huffman@30082
   123
    using Suc.hyps unfolding One_nat_def by auto
hoelzl@29803
   124
  also have "\<dots> = (\<Sum> i = 0 ..< Suc n. f (2 * i)) + (\<Sum> i = 0 ..< Suc n. g (2 * i + 1))" by auto
hoelzl@29803
   125
  finally show ?case .
hoelzl@29803
   126
qed auto
hoelzl@29803
   127
hoelzl@29803
   128
lemma sums_if': fixes g :: "nat \<Rightarrow> real" assumes "g sums x"
hoelzl@29803
   129
  shows "(\<lambda> n. if even n then 0 else g ((n - 1) div 2)) sums x"
hoelzl@29803
   130
  unfolding sums_def
hoelzl@29803
   131
proof (rule LIMSEQ_I)
hoelzl@29803
   132
  fix r :: real assume "0 < r"
hoelzl@29803
   133
  from `g sums x`[unfolded sums_def, THEN LIMSEQ_D, OF this]
hoelzl@29803
   134
  obtain no where no_eq: "\<And> n. n \<ge> no \<Longrightarrow> (norm (setsum g { 0..<n } - x) < r)" by blast
hoelzl@29803
   135
hoelzl@29803
   136
  let ?SUM = "\<lambda> m. \<Sum> i = 0 ..< m. if even i then 0 else g ((i - 1) div 2)"
hoelzl@29803
   137
  { fix m assume "m \<ge> 2 * no" hence "m div 2 \<ge> no" by auto
hoelzl@41970
   138
    have sum_eq: "?SUM (2 * (m div 2)) = setsum g { 0 ..< m div 2 }"
hoelzl@29803
   139
      using sum_split_even_odd by auto
hoelzl@29803
   140
    hence "(norm (?SUM (2 * (m div 2)) - x) < r)" using no_eq unfolding sum_eq using `m div 2 \<ge> no` by auto
hoelzl@29803
   141
    moreover
hoelzl@29803
   142
    have "?SUM (2 * (m div 2)) = ?SUM m"
hoelzl@29803
   143
    proof (cases "even m")
hoelzl@29803
   144
      case True show ?thesis unfolding even_nat_div_two_times_two[OF True, unfolded numeral_2_eq_2[symmetric]] ..
hoelzl@29803
   145
    next
hoelzl@29803
   146
      case False hence "even (Suc m)" by auto
hoelzl@29803
   147
      from even_nat_div_two_times_two[OF this, unfolded numeral_2_eq_2[symmetric]] odd_nat_plus_one_div_two[OF False, unfolded numeral_2_eq_2[symmetric]]
hoelzl@29803
   148
      have eq: "Suc (2 * (m div 2)) = m" by auto
hoelzl@29803
   149
      hence "even (2 * (m div 2))" using `odd m` by auto
hoelzl@29803
   150
      have "?SUM m = ?SUM (Suc (2 * (m div 2)))" unfolding eq ..
hoelzl@29803
   151
      also have "\<dots> = ?SUM (2 * (m div 2))" using `even (2 * (m div 2))` by auto
hoelzl@29803
   152
      finally show ?thesis by auto
hoelzl@29803
   153
    qed
hoelzl@29803
   154
    ultimately have "(norm (?SUM m - x) < r)" by auto
hoelzl@29803
   155
  }
hoelzl@29803
   156
  thus "\<exists> no. \<forall> m \<ge> no. norm (?SUM m - x) < r" by blast
hoelzl@29803
   157
qed
hoelzl@29803
   158
hoelzl@29803
   159
lemma sums_if: fixes g :: "nat \<Rightarrow> real" assumes "g sums x" and "f sums y"
hoelzl@29803
   160
  shows "(\<lambda> n. if even n then f (n div 2) else g ((n - 1) div 2)) sums (x + y)"
hoelzl@29803
   161
proof -
hoelzl@29803
   162
  let ?s = "\<lambda> n. if even n then 0 else f ((n - 1) div 2)"
hoelzl@29803
   163
  { fix B T E have "(if B then (0 :: real) else E) + (if B then T else 0) = (if B then T else E)"
hoelzl@29803
   164
      by (cases B) auto } note if_sum = this
hoelzl@29803
   165
  have g_sums: "(\<lambda> n. if even n then 0 else g ((n - 1) div 2)) sums x" using sums_if'[OF `g sums x`] .
hoelzl@41970
   166
  {
hoelzl@29803
   167
    have "?s 0 = 0" by auto
hoelzl@29803
   168
    have Suc_m1: "\<And> n. Suc n - 1 = n" by auto
wenzelm@41550
   169
    have if_eq: "\<And>B T E. (if \<not> B then T else E) = (if B then E else T)" by auto
hoelzl@29803
   170
hoelzl@29803
   171
    have "?s sums y" using sums_if'[OF `f sums y`] .
hoelzl@41970
   172
    from this[unfolded sums_def, THEN LIMSEQ_Suc]
hoelzl@29803
   173
    have "(\<lambda> n. if even n then f (n div 2) else 0) sums y"
hoelzl@29803
   174
      unfolding sums_def setsum_shift_lb_Suc0_0_upt[where f="?s", OF `?s 0 = 0`, symmetric]
hoelzl@29803
   175
                image_Suc_atLeastLessThan[symmetric] setsum_reindex[OF inj_Suc, unfolded comp_def]
nipkow@31148
   176
                even_Suc Suc_m1 if_eq .
hoelzl@29803
   177
  } from sums_add[OF g_sums this]
hoelzl@29803
   178
  show ?thesis unfolding if_sum .
hoelzl@29803
   179
qed
hoelzl@29803
   180
hoelzl@29803
   181
subsection {* Alternating series test / Leibniz formula *}
hoelzl@29803
   182
hoelzl@29803
   183
lemma sums_alternating_upper_lower:
hoelzl@29803
   184
  fixes a :: "nat \<Rightarrow> real"
hoelzl@29803
   185
  assumes mono: "\<And>n. a (Suc n) \<le> a n" and a_pos: "\<And>n. 0 \<le> a n" and "a ----> 0"
hoelzl@41970
   186
  shows "\<exists>l. ((\<forall>n. (\<Sum>i=0..<2*n. -1^i*a i) \<le> l) \<and> (\<lambda> n. \<Sum>i=0..<2*n. -1^i*a i) ----> l) \<and>
hoelzl@29803
   187
             ((\<forall>n. l \<le> (\<Sum>i=0..<2*n + 1. -1^i*a i)) \<and> (\<lambda> n. \<Sum>i=0..<2*n + 1. -1^i*a i) ----> l)"
hoelzl@29803
   188
  (is "\<exists>l. ((\<forall>n. ?f n \<le> l) \<and> _) \<and> ((\<forall>n. l \<le> ?g n) \<and> _)")
hoelzl@29803
   189
proof -
huffman@30082
   190
  have fg_diff: "\<And>n. ?f n - ?g n = - a (2 * n)" unfolding One_nat_def by auto
hoelzl@29803
   191
hoelzl@29803
   192
  have "\<forall> n. ?f n \<le> ?f (Suc n)"
hoelzl@29803
   193
  proof fix n show "?f n \<le> ?f (Suc n)" using mono[of "2*n"] by auto qed
hoelzl@29803
   194
  moreover
hoelzl@29803
   195
  have "\<forall> n. ?g (Suc n) \<le> ?g n"
huffman@30082
   196
  proof fix n show "?g (Suc n) \<le> ?g n" using mono[of "Suc (2*n)"]
huffman@30082
   197
    unfolding One_nat_def by auto qed
hoelzl@29803
   198
  moreover
hoelzl@41970
   199
  have "\<forall> n. ?f n \<le> ?g n"
huffman@30082
   200
  proof fix n show "?f n \<le> ?g n" using fg_diff a_pos
huffman@30082
   201
    unfolding One_nat_def by auto qed
hoelzl@29803
   202
  moreover
hoelzl@29803
   203
  have "(\<lambda> n. ?f n - ?g n) ----> 0" unfolding fg_diff
hoelzl@29803
   204
  proof (rule LIMSEQ_I)
hoelzl@29803
   205
    fix r :: real assume "0 < r"
hoelzl@41970
   206
    with `a ----> 0`[THEN LIMSEQ_D]
hoelzl@29803
   207
    obtain N where "\<And> n. n \<ge> N \<Longrightarrow> norm (a n - 0) < r" by auto
hoelzl@29803
   208
    hence "\<forall> n \<ge> N. norm (- a (2 * n) - 0) < r" by auto
hoelzl@29803
   209
    thus "\<exists> N. \<forall> n \<ge> N. norm (- a (2 * n) - 0) < r" by auto
hoelzl@29803
   210
  qed
hoelzl@29803
   211
  ultimately
hoelzl@51477
   212
  show ?thesis by (rule nested_sequence_unique)
hoelzl@41970
   213
qed
hoelzl@29803
   214
hoelzl@29803
   215
lemma summable_Leibniz': fixes a :: "nat \<Rightarrow> real"
hoelzl@29803
   216
  assumes a_zero: "a ----> 0" and a_pos: "\<And> n. 0 \<le> a n"
hoelzl@29803
   217
  and a_monotone: "\<And> n. a (Suc n) \<le> a n"
hoelzl@29803
   218
  shows summable: "summable (\<lambda> n. (-1)^n * a n)"
hoelzl@29803
   219
  and "\<And>n. (\<Sum>i=0..<2*n. (-1)^i*a i) \<le> (\<Sum>i. (-1)^i*a i)"
hoelzl@29803
   220
  and "(\<lambda>n. \<Sum>i=0..<2*n. (-1)^i*a i) ----> (\<Sum>i. (-1)^i*a i)"
hoelzl@29803
   221
  and "\<And>n. (\<Sum>i. (-1)^i*a i) \<le> (\<Sum>i=0..<2*n+1. (-1)^i*a i)"
hoelzl@29803
   222
  and "(\<lambda>n. \<Sum>i=0..<2*n+1. (-1)^i*a i) ----> (\<Sum>i. (-1)^i*a i)"
hoelzl@29803
   223
proof -
hoelzl@29803
   224
  let "?S n" = "(-1)^n * a n"
hoelzl@29803
   225
  let "?P n" = "\<Sum>i=0..<n. ?S i"
hoelzl@29803
   226
  let "?f n" = "?P (2 * n)"
hoelzl@29803
   227
  let "?g n" = "?P (2 * n + 1)"
hoelzl@29803
   228
  obtain l :: real where below_l: "\<forall> n. ?f n \<le> l" and "?f ----> l" and above_l: "\<forall> n. l \<le> ?g n" and "?g ----> l"
hoelzl@29803
   229
    using sums_alternating_upper_lower[OF a_monotone a_pos a_zero] by blast
hoelzl@41970
   230
hoelzl@29803
   231
  let ?Sa = "\<lambda> m. \<Sum> n = 0..<m. ?S n"
hoelzl@29803
   232
  have "?Sa ----> l"
hoelzl@29803
   233
  proof (rule LIMSEQ_I)
hoelzl@29803
   234
    fix r :: real assume "0 < r"
hoelzl@29803
   235
hoelzl@41970
   236
    with `?f ----> l`[THEN LIMSEQ_D]
hoelzl@29803
   237
    obtain f_no where f: "\<And> n. n \<ge> f_no \<Longrightarrow> norm (?f n - l) < r" by auto
hoelzl@29803
   238
hoelzl@41970
   239
    from `0 < r` `?g ----> l`[THEN LIMSEQ_D]
hoelzl@29803
   240
    obtain g_no where g: "\<And> n. n \<ge> g_no \<Longrightarrow> norm (?g n - l) < r" by auto
hoelzl@29803
   241
hoelzl@29803
   242
    { fix n :: nat
hoelzl@29803
   243
      assume "n \<ge> (max (2 * f_no) (2 * g_no))" hence "n \<ge> 2 * f_no" and "n \<ge> 2 * g_no" by auto
hoelzl@29803
   244
      have "norm (?Sa n - l) < r"
hoelzl@29803
   245
      proof (cases "even n")
wenzelm@32960
   246
        case True from even_nat_div_two_times_two[OF this]
wenzelm@32960
   247
        have n_eq: "2 * (n div 2) = n" unfolding numeral_2_eq_2[symmetric] by auto
wenzelm@32960
   248
        with `n \<ge> 2 * f_no` have "n div 2 \<ge> f_no" by auto
wenzelm@32960
   249
        from f[OF this]
wenzelm@32960
   250
        show ?thesis unfolding n_eq atLeastLessThanSuc_atLeastAtMost .
hoelzl@29803
   251
      next
huffman@35213
   252
        case False hence "even (n - 1)" by simp
wenzelm@32960
   253
        from even_nat_div_two_times_two[OF this]
wenzelm@32960
   254
        have n_eq: "2 * ((n - 1) div 2) = n - 1" unfolding numeral_2_eq_2[symmetric] by auto
wenzelm@32960
   255
        hence range_eq: "n - 1 + 1 = n" using odd_pos[OF False] by auto
wenzelm@32960
   256
wenzelm@32960
   257
        from n_eq `n \<ge> 2 * g_no` have "(n - 1) div 2 \<ge> g_no" by auto
wenzelm@32960
   258
        from g[OF this]
wenzelm@32960
   259
        show ?thesis unfolding n_eq atLeastLessThanSuc_atLeastAtMost range_eq .
hoelzl@29803
   260
      qed
hoelzl@29803
   261
    }
hoelzl@29803
   262
    thus "\<exists> no. \<forall> n \<ge> no. norm (?Sa n - l) < r" by blast
hoelzl@29803
   263
  qed
hoelzl@29803
   264
  hence sums_l: "(\<lambda>i. (-1)^i * a i) sums l" unfolding sums_def atLeastLessThanSuc_atLeastAtMost[symmetric] .
hoelzl@29803
   265
  thus "summable ?S" using summable_def by auto
hoelzl@29803
   266
hoelzl@29803
   267
  have "l = suminf ?S" using sums_unique[OF sums_l] .
hoelzl@29803
   268
hoelzl@29803
   269
  { fix n show "suminf ?S \<le> ?g n" unfolding sums_unique[OF sums_l, symmetric] using above_l by auto }
hoelzl@29803
   270
  { fix n show "?f n \<le> suminf ?S" unfolding sums_unique[OF sums_l, symmetric] using below_l by auto }
hoelzl@29803
   271
  show "?g ----> suminf ?S" using `?g ----> l` `l = suminf ?S` by auto
hoelzl@29803
   272
  show "?f ----> suminf ?S" using `?f ----> l` `l = suminf ?S` by auto
hoelzl@29803
   273
qed
hoelzl@29803
   274
hoelzl@29803
   275
theorem summable_Leibniz: fixes a :: "nat \<Rightarrow> real"
hoelzl@29803
   276
  assumes a_zero: "a ----> 0" and "monoseq a"
hoelzl@29803
   277
  shows "summable (\<lambda> n. (-1)^n * a n)" (is "?summable")
hoelzl@29803
   278
  and "0 < a 0 \<longrightarrow> (\<forall>n. (\<Sum>i. -1^i*a i) \<in> { \<Sum>i=0..<2*n. -1^i * a i .. \<Sum>i=0..<2*n+1. -1^i * a i})" (is "?pos")
hoelzl@29803
   279
  and "a 0 < 0 \<longrightarrow> (\<forall>n. (\<Sum>i. -1^i*a i) \<in> { \<Sum>i=0..<2*n+1. -1^i * a i .. \<Sum>i=0..<2*n. -1^i * a i})" (is "?neg")
hoelzl@29803
   280
  and "(\<lambda>n. \<Sum>i=0..<2*n. -1^i*a i) ----> (\<Sum>i. -1^i*a i)" (is "?f")
hoelzl@29803
   281
  and "(\<lambda>n. \<Sum>i=0..<2*n+1. -1^i*a i) ----> (\<Sum>i. -1^i*a i)" (is "?g")
hoelzl@29803
   282
proof -
hoelzl@29803
   283
  have "?summable \<and> ?pos \<and> ?neg \<and> ?f \<and> ?g"
hoelzl@29803
   284
  proof (cases "(\<forall> n. 0 \<le> a n) \<and> (\<forall>m. \<forall>n\<ge>m. a n \<le> a m)")
hoelzl@29803
   285
    case True
hoelzl@29803
   286
    hence ord: "\<And>n m. m \<le> n \<Longrightarrow> a n \<le> a m" and ge0: "\<And> n. 0 \<le> a n" by auto
hoelzl@29803
   287
    { fix n have "a (Suc n) \<le> a n" using ord[where n="Suc n" and m=n] by auto }
hoelzl@29803
   288
    note leibniz = summable_Leibniz'[OF `a ----> 0` ge0] and mono = this
hoelzl@29803
   289
    from leibniz[OF mono]
hoelzl@29803
   290
    show ?thesis using `0 \<le> a 0` by auto
hoelzl@29803
   291
  next
hoelzl@29803
   292
    let ?a = "\<lambda> n. - a n"
hoelzl@29803
   293
    case False
hoelzl@29803
   294
    with monoseq_le[OF `monoseq a` `a ----> 0`]
hoelzl@29803
   295
    have "(\<forall> n. a n \<le> 0) \<and> (\<forall>m. \<forall>n\<ge>m. a m \<le> a n)" by auto
hoelzl@29803
   296
    hence ord: "\<And>n m. m \<le> n \<Longrightarrow> ?a n \<le> ?a m" and ge0: "\<And> n. 0 \<le> ?a n" by auto
hoelzl@29803
   297
    { fix n have "?a (Suc n) \<le> ?a n" using ord[where n="Suc n" and m=n] by auto }
hoelzl@29803
   298
    note monotone = this
huffman@44568
   299
    note leibniz = summable_Leibniz'[OF _ ge0, of "\<lambda>x. x", OF tendsto_minus[OF `a ----> 0`, unfolded minus_zero] monotone]
hoelzl@29803
   300
    have "summable (\<lambda> n. (-1)^n * ?a n)" using leibniz(1) by auto
hoelzl@29803
   301
    then obtain l where "(\<lambda> n. (-1)^n * ?a n) sums l" unfolding summable_def by auto
hoelzl@29803
   302
    from this[THEN sums_minus]
hoelzl@29803
   303
    have "(\<lambda> n. (-1)^n * a n) sums -l" by auto
hoelzl@29803
   304
    hence ?summable unfolding summable_def by auto
hoelzl@29803
   305
    moreover
hoelzl@29803
   306
    have "\<And> a b :: real. \<bar> - a - - b \<bar> = \<bar>a - b\<bar>" unfolding minus_diff_minus by auto
hoelzl@41970
   307
hoelzl@29803
   308
    from suminf_minus[OF leibniz(1), unfolded mult_minus_right minus_minus]
hoelzl@29803
   309
    have move_minus: "(\<Sum>n. - (-1 ^ n * a n)) = - (\<Sum>n. -1 ^ n * a n)" by auto
hoelzl@29803
   310
hoelzl@29803
   311
    have ?pos using `0 \<le> ?a 0` by auto
hoelzl@29803
   312
    moreover have ?neg using leibniz(2,4) unfolding mult_minus_right setsum_negf move_minus neg_le_iff_le by auto
huffman@44568
   313
    moreover have ?f and ?g using leibniz(3,5)[unfolded mult_minus_right setsum_negf move_minus, THEN tendsto_minus_cancel] by auto
hoelzl@29803
   314
    ultimately show ?thesis by auto
hoelzl@29803
   315
  qed
hoelzl@29803
   316
  from this[THEN conjunct1] this[THEN conjunct2, THEN conjunct1] this[THEN conjunct2, THEN conjunct2, THEN conjunct1] this[THEN conjunct2, THEN conjunct2, THEN conjunct2, THEN conjunct1]
hoelzl@29803
   317
       this[THEN conjunct2, THEN conjunct2, THEN conjunct2, THEN conjunct2]
hoelzl@29803
   318
  show ?summable and ?pos and ?neg and ?f and ?g .
hoelzl@29803
   319
qed
paulson@15077
   320
huffman@29164
   321
subsection {* Term-by-Term Differentiability of Power Series *}
huffman@23043
   322
huffman@23043
   323
definition
huffman@23082
   324
  diffs :: "(nat => 'a::ring_1) => nat => 'a" where
huffman@23082
   325
  "diffs c = (%n. of_nat (Suc n) * c(Suc n))"
paulson@15077
   326
paulson@15077
   327
text{*Lemma about distributing negation over it*}
paulson@15077
   328
lemma diffs_minus: "diffs (%n. - c n) = (%n. - diffs c n)"
paulson@15077
   329
by (simp add: diffs_def)
paulson@15077
   330
huffman@29163
   331
lemma sums_Suc_imp:
huffman@29163
   332
  assumes f: "f 0 = 0"
huffman@29163
   333
  shows "(\<lambda>n. f (Suc n)) sums s \<Longrightarrow> (\<lambda>n. f n) sums s"
huffman@29163
   334
unfolding sums_def
huffman@29163
   335
apply (rule LIMSEQ_imp_Suc)
huffman@29163
   336
apply (subst setsum_shift_lb_Suc0_0_upt [where f=f, OF f, symmetric])
huffman@29163
   337
apply (simp only: setsum_shift_bounds_Suc_ivl)
paulson@15077
   338
done
paulson@15077
   339
paulson@15229
   340
lemma diffs_equiv:
hoelzl@41970
   341
  fixes x :: "'a::{real_normed_vector, ring_1}"
hoelzl@41970
   342
  shows "summable (%n. (diffs c)(n) * (x ^ n)) ==>
hoelzl@41970
   343
      (%n. of_nat n * c(n) * (x ^ (n - Suc 0))) sums
nipkow@15546
   344
         (\<Sum>n. (diffs c)(n) * (x ^ n))"
huffman@29163
   345
unfolding diffs_def
huffman@29163
   346
apply (drule summable_sums)
huffman@29163
   347
apply (rule sums_Suc_imp, simp_all)
paulson@15077
   348
done
paulson@15077
   349
paulson@15077
   350
lemma lemma_termdiff1:
haftmann@31017
   351
  fixes z :: "'a :: {monoid_mult,comm_ring}" shows
hoelzl@41970
   352
  "(\<Sum>p=0..<m. (((z + h) ^ (m - p)) * (z ^ p)) - (z ^ m)) =
huffman@23082
   353
   (\<Sum>p=0..<m. (z ^ p) * (((z + h) ^ (m - p)) - (z ^ (m - p))))"
wenzelm@41550
   354
by(auto simp add: algebra_simps power_add [symmetric])
paulson@15077
   355
huffman@23082
   356
lemma sumr_diff_mult_const2:
huffman@23082
   357
  "setsum f {0..<n} - of_nat n * (r::'a::ring_1) = (\<Sum>i = 0..<n. f i - r)"
huffman@23082
   358
by (simp add: setsum_subtractf)
huffman@23082
   359
paulson@15229
   360
lemma lemma_termdiff2:
haftmann@31017
   361
  fixes h :: "'a :: {field}"
huffman@20860
   362
  assumes h: "h \<noteq> 0" shows
huffman@23082
   363
  "((z + h) ^ n - z ^ n) / h - of_nat n * z ^ (n - Suc 0) =
huffman@20860
   364
   h * (\<Sum>p=0..< n - Suc 0. \<Sum>q=0..< n - Suc 0 - p.
huffman@23082
   365
        (z + h) ^ q * z ^ (n - 2 - q))" (is "?lhs = ?rhs")
huffman@23082
   366
apply (subgoal_tac "h * ?lhs = h * ?rhs", simp add: h)
huffman@20860
   367
apply (simp add: right_diff_distrib diff_divide_distrib h)
paulson@15077
   368
apply (simp add: mult_assoc [symmetric])
huffman@20860
   369
apply (cases "n", simp)
huffman@20860
   370
apply (simp add: lemma_realpow_diff_sumr2 h
huffman@20860
   371
                 right_diff_distrib [symmetric] mult_assoc
huffman@30273
   372
            del: power_Suc setsum_op_ivl_Suc of_nat_Suc)
huffman@20860
   373
apply (subst lemma_realpow_rev_sumr)
huffman@23082
   374
apply (subst sumr_diff_mult_const2)
huffman@20860
   375
apply simp
huffman@20860
   376
apply (simp only: lemma_termdiff1 setsum_right_distrib)
huffman@20860
   377
apply (rule setsum_cong [OF refl])
nipkow@15539
   378
apply (simp add: diff_minus [symmetric] less_iff_Suc_add)
huffman@20860
   379
apply (clarify)
huffman@20860
   380
apply (simp add: setsum_right_distrib lemma_realpow_diff_sumr2 mult_ac
huffman@30273
   381
            del: setsum_op_ivl_Suc power_Suc)
huffman@20860
   382
apply (subst mult_assoc [symmetric], subst power_add [symmetric])
huffman@20860
   383
apply (simp add: mult_ac)
huffman@20860
   384
done
huffman@20860
   385
huffman@20860
   386
lemma real_setsum_nat_ivl_bounded2:
haftmann@35028
   387
  fixes K :: "'a::linordered_semidom"
huffman@23082
   388
  assumes f: "\<And>p::nat. p < n \<Longrightarrow> f p \<le> K"
huffman@23082
   389
  assumes K: "0 \<le> K"
huffman@23082
   390
  shows "setsum f {0..<n-k} \<le> of_nat n * K"
huffman@23082
   391
apply (rule order_trans [OF setsum_mono])
huffman@23082
   392
apply (rule f, simp)
huffman@23082
   393
apply (simp add: mult_right_mono K)
paulson@15077
   394
done
paulson@15077
   395
paulson@15229
   396
lemma lemma_termdiff3:
haftmann@31017
   397
  fixes h z :: "'a::{real_normed_field}"
huffman@20860
   398
  assumes 1: "h \<noteq> 0"
huffman@23082
   399
  assumes 2: "norm z \<le> K"
huffman@23082
   400
  assumes 3: "norm (z + h) \<le> K"
huffman@23082
   401
  shows "norm (((z + h) ^ n - z ^ n) / h - of_nat n * z ^ (n - Suc 0))
huffman@23082
   402
          \<le> of_nat n * of_nat (n - Suc 0) * K ^ (n - 2) * norm h"
huffman@20860
   403
proof -
huffman@23082
   404
  have "norm (((z + h) ^ n - z ^ n) / h - of_nat n * z ^ (n - Suc 0)) =
huffman@23082
   405
        norm (\<Sum>p = 0..<n - Suc 0. \<Sum>q = 0..<n - Suc 0 - p.
huffman@23082
   406
          (z + h) ^ q * z ^ (n - 2 - q)) * norm h"
huffman@20860
   407
    apply (subst lemma_termdiff2 [OF 1])
huffman@23082
   408
    apply (subst norm_mult)
huffman@20860
   409
    apply (rule mult_commute)
huffman@20860
   410
    done
huffman@23082
   411
  also have "\<dots> \<le> of_nat n * (of_nat (n - Suc 0) * K ^ (n - 2)) * norm h"
huffman@23082
   412
  proof (rule mult_right_mono [OF _ norm_ge_zero])
huffman@23082
   413
    from norm_ge_zero 2 have K: "0 \<le> K" by (rule order_trans)
huffman@23082
   414
    have le_Kn: "\<And>i j n. i + j = n \<Longrightarrow> norm ((z + h) ^ i * z ^ j) \<le> K ^ n"
huffman@20860
   415
      apply (erule subst)
huffman@23082
   416
      apply (simp only: norm_mult norm_power power_add)
huffman@23082
   417
      apply (intro mult_mono power_mono 2 3 norm_ge_zero zero_le_power K)
huffman@20860
   418
      done
huffman@23082
   419
    show "norm (\<Sum>p = 0..<n - Suc 0. \<Sum>q = 0..<n - Suc 0 - p.
huffman@23082
   420
              (z + h) ^ q * z ^ (n - 2 - q))
huffman@23082
   421
          \<le> of_nat n * (of_nat (n - Suc 0) * K ^ (n - 2))"
huffman@20860
   422
      apply (intro
huffman@23082
   423
         order_trans [OF norm_setsum]
huffman@20860
   424
         real_setsum_nat_ivl_bounded2
huffman@20860
   425
         mult_nonneg_nonneg
huffman@47489
   426
         of_nat_0_le_iff
huffman@20860
   427
         zero_le_power K)
huffman@20860
   428
      apply (rule le_Kn, simp)
huffman@20860
   429
      done
huffman@20860
   430
  qed
huffman@23082
   431
  also have "\<dots> = of_nat n * of_nat (n - Suc 0) * K ^ (n - 2) * norm h"
huffman@20860
   432
    by (simp only: mult_assoc)
huffman@20860
   433
  finally show ?thesis .
huffman@20860
   434
qed
paulson@15077
   435
huffman@20860
   436
lemma lemma_termdiff4:
haftmann@31017
   437
  fixes f :: "'a::{real_normed_field} \<Rightarrow>
huffman@23082
   438
              'b::real_normed_vector"
huffman@20860
   439
  assumes k: "0 < (k::real)"
huffman@23082
   440
  assumes le: "\<And>h. \<lbrakk>h \<noteq> 0; norm h < k\<rbrakk> \<Longrightarrow> norm (f h) \<le> K * norm h"
huffman@20860
   441
  shows "f -- 0 --> 0"
huffman@31338
   442
unfolding LIM_eq diff_0_right
huffman@29163
   443
proof (safe)
huffman@29163
   444
  let ?h = "of_real (k / 2)::'a"
huffman@29163
   445
  have "?h \<noteq> 0" and "norm ?h < k" using k by simp_all
huffman@29163
   446
  hence "norm (f ?h) \<le> K * norm ?h" by (rule le)
huffman@29163
   447
  hence "0 \<le> K * norm ?h" by (rule order_trans [OF norm_ge_zero])
huffman@29163
   448
  hence zero_le_K: "0 \<le> K" using k by (simp add: zero_le_mult_iff)
huffman@29163
   449
huffman@20860
   450
  fix r::real assume r: "0 < r"
huffman@23082
   451
  show "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> 0 \<and> norm x < s \<longrightarrow> norm (f x) < r)"
huffman@20860
   452
  proof (cases)
huffman@20860
   453
    assume "K = 0"
huffman@23082
   454
    with k r le have "0 < k \<and> (\<forall>x. x \<noteq> 0 \<and> norm x < k \<longrightarrow> norm (f x) < r)"
huffman@20860
   455
      by simp
huffman@23082
   456
    thus "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> 0 \<and> norm x < s \<longrightarrow> norm (f x) < r)" ..
huffman@20860
   457
  next
huffman@20860
   458
    assume K_neq_zero: "K \<noteq> 0"
huffman@20860
   459
    with zero_le_K have K: "0 < K" by simp
huffman@23082
   460
    show "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> 0 \<and> norm x < s \<longrightarrow> norm (f x) < r)"
huffman@20860
   461
    proof (rule exI, safe)
huffman@20860
   462
      from k r K show "0 < min k (r * inverse K / 2)"
huffman@20860
   463
        by (simp add: mult_pos_pos positive_imp_inverse_positive)
huffman@20860
   464
    next
huffman@23082
   465
      fix x::'a
huffman@23082
   466
      assume x1: "x \<noteq> 0" and x2: "norm x < min k (r * inverse K / 2)"
huffman@23082
   467
      from x2 have x3: "norm x < k" and x4: "norm x < r * inverse K / 2"
huffman@20860
   468
        by simp_all
huffman@23082
   469
      from x1 x3 le have "norm (f x) \<le> K * norm x" by simp
huffman@23082
   470
      also from x4 K have "K * norm x < K * (r * inverse K / 2)"
huffman@20860
   471
        by (rule mult_strict_left_mono)
huffman@20860
   472
      also have "\<dots> = r / 2"
huffman@20860
   473
        using K_neq_zero by simp
huffman@20860
   474
      also have "r / 2 < r"
huffman@20860
   475
        using r by simp
huffman@23082
   476
      finally show "norm (f x) < r" .
huffman@20860
   477
    qed
huffman@20860
   478
  qed
huffman@20860
   479
qed
paulson@15077
   480
paulson@15229
   481
lemma lemma_termdiff5:
haftmann@31017
   482
  fixes g :: "'a::{real_normed_field} \<Rightarrow>
huffman@23082
   483
              nat \<Rightarrow> 'b::banach"
huffman@20860
   484
  assumes k: "0 < (k::real)"
huffman@20860
   485
  assumes f: "summable f"
huffman@23082
   486
  assumes le: "\<And>h n. \<lbrakk>h \<noteq> 0; norm h < k\<rbrakk> \<Longrightarrow> norm (g h n) \<le> f n * norm h"
huffman@20860
   487
  shows "(\<lambda>h. suminf (g h)) -- 0 --> 0"
huffman@20860
   488
proof (rule lemma_termdiff4 [OF k])
huffman@23082
   489
  fix h::'a assume "h \<noteq> 0" and "norm h < k"
huffman@23082
   490
  hence A: "\<forall>n. norm (g h n) \<le> f n * norm h"
huffman@20860
   491
    by (simp add: le)
huffman@23082
   492
  hence "\<exists>N. \<forall>n\<ge>N. norm (norm (g h n)) \<le> f n * norm h"
huffman@20860
   493
    by simp
huffman@23082
   494
  moreover from f have B: "summable (\<lambda>n. f n * norm h)"
huffman@20860
   495
    by (rule summable_mult2)
huffman@23082
   496
  ultimately have C: "summable (\<lambda>n. norm (g h n))"
huffman@20860
   497
    by (rule summable_comparison_test)
huffman@23082
   498
  hence "norm (suminf (g h)) \<le> (\<Sum>n. norm (g h n))"
huffman@23082
   499
    by (rule summable_norm)
huffman@23082
   500
  also from A C B have "(\<Sum>n. norm (g h n)) \<le> (\<Sum>n. f n * norm h)"
huffman@20860
   501
    by (rule summable_le)
huffman@23082
   502
  also from f have "(\<Sum>n. f n * norm h) = suminf f * norm h"
huffman@20860
   503
    by (rule suminf_mult2 [symmetric])
huffman@23082
   504
  finally show "norm (suminf (g h)) \<le> suminf f * norm h" .
huffman@20860
   505
qed
paulson@15077
   506
paulson@15077
   507
paulson@15077
   508
text{* FIXME: Long proofs*}
paulson@15077
   509
paulson@15077
   510
lemma termdiffs_aux:
haftmann@31017
   511
  fixes x :: "'a::{real_normed_field,banach}"
huffman@20849
   512
  assumes 1: "summable (\<lambda>n. diffs (diffs c) n * K ^ n)"
huffman@23082
   513
  assumes 2: "norm x < norm K"
huffman@20860
   514
  shows "(\<lambda>h. \<Sum>n. c n * (((x + h) ^ n - x ^ n) / h
huffman@23082
   515
             - of_nat n * x ^ (n - Suc 0))) -- 0 --> 0"
huffman@20849
   516
proof -
huffman@20860
   517
  from dense [OF 2]
huffman@23082
   518
  obtain r where r1: "norm x < r" and r2: "r < norm K" by fast
huffman@23082
   519
  from norm_ge_zero r1 have r: "0 < r"
huffman@20860
   520
    by (rule order_le_less_trans)
huffman@20860
   521
  hence r_neq_0: "r \<noteq> 0" by simp
huffman@20860
   522
  show ?thesis
huffman@20849
   523
  proof (rule lemma_termdiff5)
huffman@23082
   524
    show "0 < r - norm x" using r1 by simp
huffman@20849
   525
  next
huffman@23082
   526
    from r r2 have "norm (of_real r::'a) < norm K"
huffman@23082
   527
      by simp
huffman@23082
   528
    with 1 have "summable (\<lambda>n. norm (diffs (diffs c) n * (of_real r ^ n)))"
huffman@20860
   529
      by (rule powser_insidea)
huffman@23082
   530
    hence "summable (\<lambda>n. diffs (diffs (\<lambda>n. norm (c n))) n * r ^ n)"
huffman@23082
   531
      using r
huffman@23082
   532
      by (simp add: diffs_def norm_mult norm_power del: of_nat_Suc)
huffman@23082
   533
    hence "summable (\<lambda>n. of_nat n * diffs (\<lambda>n. norm (c n)) n * r ^ (n - Suc 0))"
huffman@20860
   534
      by (rule diffs_equiv [THEN sums_summable])
huffman@23082
   535
    also have "(\<lambda>n. of_nat n * diffs (\<lambda>n. norm (c n)) n * r ^ (n - Suc 0))
huffman@23082
   536
      = (\<lambda>n. diffs (%m. of_nat (m - Suc 0) * norm (c m) * inverse r) n * (r ^ n))"
huffman@20849
   537
      apply (rule ext)
huffman@20849
   538
      apply (simp add: diffs_def)
huffman@20849
   539
      apply (case_tac n, simp_all add: r_neq_0)
huffman@20849
   540
      done
hoelzl@41970
   541
    finally have "summable
huffman@23082
   542
      (\<lambda>n. of_nat n * (of_nat (n - Suc 0) * norm (c n) * inverse r) * r ^ (n - Suc 0))"
huffman@20860
   543
      by (rule diffs_equiv [THEN sums_summable])
huffman@20860
   544
    also have
huffman@23082
   545
      "(\<lambda>n. of_nat n * (of_nat (n - Suc 0) * norm (c n) * inverse r) *
huffman@20860
   546
           r ^ (n - Suc 0)) =
huffman@23082
   547
       (\<lambda>n. norm (c n) * of_nat n * of_nat (n - Suc 0) * r ^ (n - 2))"
huffman@20849
   548
      apply (rule ext)
huffman@20849
   549
      apply (case_tac "n", simp)
huffman@20849
   550
      apply (case_tac "nat", simp)
huffman@20849
   551
      apply (simp add: r_neq_0)
huffman@20849
   552
      done
huffman@20860
   553
    finally show
huffman@23082
   554
      "summable (\<lambda>n. norm (c n) * of_nat n * of_nat (n - Suc 0) * r ^ (n - 2))" .
huffman@20849
   555
  next
huffman@23082
   556
    fix h::'a and n::nat
huffman@20860
   557
    assume h: "h \<noteq> 0"
huffman@23082
   558
    assume "norm h < r - norm x"
huffman@23082
   559
    hence "norm x + norm h < r" by simp
huffman@23082
   560
    with norm_triangle_ineq have xh: "norm (x + h) < r"
huffman@20860
   561
      by (rule order_le_less_trans)
huffman@23082
   562
    show "norm (c n * (((x + h) ^ n - x ^ n) / h - of_nat n * x ^ (n - Suc 0)))
huffman@23082
   563
          \<le> norm (c n) * of_nat n * of_nat (n - Suc 0) * r ^ (n - 2) * norm h"
huffman@23082
   564
      apply (simp only: norm_mult mult_assoc)
huffman@23082
   565
      apply (rule mult_left_mono [OF _ norm_ge_zero])
huffman@20860
   566
      apply (simp (no_asm) add: mult_assoc [symmetric])
huffman@20860
   567
      apply (rule lemma_termdiff3)
huffman@20860
   568
      apply (rule h)
huffman@20860
   569
      apply (rule r1 [THEN order_less_imp_le])
huffman@20860
   570
      apply (rule xh [THEN order_less_imp_le])
huffman@20860
   571
      done
huffman@20849
   572
  qed
huffman@20849
   573
qed
webertj@20217
   574
huffman@20860
   575
lemma termdiffs:
haftmann@31017
   576
  fixes K x :: "'a::{real_normed_field,banach}"
huffman@20860
   577
  assumes 1: "summable (\<lambda>n. c n * K ^ n)"
huffman@20860
   578
  assumes 2: "summable (\<lambda>n. (diffs c) n * K ^ n)"
huffman@20860
   579
  assumes 3: "summable (\<lambda>n. (diffs (diffs c)) n * K ^ n)"
huffman@23082
   580
  assumes 4: "norm x < norm K"
huffman@20860
   581
  shows "DERIV (\<lambda>x. \<Sum>n. c n * x ^ n) x :> (\<Sum>n. (diffs c) n * x ^ n)"
huffman@29163
   582
unfolding deriv_def
huffman@29163
   583
proof (rule LIM_zero_cancel)
huffman@20860
   584
  show "(\<lambda>h. (suminf (\<lambda>n. c n * (x + h) ^ n) - suminf (\<lambda>n. c n * x ^ n)) / h
huffman@20860
   585
            - suminf (\<lambda>n. diffs c n * x ^ n)) -- 0 --> 0"
huffman@20860
   586
  proof (rule LIM_equal2)
huffman@29163
   587
    show "0 < norm K - norm x" using 4 by (simp add: less_diff_eq)
huffman@20860
   588
  next
huffman@23082
   589
    fix h :: 'a
huffman@20860
   590
    assume "h \<noteq> 0"
huffman@23082
   591
    assume "norm (h - 0) < norm K - norm x"
huffman@23082
   592
    hence "norm x + norm h < norm K" by simp
huffman@23082
   593
    hence 5: "norm (x + h) < norm K"
huffman@23082
   594
      by (rule norm_triangle_ineq [THEN order_le_less_trans])
huffman@20860
   595
    have A: "summable (\<lambda>n. c n * x ^ n)"
huffman@20860
   596
      by (rule powser_inside [OF 1 4])
huffman@20860
   597
    have B: "summable (\<lambda>n. c n * (x + h) ^ n)"
huffman@20860
   598
      by (rule powser_inside [OF 1 5])
huffman@20860
   599
    have C: "summable (\<lambda>n. diffs c n * x ^ n)"
huffman@20860
   600
      by (rule powser_inside [OF 2 4])
huffman@20860
   601
    show "((\<Sum>n. c n * (x + h) ^ n) - (\<Sum>n. c n * x ^ n)) / h
hoelzl@41970
   602
             - (\<Sum>n. diffs c n * x ^ n) =
huffman@23082
   603
          (\<Sum>n. c n * (((x + h) ^ n - x ^ n) / h - of_nat n * x ^ (n - Suc 0)))"
huffman@20860
   604
      apply (subst sums_unique [OF diffs_equiv [OF C]])
huffman@20860
   605
      apply (subst suminf_diff [OF B A])
huffman@20860
   606
      apply (subst suminf_divide [symmetric])
huffman@20860
   607
      apply (rule summable_diff [OF B A])
huffman@20860
   608
      apply (subst suminf_diff)
huffman@20860
   609
      apply (rule summable_divide)
huffman@20860
   610
      apply (rule summable_diff [OF B A])
huffman@20860
   611
      apply (rule sums_summable [OF diffs_equiv [OF C]])
huffman@29163
   612
      apply (rule arg_cong [where f="suminf"], rule ext)
nipkow@29667
   613
      apply (simp add: algebra_simps)
huffman@20860
   614
      done
huffman@20860
   615
  next
huffman@20860
   616
    show "(\<lambda>h. \<Sum>n. c n * (((x + h) ^ n - x ^ n) / h -
huffman@23082
   617
               of_nat n * x ^ (n - Suc 0))) -- 0 --> 0"
huffman@20860
   618
        by (rule termdiffs_aux [OF 3 4])
huffman@20860
   619
  qed
huffman@20860
   620
qed
huffman@20860
   621
paulson@15077
   622
hoelzl@29803
   623
subsection {* Derivability of power series *}
hoelzl@29803
   624
hoelzl@29803
   625
lemma DERIV_series': fixes f :: "real \<Rightarrow> nat \<Rightarrow> real"
hoelzl@29803
   626
  assumes DERIV_f: "\<And> n. DERIV (\<lambda> x. f x n) x0 :> (f' x0 n)"
hoelzl@29803
   627
  and allf_summable: "\<And> x. x \<in> {a <..< b} \<Longrightarrow> summable (f x)" and x0_in_I: "x0 \<in> {a <..< b}"
hoelzl@29803
   628
  and "summable (f' x0)"
hoelzl@29803
   629
  and "summable L" and L_def: "\<And> n x y. \<lbrakk> x \<in> { a <..< b} ; y \<in> { a <..< b} \<rbrakk> \<Longrightarrow> \<bar> f x n - f y n \<bar> \<le> L n * \<bar> x - y \<bar>"
hoelzl@29803
   630
  shows "DERIV (\<lambda> x. suminf (f x)) x0 :> (suminf (f' x0))"
hoelzl@29803
   631
  unfolding deriv_def
hoelzl@29803
   632
proof (rule LIM_I)
hoelzl@29803
   633
  fix r :: real assume "0 < r" hence "0 < r/3" by auto
hoelzl@29803
   634
hoelzl@41970
   635
  obtain N_L where N_L: "\<And> n. N_L \<le> n \<Longrightarrow> \<bar> \<Sum> i. L (i + n) \<bar> < r/3"
hoelzl@29803
   636
    using suminf_exist_split[OF `0 < r/3` `summable L`] by auto
hoelzl@29803
   637
hoelzl@41970
   638
  obtain N_f' where N_f': "\<And> n. N_f' \<le> n \<Longrightarrow> \<bar> \<Sum> i. f' x0 (i + n) \<bar> < r/3"
hoelzl@29803
   639
    using suminf_exist_split[OF `0 < r/3` `summable (f' x0)`] by auto
hoelzl@29803
   640
hoelzl@29803
   641
  let ?N = "Suc (max N_L N_f')"
hoelzl@29803
   642
  have "\<bar> \<Sum> i. f' x0 (i + ?N) \<bar> < r/3" (is "?f'_part < r/3") and
hoelzl@29803
   643
    L_estimate: "\<bar> \<Sum> i. L (i + ?N) \<bar> < r/3" using N_L[of "?N"] and N_f' [of "?N"] by auto
hoelzl@29803
   644
hoelzl@29803
   645
  let "?diff i x" = "(f (x0 + x) i - f x0 i) / x"
hoelzl@29803
   646
hoelzl@29803
   647
  let ?r = "r / (3 * real ?N)"
hoelzl@29803
   648
  have "0 < 3 * real ?N" by auto
hoelzl@29803
   649
  from divide_pos_pos[OF `0 < r` this]
hoelzl@29803
   650
  have "0 < ?r" .
hoelzl@29803
   651
hoelzl@29803
   652
  let "?s n" = "SOME s. 0 < s \<and> (\<forall> x. x \<noteq> 0 \<and> \<bar> x \<bar> < s \<longrightarrow> \<bar> ?diff n x - f' x0 n \<bar> < ?r)"
hoelzl@29803
   653
  def S' \<equiv> "Min (?s ` { 0 ..< ?N })"
hoelzl@29803
   654
hoelzl@29803
   655
  have "0 < S'" unfolding S'_def
hoelzl@29803
   656
  proof (rule iffD2[OF Min_gr_iff])
hoelzl@29803
   657
    show "\<forall> x \<in> (?s ` { 0 ..< ?N }). 0 < x"
hoelzl@29803
   658
    proof (rule ballI)
hoelzl@29803
   659
      fix x assume "x \<in> ?s ` {0..<?N}"
hoelzl@29803
   660
      then obtain n where "x = ?s n" and "n \<in> {0..<?N}" using image_iff[THEN iffD1] by blast
hoelzl@41970
   661
      from DERIV_D[OF DERIV_f[where n=n], THEN LIM_D, OF `0 < ?r`, unfolded real_norm_def]
hoelzl@29803
   662
      obtain s where s_bound: "0 < s \<and> (\<forall>x. x \<noteq> 0 \<and> \<bar>x\<bar> < s \<longrightarrow> \<bar>?diff n x - f' x0 n\<bar> < ?r)" by auto
hoelzl@29803
   663
      have "0 < ?s n" by (rule someI2[where a=s], auto simp add: s_bound)
hoelzl@29803
   664
      thus "0 < x" unfolding `x = ?s n` .
hoelzl@29803
   665
    qed
hoelzl@29803
   666
  qed auto
hoelzl@29803
   667
hoelzl@29803
   668
  def S \<equiv> "min (min (x0 - a) (b - x0)) S'"
hoelzl@29803
   669
  hence "0 < S" and S_a: "S \<le> x0 - a" and S_b: "S \<le> b - x0" and "S \<le> S'" using x0_in_I and `0 < S'`
hoelzl@29803
   670
    by auto
hoelzl@29803
   671
hoelzl@29803
   672
  { fix x assume "x \<noteq> 0" and "\<bar> x \<bar> < S"
hoelzl@29803
   673
    hence x_in_I: "x0 + x \<in> { a <..< b }" using S_a S_b by auto
hoelzl@41970
   674
hoelzl@29803
   675
    note diff_smbl = summable_diff[OF allf_summable[OF x_in_I] allf_summable[OF x0_in_I]]
hoelzl@29803
   676
    note div_smbl = summable_divide[OF diff_smbl]
hoelzl@29803
   677
    note all_smbl = summable_diff[OF div_smbl `summable (f' x0)`]
hoelzl@29803
   678
    note ign = summable_ignore_initial_segment[where k="?N"]
hoelzl@29803
   679
    note diff_shft_smbl = summable_diff[OF ign[OF allf_summable[OF x_in_I]] ign[OF allf_summable[OF x0_in_I]]]
hoelzl@29803
   680
    note div_shft_smbl = summable_divide[OF diff_shft_smbl]
hoelzl@29803
   681
    note all_shft_smbl = summable_diff[OF div_smbl ign[OF `summable (f' x0)`]]
hoelzl@29803
   682
hoelzl@29803
   683
    { fix n
hoelzl@41970
   684
      have "\<bar> ?diff (n + ?N) x \<bar> \<le> L (n + ?N) * \<bar> (x0 + x) - x0 \<bar> / \<bar> x \<bar>"
wenzelm@32960
   685
        using divide_right_mono[OF L_def[OF x_in_I x0_in_I] abs_ge_zero] unfolding abs_divide .
hoelzl@29803
   686
      hence "\<bar> ( \<bar> ?diff (n + ?N) x \<bar>) \<bar> \<le> L (n + ?N)" using `x \<noteq> 0` by auto
hoelzl@29803
   687
    } note L_ge = summable_le2[OF allI[OF this] ign[OF `summable L`]]
hoelzl@29803
   688
    from order_trans[OF summable_rabs[OF conjunct1[OF L_ge]] L_ge[THEN conjunct2]]
hoelzl@29803
   689
    have "\<bar> \<Sum> i. ?diff (i + ?N) x \<bar> \<le> (\<Sum> i. L (i + ?N))" .
hoelzl@29803
   690
    hence "\<bar> \<Sum> i. ?diff (i + ?N) x \<bar> \<le> r / 3" (is "?L_part \<le> r/3") using L_estimate by auto
hoelzl@29803
   691
hoelzl@29803
   692
    have "\<bar>\<Sum>n \<in> { 0 ..< ?N}. ?diff n x - f' x0 n \<bar> \<le> (\<Sum>n \<in> { 0 ..< ?N}. \<bar>?diff n x - f' x0 n \<bar>)" ..
hoelzl@29803
   693
    also have "\<dots> < (\<Sum>n \<in> { 0 ..< ?N}. ?r)"
hoelzl@29803
   694
    proof (rule setsum_strict_mono)
hoelzl@29803
   695
      fix n assume "n \<in> { 0 ..< ?N}"
hoelzl@29803
   696
      have "\<bar> x \<bar> < S" using `\<bar> x \<bar> < S` .
hoelzl@29803
   697
      also have "S \<le> S'" using `S \<le> S'` .
hoelzl@41970
   698
      also have "S' \<le> ?s n" unfolding S'_def
hoelzl@29803
   699
      proof (rule Min_le_iff[THEN iffD2])
wenzelm@32960
   700
        have "?s n \<in> (?s ` {0..<?N}) \<and> ?s n \<le> ?s n" using `n \<in> { 0 ..< ?N}` by auto
wenzelm@32960
   701
        thus "\<exists> a \<in> (?s ` {0..<?N}). a \<le> ?s n" by blast
hoelzl@29803
   702
      qed auto
hoelzl@29803
   703
      finally have "\<bar> x \<bar> < ?s n" .
hoelzl@29803
   704
hoelzl@29803
   705
      from DERIV_D[OF DERIV_f[where n=n], THEN LIM_D, OF `0 < ?r`, unfolded real_norm_def diff_0_right, unfolded some_eq_ex[symmetric], THEN conjunct2]
hoelzl@29803
   706
      have "\<forall>x. x \<noteq> 0 \<and> \<bar>x\<bar> < ?s n \<longrightarrow> \<bar>?diff n x - f' x0 n\<bar> < ?r" .
hoelzl@29803
   707
      with `x \<noteq> 0` and `\<bar>x\<bar> < ?s n`
hoelzl@29803
   708
      show "\<bar>?diff n x - f' x0 n\<bar> < ?r" by blast
hoelzl@29803
   709
    qed auto
hoelzl@29803
   710
    also have "\<dots> = of_nat (card {0 ..< ?N}) * ?r" by (rule setsum_constant)
hoelzl@29803
   711
    also have "\<dots> = real ?N * ?r" unfolding real_eq_of_nat by auto
hoelzl@29803
   712
    also have "\<dots> = r/3" by auto
hoelzl@29803
   713
    finally have "\<bar>\<Sum>n \<in> { 0 ..< ?N}. ?diff n x - f' x0 n \<bar> < r / 3" (is "?diff_part < r / 3") .
hoelzl@29803
   714
hoelzl@29803
   715
    from suminf_diff[OF allf_summable[OF x_in_I] allf_summable[OF x0_in_I]]
hoelzl@41970
   716
    have "\<bar> (suminf (f (x0 + x)) - (suminf (f x0))) / x - suminf (f' x0) \<bar> =
hoelzl@29803
   717
                    \<bar> \<Sum>n. ?diff n x - f' x0 n \<bar>" unfolding suminf_diff[OF div_smbl `summable (f' x0)`, symmetric] using suminf_divide[OF diff_smbl, symmetric] by auto
hoelzl@29803
   718
    also have "\<dots> \<le> ?diff_part + \<bar> (\<Sum>n. ?diff (n + ?N) x) - (\<Sum> n. f' x0 (n + ?N)) \<bar>" unfolding suminf_split_initial_segment[OF all_smbl, where k="?N"] unfolding suminf_diff[OF div_shft_smbl ign[OF `summable (f' x0)`]] by (rule abs_triangle_ineq)
hoelzl@29803
   719
    also have "\<dots> \<le> ?diff_part + ?L_part + ?f'_part" using abs_triangle_ineq4 by auto
hoelzl@41970
   720
    also have "\<dots> < r /3 + r/3 + r/3"
huffman@36842
   721
      using `?diff_part < r/3` `?L_part \<le> r/3` and `?f'_part < r/3`
huffman@36842
   722
      by (rule add_strict_mono [OF add_less_le_mono])
hoelzl@29803
   723
    finally have "\<bar> (suminf (f (x0 + x)) - (suminf (f x0))) / x - suminf (f' x0) \<bar> < r"
hoelzl@29803
   724
      by auto
hoelzl@41970
   725
  } thus "\<exists> s > 0. \<forall> x. x \<noteq> 0 \<and> norm (x - 0) < s \<longrightarrow>
hoelzl@29803
   726
      norm (((\<Sum>n. f (x0 + x) n) - (\<Sum>n. f x0 n)) / x - (\<Sum>n. f' x0 n)) < r" using `0 < S`
hoelzl@29803
   727
    unfolding real_norm_def diff_0_right by blast
hoelzl@29803
   728
qed
hoelzl@29803
   729
hoelzl@29803
   730
lemma DERIV_power_series': fixes f :: "nat \<Rightarrow> real"
hoelzl@29803
   731
  assumes converges: "\<And> x. x \<in> {-R <..< R} \<Longrightarrow> summable (\<lambda> n. f n * real (Suc n) * x^n)"
hoelzl@29803
   732
  and x0_in_I: "x0 \<in> {-R <..< R}" and "0 < R"
hoelzl@29803
   733
  shows "DERIV (\<lambda> x. (\<Sum> n. f n * x^(Suc n))) x0 :> (\<Sum> n. f n * real (Suc n) * x0^n)"
hoelzl@29803
   734
  (is "DERIV (\<lambda> x. (suminf (?f x))) x0 :> (suminf (?f' x0))")
hoelzl@29803
   735
proof -
hoelzl@29803
   736
  { fix R' assume "0 < R'" and "R' < R" and "-R' < x0" and "x0 < R'"
hoelzl@29803
   737
    hence "x0 \<in> {-R' <..< R'}" and "R' \<in> {-R <..< R}" and "x0 \<in> {-R <..< R}" by auto
hoelzl@29803
   738
    have "DERIV (\<lambda> x. (suminf (?f x))) x0 :> (suminf (?f' x0))"
hoelzl@29803
   739
    proof (rule DERIV_series')
hoelzl@29803
   740
      show "summable (\<lambda> n. \<bar>f n * real (Suc n) * R'^n\<bar>)"
hoelzl@29803
   741
      proof -
wenzelm@32960
   742
        have "(R' + R) / 2 < R" and "0 < (R' + R) / 2" using `0 < R'` `0 < R` `R' < R` by auto
wenzelm@32960
   743
        hence in_Rball: "(R' + R) / 2 \<in> {-R <..< R}" using `R' < R` by auto
wenzelm@32960
   744
        have "norm R' < norm ((R' + R) / 2)" using `0 < R'` `0 < R` `R' < R` by auto
wenzelm@32960
   745
        from powser_insidea[OF converges[OF in_Rball] this] show ?thesis by auto
hoelzl@29803
   746
      qed
hoelzl@29803
   747
      { fix n x y assume "x \<in> {-R' <..< R'}" and "y \<in> {-R' <..< R'}"
wenzelm@32960
   748
        show "\<bar>?f x n - ?f y n\<bar> \<le> \<bar>f n * real (Suc n) * R'^n\<bar> * \<bar>x-y\<bar>"
wenzelm@32960
   749
        proof -
hoelzl@41970
   750
          have "\<bar>f n * x ^ (Suc n) - f n * y ^ (Suc n)\<bar> = (\<bar>f n\<bar> * \<bar>x-y\<bar>) * \<bar>\<Sum>p = 0..<Suc n. x ^ p * y ^ (n - p)\<bar>"
wenzelm@32960
   751
            unfolding right_diff_distrib[symmetric] lemma_realpow_diff_sumr2 abs_mult by auto
hoelzl@41970
   752
          also have "\<dots> \<le> (\<bar>f n\<bar> * \<bar>x-y\<bar>) * (\<bar>real (Suc n)\<bar> * \<bar>R' ^ n\<bar>)"
wenzelm@32960
   753
          proof (rule mult_left_mono)
wenzelm@32960
   754
            have "\<bar>\<Sum>p = 0..<Suc n. x ^ p * y ^ (n - p)\<bar> \<le> (\<Sum>p = 0..<Suc n. \<bar>x ^ p * y ^ (n - p)\<bar>)" by (rule setsum_abs)
wenzelm@32960
   755
            also have "\<dots> \<le> (\<Sum>p = 0..<Suc n. R' ^ n)"
wenzelm@32960
   756
            proof (rule setsum_mono)
wenzelm@32960
   757
              fix p assume "p \<in> {0..<Suc n}" hence "p \<le> n" by auto
wenzelm@32960
   758
              { fix n fix x :: real assume "x \<in> {-R'<..<R'}"
wenzelm@32960
   759
                hence "\<bar>x\<bar> \<le> R'"  by auto
wenzelm@32960
   760
                hence "\<bar>x^n\<bar> \<le> R'^n" unfolding power_abs by (rule power_mono, auto)
wenzelm@32960
   761
              } from mult_mono[OF this[OF `x \<in> {-R'<..<R'}`, of p] this[OF `y \<in> {-R'<..<R'}`, of "n-p"]] `0 < R'`
wenzelm@32960
   762
              have "\<bar>x^p * y^(n-p)\<bar> \<le> R'^p * R'^(n-p)" unfolding abs_mult by auto
wenzelm@32960
   763
              thus "\<bar>x^p * y^(n-p)\<bar> \<le> R'^n" unfolding power_add[symmetric] using `p \<le> n` by auto
wenzelm@32960
   764
            qed
wenzelm@32960
   765
            also have "\<dots> = real (Suc n) * R' ^ n" unfolding setsum_constant card_atLeastLessThan real_of_nat_def by auto
wenzelm@32960
   766
            finally show "\<bar>\<Sum>p = 0..<Suc n. x ^ p * y ^ (n - p)\<bar> \<le> \<bar>real (Suc n)\<bar> * \<bar>R' ^ n\<bar>" unfolding abs_real_of_nat_cancel abs_of_nonneg[OF zero_le_power[OF less_imp_le[OF `0 < R'`]]] .
wenzelm@32960
   767
            show "0 \<le> \<bar>f n\<bar> * \<bar>x - y\<bar>" unfolding abs_mult[symmetric] by auto
wenzelm@32960
   768
          qed
huffman@36777
   769
          also have "\<dots> = \<bar>f n * real (Suc n) * R' ^ n\<bar> * \<bar>x - y\<bar>" unfolding abs_mult mult_assoc[symmetric] by algebra
wenzelm@32960
   770
          finally show ?thesis .
wenzelm@32960
   771
        qed }
hoelzl@31881
   772
      { fix n show "DERIV (\<lambda> x. ?f x n) x0 :> (?f' x0 n)"
wenzelm@32960
   773
          by (auto intro!: DERIV_intros simp del: power_Suc) }
hoelzl@29803
   774
      { fix x assume "x \<in> {-R' <..< R'}" hence "R' \<in> {-R <..< R}" and "norm x < norm R'" using assms `R' < R` by auto
wenzelm@32960
   775
        have "summable (\<lambda> n. f n * x^n)"
wenzelm@32960
   776
        proof (rule summable_le2[THEN conjunct1, OF _ powser_insidea[OF converges[OF `R' \<in> {-R <..< R}`] `norm x < norm R'`]], rule allI)
wenzelm@32960
   777
          fix n
wenzelm@32960
   778
          have le: "\<bar>f n\<bar> * 1 \<le> \<bar>f n\<bar> * real (Suc n)" by (rule mult_left_mono, auto)
wenzelm@32960
   779
          show "\<bar>f n * x ^ n\<bar> \<le> norm (f n * real (Suc n) * x ^ n)" unfolding real_norm_def abs_mult
wenzelm@32960
   780
            by (rule mult_right_mono, auto simp add: le[unfolded mult_1_right])
wenzelm@32960
   781
        qed
huffman@36777
   782
        from this[THEN summable_mult2[where c=x], unfolded mult_assoc, unfolded mult_commute]
wenzelm@32960
   783
        show "summable (?f x)" by auto }
hoelzl@29803
   784
      show "summable (?f' x0)" using converges[OF `x0 \<in> {-R <..< R}`] .
hoelzl@29803
   785
      show "x0 \<in> {-R' <..< R'}" using `x0 \<in> {-R' <..< R'}` .
hoelzl@29803
   786
    qed
hoelzl@29803
   787
  } note for_subinterval = this
hoelzl@29803
   788
  let ?R = "(R + \<bar>x0\<bar>) / 2"
hoelzl@29803
   789
  have "\<bar>x0\<bar> < ?R" using assms by auto
hoelzl@29803
   790
  hence "- ?R < x0"
hoelzl@29803
   791
  proof (cases "x0 < 0")
hoelzl@29803
   792
    case True
hoelzl@29803
   793
    hence "- x0 < ?R" using `\<bar>x0\<bar> < ?R` by auto
hoelzl@29803
   794
    thus ?thesis unfolding neg_less_iff_less[symmetric, of "- x0"] by auto
hoelzl@29803
   795
  next
hoelzl@29803
   796
    case False
hoelzl@29803
   797
    have "- ?R < 0" using assms by auto
hoelzl@41970
   798
    also have "\<dots> \<le> x0" using False by auto
hoelzl@29803
   799
    finally show ?thesis .
hoelzl@29803
   800
  qed
hoelzl@29803
   801
  hence "0 < ?R" "?R < R" "- ?R < x0" and "x0 < ?R" using assms by auto
hoelzl@29803
   802
  from for_subinterval[OF this]
hoelzl@29803
   803
  show ?thesis .
hoelzl@29803
   804
qed
chaieb@29695
   805
huffman@29164
   806
subsection {* Exponential Function *}
huffman@23043
   807
huffman@44308
   808
definition exp :: "'a \<Rightarrow> 'a::{real_normed_field,banach}" where
huffman@44308
   809
  "exp = (\<lambda>x. \<Sum>n. x ^ n /\<^sub>R real (fact n))"
huffman@23043
   810
huffman@23115
   811
lemma summable_exp_generic:
haftmann@31017
   812
  fixes x :: "'a::{real_normed_algebra_1,banach}"
haftmann@25062
   813
  defines S_def: "S \<equiv> \<lambda>n. x ^ n /\<^sub>R real (fact n)"
huffman@23115
   814
  shows "summable S"
huffman@23115
   815
proof -
haftmann@25062
   816
  have S_Suc: "\<And>n. S (Suc n) = (x * S n) /\<^sub>R real (Suc n)"
huffman@30273
   817
    unfolding S_def by (simp del: mult_Suc)
huffman@23115
   818
  obtain r :: real where r0: "0 < r" and r1: "r < 1"
huffman@23115
   819
    using dense [OF zero_less_one] by fast
huffman@23115
   820
  obtain N :: nat where N: "norm x < real N * r"
huffman@23115
   821
    using reals_Archimedean3 [OF r0] by fast
huffman@23115
   822
  from r1 show ?thesis
huffman@23115
   823
  proof (rule ratio_test [rule_format])
huffman@23115
   824
    fix n :: nat
huffman@23115
   825
    assume n: "N \<le> n"
huffman@23115
   826
    have "norm x \<le> real N * r"
huffman@23115
   827
      using N by (rule order_less_imp_le)
huffman@23115
   828
    also have "real N * r \<le> real (Suc n) * r"
huffman@23115
   829
      using r0 n by (simp add: mult_right_mono)
huffman@23115
   830
    finally have "norm x * norm (S n) \<le> real (Suc n) * r * norm (S n)"
huffman@23115
   831
      using norm_ge_zero by (rule mult_right_mono)
huffman@23115
   832
    hence "norm (x * S n) \<le> real (Suc n) * r * norm (S n)"
huffman@23115
   833
      by (rule order_trans [OF norm_mult_ineq])
huffman@23115
   834
    hence "norm (x * S n) / real (Suc n) \<le> r * norm (S n)"
huffman@23115
   835
      by (simp add: pos_divide_le_eq mult_ac)
huffman@23115
   836
    thus "norm (S (Suc n)) \<le> r * norm (S n)"
huffman@35216
   837
      by (simp add: S_Suc inverse_eq_divide)
huffman@23115
   838
  qed
huffman@23115
   839
qed
huffman@23115
   840
huffman@23115
   841
lemma summable_norm_exp:
haftmann@31017
   842
  fixes x :: "'a::{real_normed_algebra_1,banach}"
haftmann@25062
   843
  shows "summable (\<lambda>n. norm (x ^ n /\<^sub>R real (fact n)))"
huffman@23115
   844
proof (rule summable_norm_comparison_test [OF exI, rule_format])
haftmann@25062
   845
  show "summable (\<lambda>n. norm x ^ n /\<^sub>R real (fact n))"
huffman@23115
   846
    by (rule summable_exp_generic)
huffman@23115
   847
next
haftmann@25062
   848
  fix n show "norm (x ^ n /\<^sub>R real (fact n)) \<le> norm x ^ n /\<^sub>R real (fact n)"
huffman@35216
   849
    by (simp add: norm_power_ineq)
huffman@23115
   850
qed
huffman@23115
   851
huffman@23043
   852
lemma summable_exp: "summable (%n. inverse (real (fact n)) * x ^ n)"
huffman@23115
   853
by (insert summable_exp_generic [where x=x], simp)
huffman@23043
   854
haftmann@25062
   855
lemma exp_converges: "(\<lambda>n. x ^ n /\<^sub>R real (fact n)) sums exp x"
huffman@23115
   856
unfolding exp_def by (rule summable_exp_generic [THEN summable_sums])
huffman@23043
   857
huffman@23043
   858
hoelzl@41970
   859
lemma exp_fdiffs:
paulson@15077
   860
      "diffs (%n. inverse(real (fact n))) = (%n. inverse(real (fact n)))"
huffman@23431
   861
by (simp add: diffs_def mult_assoc [symmetric] real_of_nat_def of_nat_mult
huffman@23082
   862
         del: mult_Suc of_nat_Suc)
paulson@15077
   863
huffman@23115
   864
lemma diffs_of_real: "diffs (\<lambda>n. of_real (f n)) = (\<lambda>n. of_real (diffs f n))"
huffman@23115
   865
by (simp add: diffs_def)
huffman@23115
   866
paulson@15077
   867
lemma DERIV_exp [simp]: "DERIV exp x :> exp(x)"
huffman@44308
   868
unfolding exp_def scaleR_conv_of_real
huffman@44308
   869
apply (rule DERIV_cong)
huffman@44308
   870
apply (rule termdiffs [where K="of_real (1 + norm x)"])
huffman@23115
   871
apply (simp_all only: diffs_of_real scaleR_conv_of_real exp_fdiffs)
huffman@23115
   872
apply (rule exp_converges [THEN sums_summable, unfolded scaleR_conv_of_real])+
huffman@23115
   873
apply (simp del: of_real_add)
paulson@15077
   874
done
paulson@15077
   875
hoelzl@51527
   876
declare DERIV_exp[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
hoelzl@51527
   877
huffman@44311
   878
lemma isCont_exp: "isCont exp x"
huffman@44311
   879
  by (rule DERIV_exp [THEN DERIV_isCont])
huffman@44311
   880
huffman@44311
   881
lemma isCont_exp' [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. exp (f x)) a"
huffman@44311
   882
  by (rule isCont_o2 [OF _ isCont_exp])
huffman@44311
   883
huffman@44311
   884
lemma tendsto_exp [tendsto_intros]:
huffman@44311
   885
  "(f ---> a) F \<Longrightarrow> ((\<lambda>x. exp (f x)) ---> exp a) F"
huffman@44311
   886
  by (rule isCont_tendsto_compose [OF isCont_exp])
huffman@23045
   887
hoelzl@51478
   888
lemma continuous_exp [continuous_intros]: "continuous F f \<Longrightarrow> continuous F (\<lambda>x. exp (f x))"
hoelzl@51478
   889
  unfolding continuous_def by (rule tendsto_exp)
hoelzl@51478
   890
hoelzl@51478
   891
lemma continuous_on_exp [continuous_on_intros]: "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. exp (f x))"
hoelzl@51478
   892
  unfolding continuous_on_def by (auto intro: tendsto_exp)
hoelzl@51478
   893
huffman@29167
   894
subsubsection {* Properties of the Exponential Function *}
paulson@15077
   895
huffman@23278
   896
lemma powser_zero:
haftmann@31017
   897
  fixes f :: "nat \<Rightarrow> 'a::{real_normed_algebra_1}"
huffman@23278
   898
  shows "(\<Sum>n. f n * 0 ^ n) = f 0"
paulson@15077
   899
proof -
huffman@23278
   900
  have "(\<Sum>n = 0..<1. f n * 0 ^ n) = (\<Sum>n. f n * 0 ^ n)"
huffman@23115
   901
    by (rule sums_unique [OF series_zero], simp add: power_0_left)
huffman@30082
   902
  thus ?thesis unfolding One_nat_def by simp
paulson@15077
   903
qed
paulson@15077
   904
huffman@23278
   905
lemma exp_zero [simp]: "exp 0 = 1"
huffman@23278
   906
unfolding exp_def by (simp add: scaleR_conv_of_real powser_zero)
huffman@23278
   907
huffman@23115
   908
lemma setsum_cl_ivl_Suc2:
huffman@23115
   909
  "(\<Sum>i=m..Suc n. f i) = (if Suc n < m then 0 else f m + (\<Sum>i=m..n. f (Suc i)))"
nipkow@28069
   910
by (simp add: setsum_head_Suc setsum_shift_bounds_cl_Suc_ivl
huffman@23115
   911
         del: setsum_cl_ivl_Suc)
huffman@23115
   912
huffman@23115
   913
lemma exp_series_add:
haftmann@31017
   914
  fixes x y :: "'a::{real_field}"
haftmann@25062
   915
  defines S_def: "S \<equiv> \<lambda>x n. x ^ n /\<^sub>R real (fact n)"
huffman@23115
   916
  shows "S (x + y) n = (\<Sum>i=0..n. S x i * S y (n - i))"
huffman@23115
   917
proof (induct n)
huffman@23115
   918
  case 0
huffman@23115
   919
  show ?case
huffman@23115
   920
    unfolding S_def by simp
huffman@23115
   921
next
huffman@23115
   922
  case (Suc n)
haftmann@25062
   923
  have S_Suc: "\<And>x n. S x (Suc n) = (x * S x n) /\<^sub>R real (Suc n)"
huffman@30273
   924
    unfolding S_def by (simp del: mult_Suc)
haftmann@25062
   925
  hence times_S: "\<And>x n. x * S x n = real (Suc n) *\<^sub>R S x (Suc n)"
huffman@23115
   926
    by simp
huffman@23115
   927
haftmann@25062
   928
  have "real (Suc n) *\<^sub>R S (x + y) (Suc n) = (x + y) * S (x + y) n"
huffman@23115
   929
    by (simp only: times_S)
huffman@23115
   930
  also have "\<dots> = (x + y) * (\<Sum>i=0..n. S x i * S y (n-i))"
huffman@23115
   931
    by (simp only: Suc)
huffman@23115
   932
  also have "\<dots> = x * (\<Sum>i=0..n. S x i * S y (n-i))
huffman@23115
   933
                + y * (\<Sum>i=0..n. S x i * S y (n-i))"
webertj@49962
   934
    by (rule distrib_right)
huffman@23115
   935
  also have "\<dots> = (\<Sum>i=0..n. (x * S x i) * S y (n-i))
huffman@23115
   936
                + (\<Sum>i=0..n. S x i * (y * S y (n-i)))"
huffman@23115
   937
    by (simp only: setsum_right_distrib mult_ac)
haftmann@25062
   938
  also have "\<dots> = (\<Sum>i=0..n. real (Suc i) *\<^sub>R (S x (Suc i) * S y (n-i)))
haftmann@25062
   939
                + (\<Sum>i=0..n. real (Suc n-i) *\<^sub>R (S x i * S y (Suc n-i)))"
huffman@23115
   940
    by (simp add: times_S Suc_diff_le)
haftmann@25062
   941
  also have "(\<Sum>i=0..n. real (Suc i) *\<^sub>R (S x (Suc i) * S y (n-i))) =
haftmann@25062
   942
             (\<Sum>i=0..Suc n. real i *\<^sub>R (S x i * S y (Suc n-i)))"
huffman@23115
   943
    by (subst setsum_cl_ivl_Suc2, simp)
haftmann@25062
   944
  also have "(\<Sum>i=0..n. real (Suc n-i) *\<^sub>R (S x i * S y (Suc n-i))) =
haftmann@25062
   945
             (\<Sum>i=0..Suc n. real (Suc n-i) *\<^sub>R (S x i * S y (Suc n-i)))"
huffman@23115
   946
    by (subst setsum_cl_ivl_Suc, simp)
haftmann@25062
   947
  also have "(\<Sum>i=0..Suc n. real i *\<^sub>R (S x i * S y (Suc n-i))) +
haftmann@25062
   948
             (\<Sum>i=0..Suc n. real (Suc n-i) *\<^sub>R (S x i * S y (Suc n-i))) =
haftmann@25062
   949
             (\<Sum>i=0..Suc n. real (Suc n) *\<^sub>R (S x i * S y (Suc n-i)))"
huffman@23115
   950
    by (simp only: setsum_addf [symmetric] scaleR_left_distrib [symmetric]
huffman@23115
   951
              real_of_nat_add [symmetric], simp)
haftmann@25062
   952
  also have "\<dots> = real (Suc n) *\<^sub>R (\<Sum>i=0..Suc n. S x i * S y (Suc n-i))"
huffman@23127
   953
    by (simp only: scaleR_right.setsum)
huffman@23115
   954
  finally show
huffman@23115
   955
    "S (x + y) (Suc n) = (\<Sum>i=0..Suc n. S x i * S y (Suc n - i))"
huffman@35216
   956
    by (simp del: setsum_cl_ivl_Suc)
huffman@23115
   957
qed
huffman@23115
   958
huffman@23115
   959
lemma exp_add: "exp (x + y) = exp x * exp y"
huffman@23115
   960
unfolding exp_def
huffman@23115
   961
by (simp only: Cauchy_product summable_norm_exp exp_series_add)
huffman@23115
   962
huffman@29170
   963
lemma mult_exp_exp: "exp x * exp y = exp (x + y)"
huffman@29170
   964
by (rule exp_add [symmetric])
huffman@29170
   965
huffman@23241
   966
lemma exp_of_real: "exp (of_real x) = of_real (exp x)"
huffman@23241
   967
unfolding exp_def
huffman@44282
   968
apply (subst suminf_of_real)
huffman@23241
   969
apply (rule summable_exp_generic)
huffman@23241
   970
apply (simp add: scaleR_conv_of_real)
huffman@23241
   971
done
huffman@23241
   972
huffman@29170
   973
lemma exp_not_eq_zero [simp]: "exp x \<noteq> 0"
huffman@29170
   974
proof
huffman@29170
   975
  have "exp x * exp (- x) = 1" by (simp add: mult_exp_exp)
huffman@29170
   976
  also assume "exp x = 0"
huffman@29170
   977
  finally show "False" by simp
paulson@15077
   978
qed
paulson@15077
   979
huffman@29170
   980
lemma exp_minus: "exp (- x) = inverse (exp x)"
huffman@29170
   981
by (rule inverse_unique [symmetric], simp add: mult_exp_exp)
paulson@15077
   982
huffman@29170
   983
lemma exp_diff: "exp (x - y) = exp x / exp y"
huffman@29170
   984
  unfolding diff_minus divide_inverse
huffman@29170
   985
  by (simp add: exp_add exp_minus)
paulson@15077
   986
huffman@29167
   987
huffman@29167
   988
subsubsection {* Properties of the Exponential Function on Reals *}
huffman@29167
   989
huffman@29170
   990
text {* Comparisons of @{term "exp x"} with zero. *}
huffman@29167
   991
huffman@29167
   992
text{*Proof: because every exponential can be seen as a square.*}
huffman@29167
   993
lemma exp_ge_zero [simp]: "0 \<le> exp (x::real)"
huffman@29167
   994
proof -
huffman@29167
   995
  have "0 \<le> exp (x/2) * exp (x/2)" by simp
huffman@29167
   996
  thus ?thesis by (simp add: exp_add [symmetric])
huffman@29167
   997
qed
huffman@29167
   998
huffman@23115
   999
lemma exp_gt_zero [simp]: "0 < exp (x::real)"
paulson@15077
  1000
by (simp add: order_less_le)
paulson@15077
  1001
huffman@29170
  1002
lemma not_exp_less_zero [simp]: "\<not> exp (x::real) < 0"
huffman@29170
  1003
by (simp add: not_less)
huffman@29170
  1004
huffman@29170
  1005
lemma not_exp_le_zero [simp]: "\<not> exp (x::real) \<le> 0"
huffman@29170
  1006
by (simp add: not_le)
paulson@15077
  1007
huffman@23115
  1008
lemma abs_exp_cancel [simp]: "\<bar>exp x::real\<bar> = exp x"
huffman@29165
  1009
by simp
paulson@15077
  1010
paulson@15077
  1011
lemma exp_real_of_nat_mult: "exp(real n * x) = exp(x) ^ n"
paulson@15251
  1012
apply (induct "n")
webertj@49962
  1013
apply (auto simp add: real_of_nat_Suc distrib_left exp_add mult_commute)
paulson@15077
  1014
done
paulson@15077
  1015
huffman@29170
  1016
text {* Strict monotonicity of exponential. *}
huffman@29170
  1017
huffman@29170
  1018
lemma exp_ge_add_one_self_aux: "0 \<le> (x::real) ==> (1 + x) \<le> exp(x)"
huffman@29170
  1019
apply (drule order_le_imp_less_or_eq, auto)
huffman@29170
  1020
apply (simp add: exp_def)
huffman@36777
  1021
apply (rule order_trans)
huffman@29170
  1022
apply (rule_tac [2] n = 2 and f = "(%n. inverse (real (fact n)) * x ^ n)" in series_pos_le)
huffman@29170
  1023
apply (auto intro: summable_exp simp add: numeral_2_eq_2 zero_le_mult_iff)
huffman@29170
  1024
done
huffman@29170
  1025
huffman@29170
  1026
lemma exp_gt_one: "0 < (x::real) \<Longrightarrow> 1 < exp x"
huffman@29170
  1027
proof -
huffman@29170
  1028
  assume x: "0 < x"
huffman@29170
  1029
  hence "1 < 1 + x" by simp
huffman@29170
  1030
  also from x have "1 + x \<le> exp x"
huffman@29170
  1031
    by (simp add: exp_ge_add_one_self_aux)
huffman@29170
  1032
  finally show ?thesis .
huffman@29170
  1033
qed
huffman@29170
  1034
paulson@15077
  1035
lemma exp_less_mono:
huffman@23115
  1036
  fixes x y :: real
huffman@29165
  1037
  assumes "x < y" shows "exp x < exp y"
paulson@15077
  1038
proof -
huffman@29165
  1039
  from `x < y` have "0 < y - x" by simp
huffman@29165
  1040
  hence "1 < exp (y - x)" by (rule exp_gt_one)
huffman@29165
  1041
  hence "1 < exp y / exp x" by (simp only: exp_diff)
huffman@29165
  1042
  thus "exp x < exp y" by simp
paulson@15077
  1043
qed
paulson@15077
  1044
huffman@23115
  1045
lemma exp_less_cancel: "exp (x::real) < exp y ==> x < y"
huffman@29170
  1046
apply (simp add: linorder_not_le [symmetric])
huffman@29170
  1047
apply (auto simp add: order_le_less exp_less_mono)
paulson@15077
  1048
done
paulson@15077
  1049
huffman@29170
  1050
lemma exp_less_cancel_iff [iff]: "exp (x::real) < exp y \<longleftrightarrow> x < y"
paulson@15077
  1051
by (auto intro: exp_less_mono exp_less_cancel)
paulson@15077
  1052
huffman@29170
  1053
lemma exp_le_cancel_iff [iff]: "exp (x::real) \<le> exp y \<longleftrightarrow> x \<le> y"
paulson@15077
  1054
by (auto simp add: linorder_not_less [symmetric])
paulson@15077
  1055
huffman@29170
  1056
lemma exp_inj_iff [iff]: "exp (x::real) = exp y \<longleftrightarrow> x = y"
paulson@15077
  1057
by (simp add: order_eq_iff)
paulson@15077
  1058
huffman@29170
  1059
text {* Comparisons of @{term "exp x"} with one. *}
huffman@29170
  1060
huffman@29170
  1061
lemma one_less_exp_iff [simp]: "1 < exp (x::real) \<longleftrightarrow> 0 < x"
huffman@29170
  1062
  using exp_less_cancel_iff [where x=0 and y=x] by simp
huffman@29170
  1063
huffman@29170
  1064
lemma exp_less_one_iff [simp]: "exp (x::real) < 1 \<longleftrightarrow> x < 0"
huffman@29170
  1065
  using exp_less_cancel_iff [where x=x and y=0] by simp
huffman@29170
  1066
huffman@29170
  1067
lemma one_le_exp_iff [simp]: "1 \<le> exp (x::real) \<longleftrightarrow> 0 \<le> x"
huffman@29170
  1068
  using exp_le_cancel_iff [where x=0 and y=x] by simp
huffman@29170
  1069
huffman@29170
  1070
lemma exp_le_one_iff [simp]: "exp (x::real) \<le> 1 \<longleftrightarrow> x \<le> 0"
huffman@29170
  1071
  using exp_le_cancel_iff [where x=x and y=0] by simp
huffman@29170
  1072
huffman@29170
  1073
lemma exp_eq_one_iff [simp]: "exp (x::real) = 1 \<longleftrightarrow> x = 0"
huffman@29170
  1074
  using exp_inj_iff [where x=x and y=0] by simp
huffman@29170
  1075
huffman@23115
  1076
lemma lemma_exp_total: "1 \<le> y ==> \<exists>x. 0 \<le> x & x \<le> y - 1 & exp(x::real) = y"
huffman@44755
  1077
proof (rule IVT)
huffman@44755
  1078
  assume "1 \<le> y"
huffman@44755
  1079
  hence "0 \<le> y - 1" by simp
huffman@44755
  1080
  hence "1 + (y - 1) \<le> exp (y - 1)" by (rule exp_ge_add_one_self_aux)
huffman@44755
  1081
  thus "y \<le> exp (y - 1)" by simp
huffman@44755
  1082
qed (simp_all add: le_diff_eq)
paulson@15077
  1083
huffman@23115
  1084
lemma exp_total: "0 < (y::real) ==> \<exists>x. exp x = y"
huffman@44755
  1085
proof (rule linorder_le_cases [of 1 y])
huffman@44755
  1086
  assume "1 \<le> y" thus "\<exists>x. exp x = y"
huffman@44755
  1087
    by (fast dest: lemma_exp_total)
huffman@44755
  1088
next
huffman@44755
  1089
  assume "0 < y" and "y \<le> 1"
huffman@44755
  1090
  hence "1 \<le> inverse y" by (simp add: one_le_inverse_iff)
huffman@44755
  1091
  then obtain x where "exp x = inverse y" by (fast dest: lemma_exp_total)
huffman@44755
  1092
  hence "exp (- x) = y" by (simp add: exp_minus)
huffman@44755
  1093
  thus "\<exists>x. exp x = y" ..
huffman@44755
  1094
qed
paulson@15077
  1095
paulson@15077
  1096
huffman@29164
  1097
subsection {* Natural Logarithm *}
paulson@15077
  1098
huffman@44308
  1099
definition ln :: "real \<Rightarrow> real" where
huffman@23043
  1100
  "ln x = (THE u. exp u = x)"
huffman@23043
  1101
huffman@23043
  1102
lemma ln_exp [simp]: "ln (exp x) = x"
huffman@44308
  1103
  by (simp add: ln_def)
paulson@15077
  1104
huffman@22654
  1105
lemma exp_ln [simp]: "0 < x \<Longrightarrow> exp (ln x) = x"
huffman@44308
  1106
  by (auto dest: exp_total)
huffman@22654
  1107
huffman@29171
  1108
lemma exp_ln_iff [simp]: "exp (ln x) = x \<longleftrightarrow> 0 < x"
huffman@44308
  1109
  by (metis exp_gt_zero exp_ln)
paulson@15077
  1110
huffman@29171
  1111
lemma ln_unique: "exp y = x \<Longrightarrow> ln x = y"
huffman@44308
  1112
  by (erule subst, rule ln_exp)
huffman@29171
  1113
huffman@29171
  1114
lemma ln_one [simp]: "ln 1 = 0"
huffman@44308
  1115
  by (rule ln_unique, simp)
huffman@29171
  1116
huffman@29171
  1117
lemma ln_mult: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln (x * y) = ln x + ln y"
huffman@44308
  1118
  by (rule ln_unique, simp add: exp_add)
huffman@29171
  1119
huffman@29171
  1120
lemma ln_inverse: "0 < x \<Longrightarrow> ln (inverse x) = - ln x"
huffman@44308
  1121
  by (rule ln_unique, simp add: exp_minus)
huffman@29171
  1122
huffman@29171
  1123
lemma ln_div: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln (x / y) = ln x - ln y"
huffman@44308
  1124
  by (rule ln_unique, simp add: exp_diff)
paulson@15077
  1125
huffman@29171
  1126
lemma ln_realpow: "0 < x \<Longrightarrow> ln (x ^ n) = real n * ln x"
huffman@44308
  1127
  by (rule ln_unique, simp add: exp_real_of_nat_mult)
huffman@29171
  1128
huffman@29171
  1129
lemma ln_less_cancel_iff [simp]: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln x < ln y \<longleftrightarrow> x < y"
huffman@44308
  1130
  by (subst exp_less_cancel_iff [symmetric], simp)
huffman@29171
  1131
huffman@29171
  1132
lemma ln_le_cancel_iff [simp]: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln x \<le> ln y \<longleftrightarrow> x \<le> y"
huffman@44308
  1133
  by (simp add: linorder_not_less [symmetric])
huffman@29171
  1134
huffman@29171
  1135
lemma ln_inj_iff [simp]: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln x = ln y \<longleftrightarrow> x = y"
huffman@44308
  1136
  by (simp add: order_eq_iff)
huffman@29171
  1137
huffman@29171
  1138
lemma ln_add_one_self_le_self [simp]: "0 \<le> x \<Longrightarrow> ln (1 + x) \<le> x"
huffman@44308
  1139
  apply (rule exp_le_cancel_iff [THEN iffD1])
huffman@44308
  1140
  apply (simp add: exp_ge_add_one_self_aux)
huffman@44308
  1141
  done
paulson@15077
  1142
huffman@29171
  1143
lemma ln_less_self [simp]: "0 < x \<Longrightarrow> ln x < x"
huffman@44308
  1144
  by (rule order_less_le_trans [where y="ln (1 + x)"]) simp_all
huffman@44308
  1145
huffman@44308
  1146
lemma ln_ge_zero [simp]: "1 \<le> x \<Longrightarrow> 0 \<le> ln x"
huffman@44308
  1147
  using ln_le_cancel_iff [of 1 x] by simp
huffman@44308
  1148
huffman@44308
  1149
lemma ln_ge_zero_imp_ge_one: "\<lbrakk>0 \<le> ln x; 0 < x\<rbrakk> \<Longrightarrow> 1 \<le> x"
huffman@44308
  1150
  using ln_le_cancel_iff [of 1 x] by simp
huffman@44308
  1151
huffman@44308
  1152
lemma ln_ge_zero_iff [simp]: "0 < x \<Longrightarrow> (0 \<le> ln x) = (1 \<le> x)"
huffman@44308
  1153
  using ln_le_cancel_iff [of 1 x] by simp
huffman@44308
  1154
huffman@44308
  1155
lemma ln_less_zero_iff [simp]: "0 < x \<Longrightarrow> (ln x < 0) = (x < 1)"
huffman@44308
  1156
  using ln_less_cancel_iff [of x 1] by simp
huffman@44308
  1157
huffman@44308
  1158
lemma ln_gt_zero: "1 < x \<Longrightarrow> 0 < ln x"
huffman@44308
  1159
  using ln_less_cancel_iff [of 1 x] by simp
huffman@44308
  1160
huffman@44308
  1161
lemma ln_gt_zero_imp_gt_one: "\<lbrakk>0 < ln x; 0 < x\<rbrakk> \<Longrightarrow> 1 < x"
huffman@44308
  1162
  using ln_less_cancel_iff [of 1 x] by simp
huffman@44308
  1163
huffman@44308
  1164
lemma ln_gt_zero_iff [simp]: "0 < x \<Longrightarrow> (0 < ln x) = (1 < x)"
huffman@44308
  1165
  using ln_less_cancel_iff [of 1 x] by simp
huffman@44308
  1166
huffman@44308
  1167
lemma ln_eq_zero_iff [simp]: "0 < x \<Longrightarrow> (ln x = 0) = (x = 1)"
huffman@44308
  1168
  using ln_inj_iff [of x 1] by simp
huffman@44308
  1169
huffman@44308
  1170
lemma ln_less_zero: "\<lbrakk>0 < x; x < 1\<rbrakk> \<Longrightarrow> ln x < 0"
huffman@44308
  1171
  by simp
paulson@15077
  1172
huffman@23045
  1173
lemma isCont_ln: "0 < x \<Longrightarrow> isCont ln x"
huffman@44308
  1174
  apply (subgoal_tac "isCont ln (exp (ln x))", simp)
huffman@44308
  1175
  apply (rule isCont_inverse_function [where f=exp], simp_all)
huffman@44308
  1176
  done
huffman@23045
  1177
huffman@45915
  1178
lemma tendsto_ln [tendsto_intros]:
huffman@45915
  1179
  "\<lbrakk>(f ---> a) F; 0 < a\<rbrakk> \<Longrightarrow> ((\<lambda>x. ln (f x)) ---> ln a) F"
huffman@45915
  1180
  by (rule isCont_tendsto_compose [OF isCont_ln])
huffman@45915
  1181
hoelzl@51478
  1182
lemma continuous_ln:
hoelzl@51478
  1183
  "continuous F f \<Longrightarrow> 0 < f (Lim F (\<lambda>x. x)) \<Longrightarrow> continuous F (\<lambda>x. ln (f x))"
hoelzl@51478
  1184
  unfolding continuous_def by (rule tendsto_ln)
hoelzl@51478
  1185
hoelzl@51478
  1186
lemma isCont_ln' [continuous_intros]:
hoelzl@51478
  1187
  "continuous (at x) f \<Longrightarrow> 0 < f x \<Longrightarrow> continuous (at x) (\<lambda>x. ln (f x))"
hoelzl@51478
  1188
  unfolding continuous_at by (rule tendsto_ln)
hoelzl@51478
  1189
hoelzl@51478
  1190
lemma continuous_within_ln [continuous_intros]:
hoelzl@51478
  1191
  "continuous (at x within s) f \<Longrightarrow> 0 < f x \<Longrightarrow> continuous (at x within s) (\<lambda>x. ln (f x))"
hoelzl@51478
  1192
  unfolding continuous_within by (rule tendsto_ln)
hoelzl@51478
  1193
hoelzl@51478
  1194
lemma continuous_on_ln [continuous_on_intros]:
hoelzl@51478
  1195
  "continuous_on s f \<Longrightarrow> (\<forall>x\<in>s. 0 < f x) \<Longrightarrow> continuous_on s (\<lambda>x. ln (f x))"
hoelzl@51478
  1196
  unfolding continuous_on_def by (auto intro: tendsto_ln)
hoelzl@51478
  1197
huffman@23045
  1198
lemma DERIV_ln: "0 < x \<Longrightarrow> DERIV ln x :> inverse x"
huffman@44308
  1199
  apply (rule DERIV_inverse_function [where f=exp and a=0 and b="x+1"])
huffman@44317
  1200
  apply (erule DERIV_cong [OF DERIV_exp exp_ln])
huffman@44308
  1201
  apply (simp_all add: abs_if isCont_ln)
huffman@44308
  1202
  done
huffman@23045
  1203
paulson@33667
  1204
lemma DERIV_ln_divide: "0 < x ==> DERIV ln x :> 1 / x"
paulson@33667
  1205
  by (rule DERIV_ln[THEN DERIV_cong], simp, simp add: divide_inverse)
paulson@33667
  1206
hoelzl@51527
  1207
declare DERIV_ln_divide[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
hoelzl@51527
  1208
hoelzl@29803
  1209
lemma ln_series: assumes "0 < x" and "x < 2"
hoelzl@29803
  1210
  shows "ln x = (\<Sum> n. (-1)^n * (1 / real (n + 1)) * (x - 1)^(Suc n))" (is "ln x = suminf (?f (x - 1))")
hoelzl@29803
  1211
proof -
hoelzl@29803
  1212
  let "?f' x n" = "(-1)^n * (x - 1)^n"
hoelzl@29803
  1213
hoelzl@29803
  1214
  have "ln x - suminf (?f (x - 1)) = ln 1 - suminf (?f (1 - 1))"
hoelzl@29803
  1215
  proof (rule DERIV_isconst3[where x=x])
hoelzl@29803
  1216
    fix x :: real assume "x \<in> {0 <..< 2}" hence "0 < x" and "x < 2" by auto
hoelzl@29803
  1217
    have "norm (1 - x) < 1" using `0 < x` and `x < 2` by auto
hoelzl@29803
  1218
    have "1 / x = 1 / (1 - (1 - x))" by auto
hoelzl@29803
  1219
    also have "\<dots> = (\<Sum> n. (1 - x)^n)" using geometric_sums[OF `norm (1 - x) < 1`] by (rule sums_unique)
hoelzl@29803
  1220
    also have "\<dots> = suminf (?f' x)" unfolding power_mult_distrib[symmetric] by (rule arg_cong[where f=suminf], rule arg_cong[where f="op ^"], auto)
huffman@36777
  1221
    finally have "DERIV ln x :> suminf (?f' x)" using DERIV_ln[OF `0 < x`] unfolding divide_inverse by auto
hoelzl@29803
  1222
    moreover
hoelzl@29803
  1223
    have repos: "\<And> h x :: real. h - 1 + x = h + x - 1" by auto
hoelzl@29803
  1224
    have "DERIV (\<lambda>x. suminf (?f x)) (x - 1) :> (\<Sum>n. (-1)^n * (1 / real (n + 1)) * real (Suc n) * (x - 1) ^ n)"
hoelzl@29803
  1225
    proof (rule DERIV_power_series')
hoelzl@29803
  1226
      show "x - 1 \<in> {- 1<..<1}" and "(0 :: real) < 1" using `0 < x` `x < 2` by auto
hoelzl@29803
  1227
      { fix x :: real assume "x \<in> {- 1<..<1}" hence "norm (-x) < 1" by auto
wenzelm@32960
  1228
        show "summable (\<lambda>n. -1 ^ n * (1 / real (n + 1)) * real (Suc n) * x ^ n)"
huffman@30082
  1229
          unfolding One_nat_def
huffman@35216
  1230
          by (auto simp add: power_mult_distrib[symmetric] summable_geometric[OF `norm (-x) < 1`])
hoelzl@29803
  1231
      }
hoelzl@29803
  1232
    qed
huffman@30082
  1233
    hence "DERIV (\<lambda>x. suminf (?f x)) (x - 1) :> suminf (?f' x)" unfolding One_nat_def by auto
hoelzl@29803
  1234
    hence "DERIV (\<lambda>x. suminf (?f (x - 1))) x :> suminf (?f' x)" unfolding DERIV_iff repos .
hoelzl@29803
  1235
    ultimately have "DERIV (\<lambda>x. ln x - suminf (?f (x - 1))) x :> (suminf (?f' x) - suminf (?f' x))"
hoelzl@29803
  1236
      by (rule DERIV_diff)
hoelzl@29803
  1237
    thus "DERIV (\<lambda>x. ln x - suminf (?f (x - 1))) x :> 0" by auto
hoelzl@29803
  1238
  qed (auto simp add: assms)
huffman@44289
  1239
  thus ?thesis by auto
hoelzl@29803
  1240
qed
paulson@15077
  1241
hoelzl@50326
  1242
lemma exp_first_two_terms: "exp x = 1 + x + (\<Sum> n. inverse(fact (n+2)) * (x ^ (n+2)))"
hoelzl@50326
  1243
proof -
hoelzl@50326
  1244
  have "exp x = suminf (%n. inverse(fact n) * (x ^ n))"
hoelzl@50326
  1245
    by (simp add: exp_def)
hoelzl@50326
  1246
  also from summable_exp have "... = (\<Sum> n::nat = 0 ..< 2. inverse(fact n) * (x ^ n)) +
hoelzl@50326
  1247
      (\<Sum> n. inverse(fact(n+2)) * (x ^ (n+2)))" (is "_ = ?a + _")
hoelzl@50326
  1248
    by (rule suminf_split_initial_segment)
hoelzl@50326
  1249
  also have "?a = 1 + x"
hoelzl@50326
  1250
    by (simp add: numeral_2_eq_2)
hoelzl@50326
  1251
  finally show ?thesis .
hoelzl@50326
  1252
qed
hoelzl@50326
  1253
wenzelm@53076
  1254
lemma exp_bound: "0 <= (x::real) ==> x <= 1 ==> exp x <= 1 + x + x\<^sup>2"
hoelzl@50326
  1255
proof -
hoelzl@50326
  1256
  assume a: "0 <= x"
hoelzl@50326
  1257
  assume b: "x <= 1"
hoelzl@50326
  1258
  { fix n :: nat
hoelzl@50326
  1259
    have "2 * 2 ^ n \<le> fact (n + 2)"
hoelzl@50326
  1260
      by (induct n, simp, simp)
hoelzl@50326
  1261
    hence "real ((2::nat) * 2 ^ n) \<le> real (fact (n + 2))"
hoelzl@50326
  1262
      by (simp only: real_of_nat_le_iff)
hoelzl@50326
  1263
    hence "2 * 2 ^ n \<le> real (fact (n + 2))"
hoelzl@50326
  1264
      by simp
hoelzl@50326
  1265
    hence "inverse (fact (n + 2)) \<le> inverse (2 * 2 ^ n)"
hoelzl@50326
  1266
      by (rule le_imp_inverse_le) simp
hoelzl@50326
  1267
    hence "inverse (fact (n + 2)) \<le> 1/2 * (1/2)^n"
hoelzl@50326
  1268
      by (simp add: inverse_mult_distrib power_inverse)
wenzelm@53015
  1269
    hence "inverse (fact (n + 2)) * (x^n * x\<^sup>2) \<le> 1/2 * (1/2)^n * (1 * x\<^sup>2)"
hoelzl@50326
  1270
      by (rule mult_mono)
hoelzl@50326
  1271
        (rule mult_mono, simp_all add: power_le_one a b mult_nonneg_nonneg)
wenzelm@53015
  1272
    hence "inverse (fact (n + 2)) * x ^ (n + 2) \<le> (x\<^sup>2/2) * ((1/2)^n)"
hoelzl@50326
  1273
      unfolding power_add by (simp add: mult_ac del: fact_Suc) }
hoelzl@50326
  1274
  note aux1 = this
wenzelm@53015
  1275
  have "(\<lambda>n. x\<^sup>2 / 2 * (1 / 2) ^ n) sums (x\<^sup>2 / 2 * (1 / (1 - 1 / 2)))"
hoelzl@50326
  1276
    by (intro sums_mult geometric_sums, simp)
wenzelm@53076
  1277
  hence aux2: "(\<lambda>n. x\<^sup>2 / 2 * (1 / 2) ^ n) sums x\<^sup>2"
hoelzl@50326
  1278
    by simp
wenzelm@53076
  1279
  have "suminf (%n. inverse(fact (n+2)) * (x ^ (n+2))) <= x\<^sup>2"
hoelzl@50326
  1280
  proof -
hoelzl@50326
  1281
    have "suminf (%n. inverse(fact (n+2)) * (x ^ (n+2))) <=
wenzelm@53076
  1282
        suminf (%n. (x\<^sup>2/2) * ((1/2)^n))"
hoelzl@50326
  1283
      apply (rule summable_le)
hoelzl@50326
  1284
      apply (rule allI, rule aux1)
hoelzl@50326
  1285
      apply (rule summable_exp [THEN summable_ignore_initial_segment])
hoelzl@50326
  1286
      by (rule sums_summable, rule aux2)
wenzelm@53076
  1287
    also have "... = x\<^sup>2"
hoelzl@50326
  1288
      by (rule sums_unique [THEN sym], rule aux2)
hoelzl@50326
  1289
    finally show ?thesis .
hoelzl@50326
  1290
  qed
hoelzl@50326
  1291
  thus ?thesis unfolding exp_first_two_terms by auto
hoelzl@50326
  1292
qed
hoelzl@50326
  1293
hoelzl@50326
  1294
lemma ln_one_minus_pos_upper_bound: "0 <= x ==> x < 1 ==> ln (1 - x) <= - x"
hoelzl@50326
  1295
proof -
hoelzl@50326
  1296
  assume a: "0 <= (x::real)" and b: "x < 1"
wenzelm@53076
  1297
  have "(1 - x) * (1 + x + x\<^sup>2) = (1 - x^3)"
hoelzl@50326
  1298
    by (simp add: algebra_simps power2_eq_square power3_eq_cube)
hoelzl@50326
  1299
  also have "... <= 1"
hoelzl@50326
  1300
    by (auto simp add: a)
wenzelm@53076
  1301
  finally have "(1 - x) * (1 + x + x\<^sup>2) <= 1" .
wenzelm@53015
  1302
  moreover have c: "0 < 1 + x + x\<^sup>2"
hoelzl@50326
  1303
    by (simp add: add_pos_nonneg a)
wenzelm@53076
  1304
  ultimately have "1 - x <= 1 / (1 + x + x\<^sup>2)"
hoelzl@50326
  1305
    by (elim mult_imp_le_div_pos)
hoelzl@50326
  1306
  also have "... <= 1 / exp x"
hoelzl@50326
  1307
    apply (rule divide_left_mono)
hoelzl@50326
  1308
    apply (rule exp_bound, rule a)
hoelzl@50326
  1309
    apply (rule b [THEN less_imp_le])
hoelzl@50326
  1310
    apply simp
hoelzl@50326
  1311
    apply (rule mult_pos_pos)
hoelzl@50326
  1312
    apply (rule c)
hoelzl@50326
  1313
    apply simp
hoelzl@50326
  1314
    done
hoelzl@50326
  1315
  also have "... = exp (-x)"
hoelzl@50326
  1316
    by (auto simp add: exp_minus divide_inverse)
hoelzl@50326
  1317
  finally have "1 - x <= exp (- x)" .
hoelzl@50326
  1318
  also have "1 - x = exp (ln (1 - x))"
hoelzl@50326
  1319
  proof -
hoelzl@50326
  1320
    have "0 < 1 - x"
hoelzl@50326
  1321
      by (insert b, auto)
hoelzl@50326
  1322
    thus ?thesis
hoelzl@50326
  1323
      by (auto simp only: exp_ln_iff [THEN sym])
hoelzl@50326
  1324
  qed
hoelzl@50326
  1325
  finally have "exp (ln (1 - x)) <= exp (- x)" .
hoelzl@50326
  1326
  thus ?thesis by (auto simp only: exp_le_cancel_iff)
hoelzl@50326
  1327
qed
hoelzl@50326
  1328
hoelzl@50326
  1329
lemma exp_ge_add_one_self [simp]: "1 + (x::real) <= exp x"
hoelzl@50326
  1330
  apply (case_tac "0 <= x")
hoelzl@50326
  1331
  apply (erule exp_ge_add_one_self_aux)
hoelzl@50326
  1332
  apply (case_tac "x <= -1")
hoelzl@50326
  1333
  apply (subgoal_tac "1 + x <= 0")
hoelzl@50326
  1334
  apply (erule order_trans)
hoelzl@50326
  1335
  apply simp
hoelzl@50326
  1336
  apply simp
hoelzl@50326
  1337
  apply (subgoal_tac "1 + x = exp(ln (1 + x))")
hoelzl@50326
  1338
  apply (erule ssubst)
hoelzl@50326
  1339
  apply (subst exp_le_cancel_iff)
hoelzl@50326
  1340
  apply (subgoal_tac "ln (1 - (- x)) <= - (- x)")
hoelzl@50326
  1341
  apply simp
hoelzl@50326
  1342
  apply (rule ln_one_minus_pos_upper_bound)
hoelzl@50326
  1343
  apply auto
hoelzl@50326
  1344
done
hoelzl@50326
  1345
wenzelm@53076
  1346
lemma ln_one_plus_pos_lower_bound: "0 <= x ==> x <= 1 ==> x - x\<^sup>2 <= ln (1 + x)"
hoelzl@51527
  1347
proof -
hoelzl@51527
  1348
  assume a: "0 <= x" and b: "x <= 1"
wenzelm@53076
  1349
  have "exp (x - x\<^sup>2) = exp x / exp (x\<^sup>2)"
hoelzl@51527
  1350
    by (rule exp_diff)
wenzelm@53076
  1351
  also have "... <= (1 + x + x\<^sup>2) / exp (x \<^sup>2)"
hoelzl@51527
  1352
    apply (rule divide_right_mono) 
hoelzl@51527
  1353
    apply (rule exp_bound)
hoelzl@51527
  1354
    apply (rule a, rule b)
hoelzl@51527
  1355
    apply simp
hoelzl@51527
  1356
    done
wenzelm@53076
  1357
  also have "... <= (1 + x + x\<^sup>2) / (1 + x\<^sup>2)"
hoelzl@51527
  1358
    apply (rule divide_left_mono)
hoelzl@51527
  1359
    apply (simp add: exp_ge_add_one_self_aux)
hoelzl@51527
  1360
    apply (simp add: a)
hoelzl@51527
  1361
    apply (simp add: mult_pos_pos add_pos_nonneg)
hoelzl@51527
  1362
    done
hoelzl@51527
  1363
  also from a have "... <= 1 + x"
hoelzl@51527
  1364
    by (simp add: field_simps add_strict_increasing zero_le_mult_iff)
wenzelm@53076
  1365
  finally have "exp (x - x\<^sup>2) <= 1 + x" .
hoelzl@51527
  1366
  also have "... = exp (ln (1 + x))"
hoelzl@51527
  1367
  proof -
hoelzl@51527
  1368
    from a have "0 < 1 + x" by auto
hoelzl@51527
  1369
    thus ?thesis
hoelzl@51527
  1370
      by (auto simp only: exp_ln_iff [THEN sym])
hoelzl@51527
  1371
  qed
wenzelm@53076
  1372
  finally have "exp (x - x\<^sup>2) <= exp (ln (1 + x))" .
hoelzl@51527
  1373
  thus ?thesis by (auto simp only: exp_le_cancel_iff)
hoelzl@51527
  1374
qed
hoelzl@51527
  1375
hoelzl@51527
  1376
lemma aux5: "x < 1 ==> ln(1 - x) = - ln(1 + x / (1 - x))"
hoelzl@51527
  1377
proof -
hoelzl@51527
  1378
  assume a: "x < 1"
hoelzl@51527
  1379
  have "ln(1 - x) = - ln(1 / (1 - x))"
hoelzl@51527
  1380
  proof -
hoelzl@51527
  1381
    have "ln(1 - x) = - (- ln (1 - x))"
hoelzl@51527
  1382
      by auto
hoelzl@51527
  1383
    also have "- ln(1 - x) = ln 1 - ln(1 - x)"
hoelzl@51527
  1384
      by simp
hoelzl@51527
  1385
    also have "... = ln(1 / (1 - x))"
hoelzl@51527
  1386
      apply (rule ln_div [THEN sym])
hoelzl@51527
  1387
      by (insert a, auto)
hoelzl@51527
  1388
    finally show ?thesis .
hoelzl@51527
  1389
  qed
hoelzl@51527
  1390
  also have " 1 / (1 - x) = 1 + x / (1 - x)" using a by(simp add:field_simps)
hoelzl@51527
  1391
  finally show ?thesis .
hoelzl@51527
  1392
qed
hoelzl@51527
  1393
hoelzl@51527
  1394
lemma ln_one_minus_pos_lower_bound: "0 <= x ==> x <= (1 / 2) ==> 
wenzelm@53076
  1395
    - x - 2 * x\<^sup>2 <= ln (1 - x)"
hoelzl@51527
  1396
proof -
hoelzl@51527
  1397
  assume a: "0 <= x" and b: "x <= (1 / 2)"
hoelzl@51527
  1398
  from b have c: "x < 1"
hoelzl@51527
  1399
    by auto
hoelzl@51527
  1400
  then have "ln (1 - x) = - ln (1 + x / (1 - x))"
hoelzl@51527
  1401
    by (rule aux5)
hoelzl@51527
  1402
  also have "- (x / (1 - x)) <= ..."
hoelzl@51527
  1403
  proof - 
hoelzl@51527
  1404
    have "ln (1 + x / (1 - x)) <= x / (1 - x)"
hoelzl@51527
  1405
      apply (rule ln_add_one_self_le_self)
hoelzl@51527
  1406
      apply (rule divide_nonneg_pos)
hoelzl@51527
  1407
      by (insert a c, auto) 
hoelzl@51527
  1408
    thus ?thesis
hoelzl@51527
  1409
      by auto
hoelzl@51527
  1410
  qed
hoelzl@51527
  1411
  also have "- (x / (1 - x)) = -x / (1 - x)"
hoelzl@51527
  1412
    by auto
hoelzl@51527
  1413
  finally have d: "- x / (1 - x) <= ln (1 - x)" .
hoelzl@51527
  1414
  have "0 < 1 - x" using a b by simp
wenzelm@53076
  1415
  hence e: "-x - 2 * x\<^sup>2 <= - x / (1 - x)"
hoelzl@51527
  1416
    using mult_right_le_one_le[of "x*x" "2*x"] a b
hoelzl@51527
  1417
    by (simp add:field_simps power2_eq_square)
wenzelm@53076
  1418
  from e d show "- x - 2 * x\<^sup>2 <= ln (1 - x)"
hoelzl@51527
  1419
    by (rule order_trans)
hoelzl@51527
  1420
qed
hoelzl@51527
  1421
hoelzl@51527
  1422
lemma ln_add_one_self_le_self2: "-1 < x ==> ln(1 + x) <= x"
hoelzl@51527
  1423
  apply (subgoal_tac "ln (1 + x) \<le> ln (exp x)", simp)
hoelzl@51527
  1424
  apply (subst ln_le_cancel_iff)
hoelzl@51527
  1425
  apply auto
hoelzl@51527
  1426
done
hoelzl@51527
  1427
hoelzl@51527
  1428
lemma abs_ln_one_plus_x_minus_x_bound_nonneg:
wenzelm@53076
  1429
    "0 <= x ==> x <= 1 ==> abs(ln (1 + x) - x) <= x\<^sup>2"
hoelzl@51527
  1430
proof -
hoelzl@51527
  1431
  assume x: "0 <= x"
hoelzl@51527
  1432
  assume x1: "x <= 1"
hoelzl@51527
  1433
  from x have "ln (1 + x) <= x"
hoelzl@51527
  1434
    by (rule ln_add_one_self_le_self)
hoelzl@51527
  1435
  then have "ln (1 + x) - x <= 0" 
hoelzl@51527
  1436
    by simp
hoelzl@51527
  1437
  then have "abs(ln(1 + x) - x) = - (ln(1 + x) - x)"
hoelzl@51527
  1438
    by (rule abs_of_nonpos)
hoelzl@51527
  1439
  also have "... = x - ln (1 + x)" 
hoelzl@51527
  1440
    by simp
wenzelm@53076
  1441
  also have "... <= x\<^sup>2"
hoelzl@51527
  1442
  proof -
wenzelm@53076
  1443
    from x x1 have "x - x\<^sup>2 <= ln (1 + x)"
hoelzl@51527
  1444
      by (intro ln_one_plus_pos_lower_bound)
hoelzl@51527
  1445
    thus ?thesis
hoelzl@51527
  1446
      by simp
hoelzl@51527
  1447
  qed
hoelzl@51527
  1448
  finally show ?thesis .
hoelzl@51527
  1449
qed
hoelzl@51527
  1450
hoelzl@51527
  1451
lemma abs_ln_one_plus_x_minus_x_bound_nonpos:
wenzelm@53076
  1452
    "-(1 / 2) <= x ==> x <= 0 ==> abs(ln (1 + x) - x) <= 2 * x\<^sup>2"
hoelzl@51527
  1453
proof -
hoelzl@51527
  1454
  assume a: "-(1 / 2) <= x"
hoelzl@51527
  1455
  assume b: "x <= 0"
hoelzl@51527
  1456
  have "abs(ln (1 + x) - x) = x - ln(1 - (-x))" 
hoelzl@51527
  1457
    apply (subst abs_of_nonpos)
hoelzl@51527
  1458
    apply simp
hoelzl@51527
  1459
    apply (rule ln_add_one_self_le_self2)
hoelzl@51527
  1460
    using a apply auto
hoelzl@51527
  1461
    done
wenzelm@53076
  1462
  also have "... <= 2 * x\<^sup>2"
wenzelm@53076
  1463
    apply (subgoal_tac "- (-x) - 2 * (-x)\<^sup>2 <= ln (1 - (-x))")
hoelzl@51527
  1464
    apply (simp add: algebra_simps)
hoelzl@51527
  1465
    apply (rule ln_one_minus_pos_lower_bound)
hoelzl@51527
  1466
    using a b apply auto
hoelzl@51527
  1467
    done
hoelzl@51527
  1468
  finally show ?thesis .
hoelzl@51527
  1469
qed
hoelzl@51527
  1470
hoelzl@51527
  1471
lemma abs_ln_one_plus_x_minus_x_bound:
wenzelm@53076
  1472
    "abs x <= 1 / 2 ==> abs(ln (1 + x) - x) <= 2 * x\<^sup>2"
hoelzl@51527
  1473
  apply (case_tac "0 <= x")
hoelzl@51527
  1474
  apply (rule order_trans)
hoelzl@51527
  1475
  apply (rule abs_ln_one_plus_x_minus_x_bound_nonneg)
hoelzl@51527
  1476
  apply auto
hoelzl@51527
  1477
  apply (rule abs_ln_one_plus_x_minus_x_bound_nonpos)
hoelzl@51527
  1478
  apply auto
hoelzl@51527
  1479
done
hoelzl@51527
  1480
hoelzl@51527
  1481
lemma ln_x_over_x_mono: "exp 1 <= x ==> x <= y ==> (ln y / y) <= (ln x / x)"  
hoelzl@51527
  1482
proof -
hoelzl@51527
  1483
  assume x: "exp 1 <= x" "x <= y"
hoelzl@51527
  1484
  moreover have "0 < exp (1::real)" by simp
hoelzl@51527
  1485
  ultimately have a: "0 < x" and b: "0 < y"
hoelzl@51527
  1486
    by (fast intro: less_le_trans order_trans)+
hoelzl@51527
  1487
  have "x * ln y - x * ln x = x * (ln y - ln x)"
hoelzl@51527
  1488
    by (simp add: algebra_simps)
hoelzl@51527
  1489
  also have "... = x * ln(y / x)"
hoelzl@51527
  1490
    by (simp only: ln_div a b)
hoelzl@51527
  1491
  also have "y / x = (x + (y - x)) / x"
hoelzl@51527
  1492
    by simp
hoelzl@51527
  1493
  also have "... = 1 + (y - x) / x"
hoelzl@51527
  1494
    using x a by (simp add: field_simps)
hoelzl@51527
  1495
  also have "x * ln(1 + (y - x) / x) <= x * ((y - x) / x)"
hoelzl@51527
  1496
    apply (rule mult_left_mono)
hoelzl@51527
  1497
    apply (rule ln_add_one_self_le_self)
hoelzl@51527
  1498
    apply (rule divide_nonneg_pos)
hoelzl@51527
  1499
    using x a apply simp_all
hoelzl@51527
  1500
    done
hoelzl@51527
  1501
  also have "... = y - x" using a by simp
hoelzl@51527
  1502
  also have "... = (y - x) * ln (exp 1)" by simp
hoelzl@51527
  1503
  also have "... <= (y - x) * ln x"
hoelzl@51527
  1504
    apply (rule mult_left_mono)
hoelzl@51527
  1505
    apply (subst ln_le_cancel_iff)
hoelzl@51527
  1506
    apply fact
hoelzl@51527
  1507
    apply (rule a)
hoelzl@51527
  1508
    apply (rule x)
hoelzl@51527
  1509
    using x apply simp
hoelzl@51527
  1510
    done
hoelzl@51527
  1511
  also have "... = y * ln x - x * ln x"
hoelzl@51527
  1512
    by (rule left_diff_distrib)
hoelzl@51527
  1513
  finally have "x * ln y <= y * ln x"
hoelzl@51527
  1514
    by arith
hoelzl@51527
  1515
  then have "ln y <= (y * ln x) / x" using a by (simp add: field_simps)
hoelzl@51527
  1516
  also have "... = y * (ln x / x)" by simp
hoelzl@51527
  1517
  finally show ?thesis using b by (simp add: field_simps)
hoelzl@51527
  1518
qed
hoelzl@51527
  1519
hoelzl@51527
  1520
lemma ln_le_minus_one:
hoelzl@51527
  1521
  "0 < x \<Longrightarrow> ln x \<le> x - 1"
hoelzl@51527
  1522
  using exp_ge_add_one_self[of "ln x"] by simp
hoelzl@51527
  1523
hoelzl@51527
  1524
lemma ln_eq_minus_one:
hoelzl@51527
  1525
  assumes "0 < x" "ln x = x - 1" shows "x = 1"
hoelzl@51527
  1526
proof -
hoelzl@51527
  1527
  let "?l y" = "ln y - y + 1"
hoelzl@51527
  1528
  have D: "\<And>x. 0 < x \<Longrightarrow> DERIV ?l x :> (1 / x - 1)"
hoelzl@51527
  1529
    by (auto intro!: DERIV_intros)
hoelzl@51527
  1530
hoelzl@51527
  1531
  show ?thesis
hoelzl@51527
  1532
  proof (cases rule: linorder_cases)
hoelzl@51527
  1533
    assume "x < 1"
hoelzl@51527
  1534
    from dense[OF `x < 1`] obtain a where "x < a" "a < 1" by blast
hoelzl@51527
  1535
    from `x < a` have "?l x < ?l a"
hoelzl@51527
  1536
    proof (rule DERIV_pos_imp_increasing, safe)
hoelzl@51527
  1537
      fix y assume "x \<le> y" "y \<le> a"
hoelzl@51527
  1538
      with `0 < x` `a < 1` have "0 < 1 / y - 1" "0 < y"
hoelzl@51527
  1539
        by (auto simp: field_simps)
hoelzl@51527
  1540
      with D show "\<exists>z. DERIV ?l y :> z \<and> 0 < z"
hoelzl@51527
  1541
        by auto
hoelzl@51527
  1542
    qed
hoelzl@51527
  1543
    also have "\<dots> \<le> 0"
hoelzl@51527
  1544
      using ln_le_minus_one `0 < x` `x < a` by (auto simp: field_simps)
hoelzl@51527
  1545
    finally show "x = 1" using assms by auto
hoelzl@51527
  1546
  next
hoelzl@51527
  1547
    assume "1 < x"
hoelzl@51527
  1548
    from dense[OF `1 < x`] obtain a where "1 < a" "a < x" by blast
hoelzl@51527
  1549
    from `a < x` have "?l x < ?l a"
hoelzl@51527
  1550
    proof (rule DERIV_neg_imp_decreasing, safe)
hoelzl@51527
  1551
      fix y assume "a \<le> y" "y \<le> x"
hoelzl@51527
  1552
      with `1 < a` have "1 / y - 1 < 0" "0 < y"
hoelzl@51527
  1553
        by (auto simp: field_simps)
hoelzl@51527
  1554
      with D show "\<exists>z. DERIV ?l y :> z \<and> z < 0"
hoelzl@51527
  1555
        by blast
hoelzl@51527
  1556
    qed
hoelzl@51527
  1557
    also have "\<dots> \<le> 0"
hoelzl@51527
  1558
      using ln_le_minus_one `1 < a` by (auto simp: field_simps)
hoelzl@51527
  1559
    finally show "x = 1" using assms by auto
hoelzl@51527
  1560
  qed simp
hoelzl@51527
  1561
qed
hoelzl@51527
  1562
hoelzl@50326
  1563
lemma exp_at_bot: "(exp ---> (0::real)) at_bot"
hoelzl@50326
  1564
  unfolding tendsto_Zfun_iff
hoelzl@50326
  1565
proof (rule ZfunI, simp add: eventually_at_bot_dense)
hoelzl@50326
  1566
  fix r :: real assume "0 < r"
hoelzl@50326
  1567
  { fix x assume "x < ln r"
hoelzl@50326
  1568
    then have "exp x < exp (ln r)"
hoelzl@50326
  1569
      by simp
hoelzl@50326
  1570
    with `0 < r` have "exp x < r"
hoelzl@50326
  1571
      by simp }
hoelzl@50326
  1572
  then show "\<exists>k. \<forall>n<k. exp n < r" by auto
hoelzl@50326
  1573
qed
hoelzl@50326
  1574
hoelzl@50326
  1575
lemma exp_at_top: "LIM x at_top. exp x :: real :> at_top"
hoelzl@50346
  1576
  by (rule filterlim_at_top_at_top[where Q="\<lambda>x. True" and P="\<lambda>x. 0 < x" and g="ln"])
hoelzl@50346
  1577
     (auto intro: eventually_gt_at_top)
hoelzl@50326
  1578
hoelzl@50326
  1579
lemma ln_at_0: "LIM x at_right 0. ln x :> at_bot"
hoelzl@50346
  1580
  by (rule filterlim_at_bot_at_right[where Q="\<lambda>x. 0 < x" and P="\<lambda>x. True" and g="exp"])
hoelzl@51641
  1581
     (auto simp: eventually_at_filter)
hoelzl@50326
  1582
hoelzl@50326
  1583
lemma ln_at_top: "LIM x at_top. ln x :> at_top"
hoelzl@50346
  1584
  by (rule filterlim_at_top_at_top[where Q="\<lambda>x. 0 < x" and P="\<lambda>x. True" and g="exp"])
hoelzl@50346
  1585
     (auto intro: eventually_gt_at_top)
hoelzl@50326
  1586
hoelzl@50347
  1587
lemma tendsto_power_div_exp_0: "((\<lambda>x. x ^ k / exp x) ---> (0::real)) at_top"
hoelzl@50347
  1588
proof (induct k)
hoelzl@50347
  1589
  show "((\<lambda>x. x ^ 0 / exp x) ---> (0::real)) at_top"
hoelzl@50347
  1590
    by (simp add: inverse_eq_divide[symmetric])
hoelzl@50347
  1591
       (metis filterlim_compose[OF tendsto_inverse_0] exp_at_top filterlim_mono
hoelzl@50347
  1592
              at_top_le_at_infinity order_refl)
hoelzl@50347
  1593
next
hoelzl@50347
  1594
  case (Suc k)
hoelzl@50347
  1595
  show ?case
hoelzl@50347
  1596
  proof (rule lhospital_at_top_at_top)
hoelzl@50347
  1597
    show "eventually (\<lambda>x. DERIV (\<lambda>x. x ^ Suc k) x :> (real (Suc k) * x^k)) at_top"
hoelzl@50347
  1598
      by eventually_elim (intro DERIV_intros, simp, simp)
hoelzl@50347
  1599
    show "eventually (\<lambda>x. DERIV exp x :> exp x) at_top"
hoelzl@50347
  1600
      by eventually_elim (auto intro!: DERIV_intros)
hoelzl@50347
  1601
    show "eventually (\<lambda>x. exp x \<noteq> 0) at_top"
hoelzl@50347
  1602
      by auto
hoelzl@50347
  1603
    from tendsto_mult[OF tendsto_const Suc, of "real (Suc k)"]
hoelzl@50347
  1604
    show "((\<lambda>x. real (Suc k) * x ^ k / exp x) ---> 0) at_top"
hoelzl@50347
  1605
      by simp
hoelzl@50347
  1606
  qed (rule exp_at_top)
hoelzl@50347
  1607
qed
hoelzl@50347
  1608
hoelzl@51527
  1609
hoelzl@51527
  1610
definition
hoelzl@51527
  1611
  powr  :: "[real,real] => real"     (infixr "powr" 80) where
hoelzl@51527
  1612
    --{*exponentation with real exponent*}
hoelzl@51527
  1613
  "x powr a = exp(a * ln x)"
hoelzl@51527
  1614
hoelzl@51527
  1615
definition
hoelzl@51527
  1616
  log :: "[real,real] => real" where
hoelzl@51527
  1617
    --{*logarithm of @{term x} to base @{term a}*}
hoelzl@51527
  1618
  "log a x = ln x / ln a"
hoelzl@51527
  1619
hoelzl@51527
  1620
hoelzl@51527
  1621
lemma tendsto_log [tendsto_intros]:
hoelzl@51527
  1622
  "\<lbrakk>(f ---> a) F; (g ---> b) F; 0 < a; a \<noteq> 1; 0 < b\<rbrakk> \<Longrightarrow> ((\<lambda>x. log (f x) (g x)) ---> log a b) F"
hoelzl@51527
  1623
  unfolding log_def by (intro tendsto_intros) auto
hoelzl@51527
  1624
hoelzl@51527
  1625
lemma continuous_log:
hoelzl@51527
  1626
  assumes "continuous F f" and "continuous F g" and "0 < f (Lim F (\<lambda>x. x))" and "f (Lim F (\<lambda>x. x)) \<noteq> 1" and "0 < g (Lim F (\<lambda>x. x))"
hoelzl@51527
  1627
  shows "continuous F (\<lambda>x. log (f x) (g x))"
hoelzl@51527
  1628
  using assms unfolding continuous_def by (rule tendsto_log)
hoelzl@51527
  1629
hoelzl@51527
  1630
lemma continuous_at_within_log[continuous_intros]:
hoelzl@51527
  1631
  assumes "continuous (at a within s) f" "continuous (at a within s) g" and "0 < f a" and "f a \<noteq> 1" and "0 < g a"
hoelzl@51527
  1632
  shows "continuous (at a within s) (\<lambda>x. log (f x) (g x))"
hoelzl@51527
  1633
  using assms unfolding continuous_within by (rule tendsto_log)
hoelzl@51527
  1634
hoelzl@51527
  1635
lemma isCont_log[continuous_intros, simp]:
hoelzl@51527
  1636
  assumes "isCont f a" "isCont g a" "0 < f a" "f a \<noteq> 1" "0 < g a"
hoelzl@51527
  1637
  shows "isCont (\<lambda>x. log (f x) (g x)) a"
hoelzl@51527
  1638
  using assms unfolding continuous_at by (rule tendsto_log)
hoelzl@51527
  1639
hoelzl@51527
  1640
lemma continuous_on_log[continuous_on_intros]:
hoelzl@51527
  1641
  assumes "continuous_on s f" "continuous_on s g" and "\<forall>x\<in>s. 0 < f x" "\<forall>x\<in>s. f x \<noteq> 1" "\<forall>x\<in>s. 0 < g x"
hoelzl@51527
  1642
  shows "continuous_on s (\<lambda>x. log (f x) (g x))"
hoelzl@51527
  1643
  using assms unfolding continuous_on_def by (fast intro: tendsto_log)
hoelzl@51527
  1644
hoelzl@51527
  1645
lemma powr_one_eq_one [simp]: "1 powr a = 1"
hoelzl@51527
  1646
by (simp add: powr_def)
hoelzl@51527
  1647
hoelzl@51527
  1648
lemma powr_zero_eq_one [simp]: "x powr 0 = 1"
hoelzl@51527
  1649
by (simp add: powr_def)
hoelzl@51527
  1650
hoelzl@51527
  1651
lemma powr_one_gt_zero_iff [simp]: "(x powr 1 = x) = (0 < x)"
hoelzl@51527
  1652
by (simp add: powr_def)
hoelzl@51527
  1653
declare powr_one_gt_zero_iff [THEN iffD2, simp]
hoelzl@51527
  1654
hoelzl@51527
  1655
lemma powr_mult: 
hoelzl@51527
  1656
      "[| 0 < x; 0 < y |] ==> (x * y) powr a = (x powr a) * (y powr a)"
hoelzl@51527
  1657
by (simp add: powr_def exp_add [symmetric] ln_mult distrib_left)
hoelzl@51527
  1658
hoelzl@51527
  1659
lemma powr_gt_zero [simp]: "0 < x powr a"
hoelzl@51527
  1660
by (simp add: powr_def)
hoelzl@51527
  1661
hoelzl@51527
  1662
lemma powr_ge_pzero [simp]: "0 <= x powr y"
hoelzl@51527
  1663
by (rule order_less_imp_le, rule powr_gt_zero)
hoelzl@51527
  1664
hoelzl@51527
  1665
lemma powr_not_zero [simp]: "x powr a \<noteq> 0"
hoelzl@51527
  1666
by (simp add: powr_def)
hoelzl@51527
  1667
hoelzl@51527
  1668
lemma powr_divide:
hoelzl@51527
  1669
     "[| 0 < x; 0 < y |] ==> (x / y) powr a = (x powr a)/(y powr a)"
hoelzl@51527
  1670
apply (simp add: divide_inverse positive_imp_inverse_positive powr_mult)
hoelzl@51527
  1671
apply (simp add: powr_def exp_minus [symmetric] exp_add [symmetric] ln_inverse)
hoelzl@51527
  1672
done
hoelzl@51527
  1673
hoelzl@51527
  1674
lemma powr_divide2: "x powr a / x powr b = x powr (a - b)"
hoelzl@51527
  1675
  apply (simp add: powr_def)
hoelzl@51527
  1676
  apply (subst exp_diff [THEN sym])
hoelzl@51527
  1677
  apply (simp add: left_diff_distrib)
hoelzl@51527
  1678
done
hoelzl@51527
  1679
hoelzl@51527
  1680
lemma powr_add: "x powr (a + b) = (x powr a) * (x powr b)"
hoelzl@51527
  1681
by (simp add: powr_def exp_add [symmetric] distrib_right)
hoelzl@51527
  1682
hoelzl@51527
  1683
lemma powr_mult_base:
hoelzl@51527
  1684
  "0 < x \<Longrightarrow>x * x powr y = x powr (1 + y)"
hoelzl@51527
  1685
using assms by (auto simp: powr_add)
hoelzl@51527
  1686
hoelzl@51527
  1687
lemma powr_powr: "(x powr a) powr b = x powr (a * b)"
hoelzl@51527
  1688
by (simp add: powr_def)
hoelzl@51527
  1689
hoelzl@51527
  1690
lemma powr_powr_swap: "(x powr a) powr b = (x powr b) powr a"
hoelzl@51527
  1691
by (simp add: powr_powr mult_commute)
hoelzl@51527
  1692
hoelzl@51527
  1693
lemma powr_minus: "x powr (-a) = inverse (x powr a)"
hoelzl@51527
  1694
by (simp add: powr_def exp_minus [symmetric])
hoelzl@51527
  1695
hoelzl@51527
  1696
lemma powr_minus_divide: "x powr (-a) = 1/(x powr a)"
hoelzl@51527
  1697
by (simp add: divide_inverse powr_minus)
hoelzl@51527
  1698
hoelzl@51527
  1699
lemma powr_less_mono: "[| a < b; 1 < x |] ==> x powr a < x powr b"
hoelzl@51527
  1700
by (simp add: powr_def)
hoelzl@51527
  1701
hoelzl@51527
  1702
lemma powr_less_cancel: "[| x powr a < x powr b; 1 < x |] ==> a < b"
hoelzl@51527
  1703
by (simp add: powr_def)
hoelzl@51527
  1704
hoelzl@51527
  1705
lemma powr_less_cancel_iff [simp]: "1 < x ==> (x powr a < x powr b) = (a < b)"
hoelzl@51527
  1706
by (blast intro: powr_less_cancel powr_less_mono)
hoelzl@51527
  1707
hoelzl@51527
  1708
lemma powr_le_cancel_iff [simp]: "1 < x ==> (x powr a \<le> x powr b) = (a \<le> b)"
hoelzl@51527
  1709
by (simp add: linorder_not_less [symmetric])
hoelzl@51527
  1710
hoelzl@51527
  1711
lemma log_ln: "ln x = log (exp(1)) x"
hoelzl@51527
  1712
by (simp add: log_def)
hoelzl@51527
  1713
hoelzl@51527
  1714
lemma DERIV_log: assumes "x > 0" shows "DERIV (\<lambda>y. log b y) x :> 1 / (ln b * x)"
hoelzl@51527
  1715
proof -
hoelzl@51527
  1716
  def lb \<equiv> "1 / ln b"
hoelzl@51527
  1717
  moreover have "DERIV (\<lambda>y. lb * ln y) x :> lb / x"
hoelzl@51527
  1718
    using `x > 0` by (auto intro!: DERIV_intros)
hoelzl@51527
  1719
  ultimately show ?thesis
hoelzl@51527
  1720
    by (simp add: log_def)
hoelzl@51527
  1721
qed
hoelzl@51527
  1722
hoelzl@51527
  1723
lemmas DERIV_log[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
hoelzl@51527
  1724
hoelzl@51527
  1725
lemma powr_log_cancel [simp]:
hoelzl@51527
  1726
     "[| 0 < a; a \<noteq> 1; 0 < x |] ==> a powr (log a x) = x"
hoelzl@51527
  1727
by (simp add: powr_def log_def)
hoelzl@51527
  1728
hoelzl@51527
  1729
lemma log_powr_cancel [simp]: "[| 0 < a; a \<noteq> 1 |] ==> log a (a powr y) = y"
hoelzl@51527
  1730
by (simp add: log_def powr_def)
hoelzl@51527
  1731
hoelzl@51527
  1732
lemma log_mult: 
hoelzl@51527
  1733
     "[| 0 < a; a \<noteq> 1; 0 < x; 0 < y |]  
hoelzl@51527
  1734
      ==> log a (x * y) = log a x + log a y"
hoelzl@51527
  1735
by (simp add: log_def ln_mult divide_inverse distrib_right)
hoelzl@51527
  1736
hoelzl@51527
  1737
lemma log_eq_div_ln_mult_log: 
hoelzl@51527
  1738
     "[| 0 < a; a \<noteq> 1; 0 < b; b \<noteq> 1; 0 < x |]  
hoelzl@51527
  1739
      ==> log a x = (ln b/ln a) * log b x"
hoelzl@51527
  1740
by (simp add: log_def divide_inverse)
hoelzl@51527
  1741
hoelzl@51527
  1742
text{*Base 10 logarithms*}
hoelzl@51527
  1743
lemma log_base_10_eq1: "0 < x ==> log 10 x = (ln (exp 1) / ln 10) * ln x"
hoelzl@51527
  1744
by (simp add: log_def)
hoelzl@51527
  1745
hoelzl@51527
  1746
lemma log_base_10_eq2: "0 < x ==> log 10 x = (log 10 (exp 1)) * ln x"
hoelzl@51527
  1747
by (simp add: log_def)
hoelzl@51527
  1748
hoelzl@51527
  1749
lemma log_one [simp]: "log a 1 = 0"
hoelzl@51527
  1750
by (simp add: log_def)
hoelzl@51527
  1751
hoelzl@51527
  1752
lemma log_eq_one [simp]: "[| 0 < a; a \<noteq> 1 |] ==> log a a = 1"
hoelzl@51527
  1753
by (simp add: log_def)
hoelzl@51527
  1754
hoelzl@51527
  1755
lemma log_inverse:
hoelzl@51527
  1756
     "[| 0 < a; a \<noteq> 1; 0 < x |] ==> log a (inverse x) = - log a x"
hoelzl@51527
  1757
apply (rule_tac a1 = "log a x" in add_left_cancel [THEN iffD1])
hoelzl@51527
  1758
apply (simp add: log_mult [symmetric])
hoelzl@51527
  1759
done
hoelzl@51527
  1760
hoelzl@51527
  1761
lemma log_divide:
hoelzl@51527
  1762
     "[|0 < a; a \<noteq> 1; 0 < x; 0 < y|] ==> log a (x/y) = log a x - log a y"
hoelzl@51527
  1763
by (simp add: log_mult divide_inverse log_inverse)
hoelzl@51527
  1764
hoelzl@51527
  1765
lemma log_less_cancel_iff [simp]:
hoelzl@51527
  1766
     "[| 1 < a; 0 < x; 0 < y |] ==> (log a x < log a y) = (x < y)"
hoelzl@51527
  1767
apply safe
hoelzl@51527
  1768
apply (rule_tac [2] powr_less_cancel)
hoelzl@51527
  1769
apply (drule_tac a = "log a x" in powr_less_mono, auto)
hoelzl@51527
  1770
done
hoelzl@51527
  1771
hoelzl@51527
  1772
lemma log_inj: assumes "1 < b" shows "inj_on (log b) {0 <..}"
hoelzl@51527
  1773
proof (rule inj_onI, simp)
hoelzl@51527
  1774
  fix x y assume pos: "0 < x" "0 < y" and *: "log b x = log b y"
hoelzl@51527
  1775
  show "x = y"
hoelzl@51527
  1776
  proof (cases rule: linorder_cases)
hoelzl@51527
  1777
    assume "x < y" hence "log b x < log b y"
hoelzl@51527
  1778
      using log_less_cancel_iff[OF `1 < b`] pos by simp
hoelzl@51527
  1779
    thus ?thesis using * by simp
hoelzl@51527
  1780
  next
hoelzl@51527
  1781
    assume "y < x" hence "log b y < log b x"
hoelzl@51527
  1782
      using log_less_cancel_iff[OF `1 < b`] pos by simp
hoelzl@51527
  1783
    thus ?thesis using * by simp
hoelzl@51527
  1784
  qed simp
hoelzl@51527
  1785
qed
hoelzl@51527
  1786
hoelzl@51527
  1787
lemma log_le_cancel_iff [simp]:
hoelzl@51527
  1788
     "[| 1 < a; 0 < x; 0 < y |] ==> (log a x \<le> log a y) = (x \<le> y)"
hoelzl@51527
  1789
by (simp add: linorder_not_less [symmetric])
hoelzl@51527
  1790
hoelzl@51527
  1791
lemma zero_less_log_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> 0 < log a x \<longleftrightarrow> 1 < x"
hoelzl@51527
  1792
  using log_less_cancel_iff[of a 1 x] by simp
hoelzl@51527
  1793
hoelzl@51527
  1794
lemma zero_le_log_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> 0 \<le> log a x \<longleftrightarrow> 1 \<le> x"
hoelzl@51527
  1795
  using log_le_cancel_iff[of a 1 x] by simp
hoelzl@51527
  1796
hoelzl@51527
  1797
lemma log_less_zero_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> log a x < 0 \<longleftrightarrow> x < 1"
hoelzl@51527
  1798
  using log_less_cancel_iff[of a x 1] by simp
hoelzl@51527
  1799
hoelzl@51527
  1800
lemma log_le_zero_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> log a x \<le> 0 \<longleftrightarrow> x \<le> 1"
hoelzl@51527
  1801
  using log_le_cancel_iff[of a x 1] by simp
hoelzl@51527
  1802
hoelzl@51527
  1803
lemma one_less_log_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> 1 < log a x \<longleftrightarrow> a < x"
hoelzl@51527
  1804
  using log_less_cancel_iff[of a a x] by simp
hoelzl@51527
  1805
hoelzl@51527
  1806
lemma one_le_log_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> 1 \<le> log a x \<longleftrightarrow> a \<le> x"
hoelzl@51527
  1807
  using log_le_cancel_iff[of a a x] by simp
hoelzl@51527
  1808
hoelzl@51527
  1809
lemma log_less_one_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> log a x < 1 \<longleftrightarrow> x < a"
hoelzl@51527
  1810
  using log_less_cancel_iff[of a x a] by simp
hoelzl@51527
  1811
hoelzl@51527
  1812
lemma log_le_one_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> log a x \<le> 1 \<longleftrightarrow> x \<le> a"
hoelzl@51527
  1813
  using log_le_cancel_iff[of a x a] by simp
hoelzl@51527
  1814
hoelzl@51527
  1815
lemma powr_realpow: "0 < x ==> x powr (real n) = x^n"
hoelzl@51527
  1816
  apply (induct n, simp)
hoelzl@51527
  1817
  apply (subgoal_tac "real(Suc n) = real n + 1")
hoelzl@51527
  1818
  apply (erule ssubst)
hoelzl@51527
  1819
  apply (subst powr_add, simp, simp)
hoelzl@51527
  1820
done
hoelzl@51527
  1821
noschinl@52139
  1822
lemma powr_realpow_numeral: "0 < x \<Longrightarrow> x powr (numeral n :: real) = x^(numeral n)"
noschinl@52139
  1823
  unfolding real_of_nat_numeral[symmetric] by (rule powr_realpow)
noschinl@52139
  1824
hoelzl@51527
  1825
lemma powr_realpow2: "0 <= x ==> 0 < n ==> x^n = (if (x = 0) then 0 else x powr (real n))"
hoelzl@51527
  1826
  apply (case_tac "x = 0", simp, simp)
hoelzl@51527
  1827
  apply (rule powr_realpow [THEN sym], simp)
hoelzl@51527
  1828
done
hoelzl@51527
  1829
hoelzl@51527
  1830
lemma powr_int:
hoelzl@51527
  1831
  assumes "x > 0"
hoelzl@51527
  1832
  shows "x powr i = (if i \<ge> 0 then x ^ nat i else 1 / x ^ nat (-i))"
hoelzl@51527
  1833
proof cases
hoelzl@51527
  1834
  assume "i < 0"
hoelzl@51527
  1835
  have r: "x powr i = 1 / x powr (-i)" by (simp add: powr_minus field_simps)
hoelzl@51527
  1836
  show ?thesis using `i < 0` `x > 0` by (simp add: r field_simps powr_realpow[symmetric])
hoelzl@51527
  1837
qed (simp add: assms powr_realpow[symmetric])
hoelzl@51527
  1838
hoelzl@51527
  1839
lemma powr_numeral: "0 < x \<Longrightarrow> x powr numeral n = x^numeral n"
hoelzl@51527
  1840
  using powr_realpow[of x "numeral n"] by simp
hoelzl@51527
  1841
hoelzl@51527
  1842
lemma powr_neg_numeral: "0 < x \<Longrightarrow> x powr neg_numeral n = 1 / x^numeral n"
hoelzl@51527
  1843
  using powr_int[of x "neg_numeral n"] by simp
hoelzl@51527
  1844
hoelzl@51527
  1845
lemma root_powr_inverse:
hoelzl@51527
  1846
  "0 < n \<Longrightarrow> 0 < x \<Longrightarrow> root n x = x powr (1/n)"
hoelzl@51527
  1847
  by (rule real_root_pos_unique) (auto simp: powr_realpow[symmetric] powr_powr)
hoelzl@51527
  1848
hoelzl@51527
  1849
lemma ln_powr: "0 < x ==> 0 < y ==> ln(x powr y) = y * ln x"
hoelzl@51527
  1850
by (unfold powr_def, simp)
hoelzl@51527
  1851
hoelzl@51527
  1852
lemma log_powr: "0 < x ==> 0 \<le> y ==> log b (x powr y) = y * log b x"
hoelzl@51527
  1853
  apply (case_tac "y = 0")
hoelzl@51527
  1854
  apply force
hoelzl@51527
  1855
  apply (auto simp add: log_def ln_powr field_simps)
hoelzl@51527
  1856
done
hoelzl@51527
  1857
hoelzl@51527
  1858
lemma log_nat_power: "0 < x ==> log b (x^n) = real n * log b x"
hoelzl@51527
  1859
  apply (subst powr_realpow [symmetric])
hoelzl@51527
  1860
  apply (auto simp add: log_powr)
hoelzl@51527
  1861
done
hoelzl@51527
  1862
hoelzl@51527
  1863
lemma ln_bound: "1 <= x ==> ln x <= x"
hoelzl@51527
  1864
  apply (subgoal_tac "ln(1 + (x - 1)) <= x - 1")
hoelzl@51527
  1865
  apply simp
hoelzl@51527
  1866
  apply (rule ln_add_one_self_le_self, simp)
hoelzl@51527
  1867
done
hoelzl@51527
  1868
hoelzl@51527
  1869
lemma powr_mono: "a <= b ==> 1 <= x ==> x powr a <= x powr b"
hoelzl@51527
  1870
  apply (case_tac "x = 1", simp)
hoelzl@51527
  1871
  apply (case_tac "a = b", simp)
hoelzl@51527
  1872
  apply (rule order_less_imp_le)
hoelzl@51527
  1873
  apply (rule powr_less_mono, auto)
hoelzl@51527
  1874
done
hoelzl@51527
  1875
hoelzl@51527
  1876
lemma ge_one_powr_ge_zero: "1 <= x ==> 0 <= a ==> 1 <= x powr a"
hoelzl@51527
  1877
  apply (subst powr_zero_eq_one [THEN sym])
hoelzl@51527
  1878
  apply (rule powr_mono, assumption+)
hoelzl@51527
  1879
done
hoelzl@51527
  1880
hoelzl@51527
  1881
lemma powr_less_mono2: "0 < a ==> 0 < x ==> x < y ==> x powr a <
hoelzl@51527
  1882
    y powr a"
hoelzl@51527
  1883
  apply (unfold powr_def)
hoelzl@51527
  1884
  apply (rule exp_less_mono)
hoelzl@51527
  1885
  apply (rule mult_strict_left_mono)
hoelzl@51527
  1886
  apply (subst ln_less_cancel_iff, assumption)
hoelzl@51527
  1887
  apply (rule order_less_trans)
hoelzl@51527
  1888
  prefer 2
hoelzl@51527
  1889
  apply assumption+
hoelzl@51527
  1890
done
hoelzl@51527
  1891
hoelzl@51527
  1892
lemma powr_less_mono2_neg: "a < 0 ==> 0 < x ==> x < y ==> y powr a <
hoelzl@51527
  1893
    x powr a"
hoelzl@51527
  1894
  apply (unfold powr_def)
hoelzl@51527
  1895
  apply (rule exp_less_mono)
hoelzl@51527
  1896
  apply (rule mult_strict_left_mono_neg)
hoelzl@51527
  1897
  apply (subst ln_less_cancel_iff)
hoelzl@51527
  1898
  apply assumption
hoelzl@51527
  1899
  apply (rule order_less_trans)
hoelzl@51527
  1900
  prefer 2
hoelzl@51527
  1901
  apply assumption+
hoelzl@51527
  1902
done
hoelzl@51527
  1903
hoelzl@51527
  1904
lemma powr_mono2: "0 <= a ==> 0 < x ==> x <= y ==> x powr a <= y powr a"
hoelzl@51527
  1905
  apply (case_tac "a = 0", simp)
hoelzl@51527
  1906
  apply (case_tac "x = y", simp)
hoelzl@51527
  1907
  apply (rule order_less_imp_le)
hoelzl@51527
  1908
  apply (rule powr_less_mono2, auto)
hoelzl@51527
  1909
done
hoelzl@51527
  1910
hoelzl@51527
  1911
lemma powr_inj:
hoelzl@51527
  1912
  "0 < a \<Longrightarrow> a \<noteq> 1 \<Longrightarrow> a powr x = a powr y \<longleftrightarrow> x = y"
hoelzl@51527
  1913
  unfolding powr_def exp_inj_iff by simp
hoelzl@51527
  1914
hoelzl@51527
  1915
lemma ln_powr_bound: "1 <= x ==> 0 < a ==> ln x <= (x powr a) / a"
hoelzl@51527
  1916
  apply (rule mult_imp_le_div_pos)
hoelzl@51527
  1917
  apply (assumption)
hoelzl@51527
  1918
  apply (subst mult_commute)
hoelzl@51527
  1919
  apply (subst ln_powr [THEN sym])
hoelzl@51527
  1920
  apply auto
hoelzl@51527
  1921
  apply (rule ln_bound)
hoelzl@51527
  1922
  apply (erule ge_one_powr_ge_zero)
hoelzl@51527
  1923
  apply (erule order_less_imp_le)
hoelzl@51527
  1924
done
hoelzl@51527
  1925
hoelzl@51527
  1926
lemma ln_powr_bound2:
hoelzl@51527
  1927
  assumes "1 < x" and "0 < a"
hoelzl@51527
  1928
  shows "(ln x) powr a <= (a powr a) * x"
hoelzl@51527
  1929
proof -
hoelzl@51527
  1930
  from assms have "ln x <= (x powr (1 / a)) / (1 / a)"
hoelzl@51527
  1931
    apply (intro ln_powr_bound)
hoelzl@51527
  1932
    apply (erule order_less_imp_le)
hoelzl@51527
  1933
    apply (rule divide_pos_pos)
hoelzl@51527
  1934
    apply simp_all
hoelzl@51527
  1935
    done
hoelzl@51527
  1936
  also have "... = a * (x powr (1 / a))"
hoelzl@51527
  1937
    by simp
hoelzl@51527
  1938
  finally have "(ln x) powr a <= (a * (x powr (1 / a))) powr a"
hoelzl@51527
  1939
    apply (intro powr_mono2)
hoelzl@51527
  1940
    apply (rule order_less_imp_le, rule assms)
hoelzl@51527
  1941
    apply (rule ln_gt_zero)
hoelzl@51527
  1942
    apply (rule assms)
hoelzl@51527
  1943
    apply assumption
hoelzl@51527
  1944
    done
hoelzl@51527
  1945
  also have "... = (a powr a) * ((x powr (1 / a)) powr a)"
hoelzl@51527
  1946
    apply (rule powr_mult)
hoelzl@51527
  1947
    apply (rule assms)
hoelzl@51527
  1948
    apply (rule powr_gt_zero)
hoelzl@51527
  1949
    done
hoelzl@51527
  1950
  also have "(x powr (1 / a)) powr a = x powr ((1 / a) * a)"
hoelzl@51527
  1951
    by (rule powr_powr)
hoelzl@51527
  1952
  also have "... = x"
hoelzl@51527
  1953
    apply simp
hoelzl@51527
  1954
    apply (subgoal_tac "a ~= 0")
hoelzl@51527
  1955
    using assms apply auto
hoelzl@51527
  1956
    done
hoelzl@51527
  1957
  finally show ?thesis .
hoelzl@51527
  1958
qed
hoelzl@51527
  1959
hoelzl@51527
  1960
lemma tendsto_powr [tendsto_intros]:
hoelzl@51527
  1961
  "\<lbrakk>(f ---> a) F; (g ---> b) F; 0 < a\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x powr g x) ---> a powr b) F"
hoelzl@51527
  1962
  unfolding powr_def by (intro tendsto_intros)
hoelzl@51527
  1963
hoelzl@51527
  1964
lemma continuous_powr:
hoelzl@51527
  1965
  assumes "continuous F f" and "continuous F g" and "0 < f (Lim F (\<lambda>x. x))"
hoelzl@51527
  1966
  shows "continuous F (\<lambda>x. (f x) powr (g x))"
hoelzl@51527
  1967
  using assms unfolding continuous_def by (rule tendsto_powr)
hoelzl@51527
  1968
hoelzl@51527
  1969
lemma continuous_at_within_powr[continuous_intros]:
hoelzl@51527
  1970
  assumes "continuous (at a within s) f" "continuous (at a within s) g" and "0 < f a"
hoelzl@51527
  1971
  shows "continuous (at a within s) (\<lambda>x. (f x) powr (g x))"
hoelzl@51527
  1972
  using assms unfolding continuous_within by (rule tendsto_powr)
hoelzl@51527
  1973
hoelzl@51527
  1974
lemma isCont_powr[continuous_intros, simp]:
hoelzl@51527
  1975
  assumes "isCont f a" "isCont g a" "0 < f a"
hoelzl@51527
  1976
  shows "isCont (\<lambda>x. (f x) powr g x) a"
hoelzl@51527
  1977
  using assms unfolding continuous_at by (rule tendsto_powr)
hoelzl@51527
  1978
hoelzl@51527
  1979
lemma continuous_on_powr[continuous_on_intros]:
hoelzl@51527
  1980
  assumes "continuous_on s f" "continuous_on s g" and "\<forall>x\<in>s. 0 < f x"
hoelzl@51527
  1981
  shows "continuous_on s (\<lambda>x. (f x) powr (g x))"
hoelzl@51527
  1982
  using assms unfolding continuous_on_def by (fast intro: tendsto_powr)
hoelzl@51527
  1983
hoelzl@51527
  1984
(* FIXME: generalize by replacing d by with g x and g ---> d? *)
hoelzl@51527
  1985
lemma tendsto_zero_powrI:
hoelzl@51527
  1986
  assumes "eventually (\<lambda>x. 0 < f x ) F" and "(f ---> 0) F"
hoelzl@51527
  1987
  assumes "0 < d"
hoelzl@51527
  1988
  shows "((\<lambda>x. f x powr d) ---> 0) F"
hoelzl@51527
  1989
proof (rule tendstoI)
hoelzl@51527
  1990
  fix e :: real assume "0 < e"
hoelzl@51527
  1991
  def Z \<equiv> "e powr (1 / d)"
hoelzl@51527
  1992
  with `0 < e` have "0 < Z" by simp
hoelzl@51527
  1993
  with assms have "eventually (\<lambda>x. 0 < f x \<and> dist (f x) 0 < Z) F"
hoelzl@51527
  1994
    by (intro eventually_conj tendstoD)
hoelzl@51527
  1995
  moreover
hoelzl@51527
  1996
  from assms have "\<And>x. 0 < x \<and> dist x 0 < Z \<Longrightarrow> x powr d < Z powr d"
hoelzl@51527
  1997
    by (intro powr_less_mono2) (auto simp: dist_real_def)
hoelzl@51527
  1998
  with assms `0 < e` have "\<And>x. 0 < x \<and> dist x 0 < Z \<Longrightarrow> dist (x powr d) 0 < e"
hoelzl@51527
  1999
    unfolding dist_real_def Z_def by (auto simp: powr_powr)
hoelzl@51527
  2000
  ultimately
hoelzl@51527
  2001
  show "eventually (\<lambda>x. dist (f x powr d) 0 < e) F" by (rule eventually_elim1)
hoelzl@51527
  2002
qed
hoelzl@51527
  2003
hoelzl@51527
  2004
lemma tendsto_neg_powr:
hoelzl@51527
  2005
  assumes "s < 0" and "LIM x F. f x :> at_top"
hoelzl@51527
  2006
  shows "((\<lambda>x. f x powr s) ---> 0) F"
hoelzl@51527
  2007
proof (rule tendstoI)
hoelzl@51527
  2008
  fix e :: real assume "0 < e"
hoelzl@51527
  2009
  def Z \<equiv> "e powr (1 / s)"
hoelzl@51527
  2010
  from assms have "eventually (\<lambda>x. Z < f x) F"
hoelzl@51527
  2011
    by (simp add: filterlim_at_top_dense)
hoelzl@51527
  2012
  moreover
hoelzl@51527
  2013
  from assms have "\<And>x. Z < x \<Longrightarrow> x powr s < Z powr s"
hoelzl@51527
  2014
    by (auto simp: Z_def intro!: powr_less_mono2_neg)
hoelzl@51527
  2015
  with assms `0 < e` have "\<And>x. Z < x \<Longrightarrow> dist (x powr s) 0 < e"
hoelzl@51527
  2016
    by (simp add: powr_powr Z_def dist_real_def)
hoelzl@51527
  2017
  ultimately
hoelzl@51527
  2018
  show "eventually (\<lambda>x. dist (f x powr s) 0 < e) F" by (rule eventually_elim1)
hoelzl@51527
  2019
qed
hoelzl@51527
  2020
huffman@29164
  2021
subsection {* Sine and Cosine *}
huffman@29164
  2022
huffman@44308
  2023
definition sin_coeff :: "nat \<Rightarrow> real" where
huffman@31271
  2024
  "sin_coeff = (\<lambda>n. if even n then 0 else -1 ^ ((n - Suc 0) div 2) / real (fact n))"
huffman@31271
  2025
huffman@44308
  2026
definition cos_coeff :: "nat \<Rightarrow> real" where
huffman@31271
  2027
  "cos_coeff = (\<lambda>n. if even n then (-1 ^ (n div 2)) / real (fact n) else 0)"
huffman@31271
  2028
huffman@44308
  2029
definition sin :: "real \<Rightarrow> real" where
huffman@44308
  2030
  "sin = (\<lambda>x. \<Sum>n. sin_coeff n * x ^ n)"
huffman@44308
  2031
huffman@44308
  2032
definition cos :: "real \<Rightarrow> real" where
huffman@44308
  2033
  "cos = (\<lambda>x. \<Sum>n. cos_coeff n * x ^ n)"
huffman@31271
  2034
huffman@44319
  2035
lemma sin_coeff_0 [simp]: "sin_coeff 0 = 0"
huffman@44319
  2036
  unfolding sin_coeff_def by simp
huffman@44319
  2037
huffman@44319
  2038
lemma cos_coeff_0 [simp]: "cos_coeff 0 = 1"
huffman@44319
  2039
  unfolding cos_coeff_def by simp
huffman@44319
  2040
huffman@44319
  2041
lemma sin_coeff_Suc: "sin_coeff (Suc n) = cos_coeff n / real (Suc n)"
huffman@44319
  2042
  unfolding cos_coeff_def sin_coeff_def
huffman@44319
  2043
  by (simp del: mult_Suc)
huffman@44319
  2044
huffman@44319
  2045
lemma cos_coeff_Suc: "cos_coeff (Suc n) = - sin_coeff n / real (Suc n)"
huffman@44319
  2046
  unfolding cos_coeff_def sin_coeff_def
huffman@44319
  2047
  by (simp del: mult_Suc, auto simp add: odd_Suc_mult_two_ex)
huffman@44319
  2048
huffman@31271
  2049
lemma summable_sin: "summable (\<lambda>n. sin_coeff n * x ^ n)"
huffman@31271
  2050
unfolding sin_coeff_def
huffman@44308
  2051
apply (rule summable_comparison_test [OF _ summable_exp [where x="\<bar>x\<bar>"]])
huffman@29164
  2052
apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
huffman@29164
  2053
done
huffman@29164
  2054
huffman@31271
  2055
lemma summable_cos: "summable (\<lambda>n. cos_coeff n * x ^ n)"
huffman@31271
  2056
unfolding cos_coeff_def
huffman@44308
  2057
apply (rule summable_comparison_test [OF _ summable_exp [where x="\<bar>x\<bar>"]])
huffman@29164
  2058
apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
huffman@29164
  2059
done
huffman@29164
  2060
huffman@31271
  2061
lemma sin_converges: "(\<lambda>n. sin_coeff n * x ^ n) sums sin(x)"
huffman@29164
  2062
unfolding sin_def by (rule summable_sin [THEN summable_sums])
huffman@29164
  2063
huffman@31271
  2064
lemma cos_converges: "(\<lambda>n. cos_coeff n * x ^ n) sums cos(x)"
huffman@29164
  2065
unfolding cos_def by (rule summable_cos [THEN summable_sums])
huffman@29164
  2066
huffman@44319
  2067
lemma diffs_sin_coeff: "diffs sin_coeff = cos_coeff"
huffman@44319
  2068
  by (simp add: diffs_def sin_coeff_Suc real_of_nat_def del: of_nat_Suc)
huffman@44319
  2069
huffman@44319
  2070
lemma diffs_cos_coeff: "diffs cos_coeff = (\<lambda>n. - sin_coeff n)"
huffman@44319
  2071
  by (simp add: diffs_def cos_coeff_Suc real_of_nat_def del: of_nat_Suc)
huffman@29164
  2072
huffman@29164
  2073
text{*Now at last we can get the derivatives of exp, sin and cos*}
huffman@29164
  2074
huffman@29164
  2075
lemma DERIV_sin [simp]: "DERIV sin x :> cos(x)"
huffman@44319
  2076
  unfolding sin_def cos_def
huffman@44319
  2077
  apply (rule DERIV_cong, rule termdiffs [where K="1 + \<bar>x\<bar>"])
huffman@44319
  2078
  apply (simp_all add: diffs_sin_coeff diffs_cos_coeff
huffman@44319
  2079
    summable_minus summable_sin summable_cos)
huffman@44319
  2080
  done
huffman@29164
  2081
hoelzl@51527
  2082
declare DERIV_sin[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
hoelzl@51527
  2083
huffman@29164
  2084
lemma DERIV_cos [simp]: "DERIV cos x :> -sin(x)"
huffman@44319
  2085
  unfolding cos_def sin_def
huffman@44319
  2086
  apply (rule DERIV_cong, rule termdiffs [where K="1 + \<bar>x\<bar>"])
huffman@44319
  2087
  apply (simp_all add: diffs_sin_coeff diffs_cos_coeff diffs_minus
huffman@44319
  2088
    summable_minus summable_sin summable_cos suminf_minus)
huffman@44319
  2089
  done
huffman@29164
  2090
hoelzl@51527
  2091
declare DERIV_cos[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
hoelzl@51527
  2092
huffman@44311
  2093
lemma isCont_sin: "isCont sin x"
huffman@44311
  2094
  by (rule DERIV_sin [THEN DERIV_isCont])
huffman@44311
  2095
huffman@44311
  2096
lemma isCont_cos: "isCont cos x"
huffman@44311
  2097
  by (rule DERIV_cos [THEN DERIV_isCont])
huffman@44311
  2098
huffman@44311
  2099
lemma isCont_sin' [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. sin (f x)) a"
huffman@44311
  2100
  by (rule isCont_o2 [OF _ isCont_sin])
huffman@44311
  2101
huffman@44311
  2102
lemma isCont_cos' [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. cos (f x)) a"
huffman@44311
  2103
  by (rule isCont_o2 [OF _ isCont_cos])
huffman@44311
  2104
huffman@44311
  2105
lemma tendsto_sin [tendsto_intros]:
huffman@44311
  2106
  "(f ---> a) F \<Longrightarrow> ((\<lambda>x. sin (f x)) ---> sin a) F"
huffman@44311
  2107
  by (rule isCont_tendsto_compose [OF isCont_sin])
huffman@44311
  2108
huffman@44311
  2109
lemma tendsto_cos [tendsto_intros]:
huffman@44311
  2110
  "(f ---> a) F \<Longrightarrow> ((\<lambda>x. cos (f x)) ---> cos a) F"
huffman@44311
  2111
  by (rule isCont_tendsto_compose [OF isCont_cos])
huffman@29164
  2112
hoelzl@51478
  2113
lemma continuous_sin [continuous_intros]:
hoelzl@51478
  2114
  "continuous F f \<Longrightarrow> continuous F (\<lambda>x. sin (f x))"
hoelzl@51478
  2115
  unfolding continuous_def by (rule tendsto_sin)
hoelzl@51478
  2116
hoelzl@51478
  2117
lemma continuous_on_sin [continuous_on_intros]:
hoelzl@51478
  2118
  "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. sin (f x))"
hoelzl@51478
  2119
  unfolding continuous_on_def by (auto intro: tendsto_sin)
hoelzl@51478
  2120
hoelzl@51478
  2121
lemma continuous_cos [continuous_intros]:
hoelzl@51478
  2122
  "continuous F f \<Longrightarrow> continuous F (\<lambda>x. cos (f x))"
hoelzl@51478
  2123
  unfolding continuous_def by (rule tendsto_cos)
hoelzl@51478
  2124
hoelzl@51478
  2125
lemma continuous_on_cos [continuous_on_intros]:
hoelzl@51478
  2126
  "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. cos (f x))"
hoelzl@51478
  2127
  unfolding continuous_on_def by (auto intro: tendsto_cos)
hoelzl@51478
  2128
huffman@29164
  2129
subsection {* Properties of Sine and Cosine *}
paulson@15077
  2130
paulson@15077
  2131
lemma sin_zero [simp]: "sin 0 = 0"
huffman@44311
  2132
  unfolding sin_def sin_coeff_def by (simp add: powser_zero)
paulson@15077
  2133
paulson@15077
  2134
lemma cos_zero [simp]: "cos 0 = 1"
huffman@44311
  2135
  unfolding cos_def cos_coeff_def by (simp add: powser_zero)
paulson@15077
  2136
wenzelm@53015
  2137
lemma sin_cos_squared_add [simp]: "(sin x)\<^sup>2 + (cos x)\<^sup>2 = 1"
huffman@44308
  2138
proof -
wenzelm@53015
  2139
  have "\<forall>x. DERIV (\<lambda>x. (sin x)\<^sup>2 + (cos x)\<^sup>2) x :> 0"
huffman@44308
  2140
    by (auto intro!: DERIV_intros)
wenzelm@53015
  2141
  hence "(sin x)\<^sup>2 + (cos x)\<^sup>2 = (sin 0)\<^sup>2 + (cos 0)\<^sup>2"
huffman@44308
  2142
    by (rule DERIV_isconst_all)
wenzelm@53015
  2143
  thus "(sin x)\<^sup>2 + (cos x)\<^sup>2 = 1" by simp
huffman@44308
  2144
qed
huffman@44308
  2145
wenzelm@53015
  2146
lemma sin_cos_squared_add2 [simp]: "(cos x)\<^sup>2 + (sin x)\<^sup>2 = 1"
huffman@44308
  2147
  by (subst add_commute, rule sin_cos_squared_add)
paulson@15077
  2148
paulson@15077
  2149
lemma sin_cos_squared_add3 [simp]: "cos x * cos x + sin x * sin x = 1"
huffman@44308
  2150
  using sin_cos_squared_add2 [unfolded power2_eq_square] .
paulson@15077
  2151
wenzelm@53015
  2152
lemma sin_squared_eq: "(sin x)\<^sup>2 = 1 - (cos x)\<^sup>2"
huffman@44308
  2153
  unfolding eq_diff_eq by (rule sin_cos_squared_add)
paulson@15077
  2154
wenzelm@53015
  2155
lemma cos_squared_eq: "(cos x)\<^sup>2 = 1 - (sin x)\<^sup>2"
huffman@44308
  2156
  unfolding eq_diff_eq by (rule sin_cos_squared_add2)
paulson@15077
  2157
paulson@15081
  2158
lemma abs_sin_le_one [simp]: "\<bar>sin x\<bar> \<le> 1"
huffman@44308
  2159
  by (rule power2_le_imp_le, simp_all add: sin_squared_eq)
paulson@15077
  2160
paulson@15077
  2161
lemma sin_ge_minus_one [simp]: "-1 \<le> sin x"
huffman@44308
  2162
  using abs_sin_le_one [of x] unfolding abs_le_iff by simp
paulson@15077
  2163
paulson@15077
  2164
lemma sin_le_one [simp]: "sin x \<le> 1"
huffman@44308
  2165
  using abs_sin_le_one [of x] unfolding abs_le_iff by simp
paulson@15077
  2166
paulson@15081
  2167
lemma abs_cos_le_one [simp]: "\<bar>cos x\<bar> \<le> 1"
huffman@44308
  2168
  by (rule power2_le_imp_le, simp_all add: cos_squared_eq)
paulson@15077
  2169
paulson@15077
  2170
lemma cos_ge_minus_one [simp]: "-1 \<le> cos x"
huffman@44308
  2171
  using abs_cos_le_one [of x] unfolding abs_le_iff by simp
paulson@15077
  2172
paulson@15077
  2173
lemma cos_le_one [simp]: "cos x \<le> 1"
huffman@44308
  2174
  using abs_cos_le_one [of x] unfolding abs_le_iff by simp
paulson@15077
  2175
hoelzl@41970
  2176
lemma DERIV_fun_pow: "DERIV g x :> m ==>
paulson@15077
  2177
      DERIV (%x. (g x) ^ n) x :> real n * (g x) ^ (n - 1) * m"
huffman@44311
  2178
  by (auto intro!: DERIV_intros)
paulson@15077
  2179
paulson@15229
  2180
lemma DERIV_fun_exp:
paulson@15229
  2181
     "DERIV g x :> m ==> DERIV (%x. exp(g x)) x :> exp(g x) * m"
huffman@44311
  2182
  by (auto intro!: DERIV_intros)
paulson@15077
  2183
paulson@15229
  2184
lemma DERIV_fun_sin:
paulson@15229
  2185
     "DERIV g x :> m ==> DERIV (%x. sin(g x)) x :> cos(g x) * m"
huffman@44311
  2186
  by (auto intro!: DERIV_intros)
paulson@15077
  2187
paulson@15229
  2188
lemma DERIV_fun_cos:
paulson@15229
  2189
     "DERIV g x :> m ==> DERIV (%x. cos(g x)) x :> -sin(g x) * m"
huffman@44311
  2190
  by (auto intro!: DERIV_intros)
paulson@15077
  2191
huffman@44308
  2192
lemma sin_cos_add_lemma:
wenzelm@53076
  2193
     "(sin (x + y) - (sin x * cos y + cos x * sin y))\<^sup>2 +
wenzelm@53076
  2194
      (cos (x + y) - (cos x * cos y - sin x * sin y))\<^sup>2 = 0"
huffman@44308
  2195
  (is "?f x = 0")
huffman@44308
  2196
proof -
huffman@44308
  2197
  have "\<forall>x. DERIV (\<lambda>x. ?f x) x :> 0"
huffman@44308
  2198
    by (auto intro!: DERIV_intros simp add: algebra_simps)
huffman@44308
  2199
  hence "?f x = ?f 0"
huffman@44308
  2200
    by (rule DERIV_isconst_all)
huffman@44308
  2201
  thus ?thesis by simp
huffman@44308
  2202
qed
paulson@15077
  2203
paulson@15077
  2204
lemma sin_add: "sin (x + y) = sin x * cos y + cos x * sin y"
huffman@44308
  2205
  using sin_cos_add_lemma unfolding realpow_two_sum_zero_iff by simp
paulson@15077
  2206
paulson@15077
  2207
lemma cos_add: "cos (x + y) = cos x * cos y - sin x * sin y"
huffman@44308
  2208
  using sin_cos_add_lemma unfolding realpow_two_sum_zero_iff by simp
huffman@44308
  2209
huffman@44308
  2210
lemma sin_cos_minus_lemma:
wenzelm@53015
  2211
  "(sin(-x) + sin(x))\<^sup>2 + (cos(-x) - cos(x))\<^sup>2 = 0" (is "?f x = 0")
huffman@44308
  2212
proof -
huffman@44308
  2213
  have "\<forall>x. DERIV (\<lambda>x. ?f x) x :> 0"
huffman@44308
  2214
    by (auto intro!: DERIV_intros simp add: algebra_simps)
huffman@44308
  2215
  hence "?f x = ?f 0"
huffman@44308
  2216
    by (rule DERIV_isconst_all)
huffman@44308
  2217
  thus ?thesis by simp
huffman@44308
  2218
qed
paulson@15077
  2219
paulson@15077
  2220
lemma sin_minus [simp]: "sin (-x) = -sin(x)"
huffman@44308
  2221
  using sin_cos_minus_lemma [where x=x] by simp
paulson@15077
  2222
paulson@15077
  2223
lemma cos_minus [simp]: "cos (-x) = cos(x)"
huffman@44308
  2224
  using sin_cos_minus_lemma [where x=x] by simp
paulson@15077
  2225
paulson@15077
  2226
lemma sin_diff: "sin (x - y) = sin x * cos y - cos x * sin y"
huffman@44308
  2227
  by (simp add: diff_minus sin_add)
paulson@15077
  2228
paulson@15077
  2229
lemma sin_diff2: "sin (x - y) = cos y * sin x - sin y * cos x"
huffman@44308
  2230
  by (simp add: sin_diff mult_commute)
paulson@15077
  2231
paulson@15077
  2232
lemma cos_diff: "cos (x - y) = cos x * cos y + sin x * sin y"
huffman@44308
  2233
  by (simp add: diff_minus cos_add)
paulson@15077
  2234
paulson@15077
  2235
lemma cos_diff2: "cos (x - y) = cos y * cos x + sin y * sin x"
huffman@44308
  2236
  by (simp add: cos_diff mult_commute)
paulson@15077
  2237
paulson@15077
  2238
lemma sin_double [simp]: "sin(2 * x) = 2* sin x * cos x"
huffman@29165
  2239
  using sin_add [where x=x and y=x] by simp
paulson@15077
  2240
wenzelm@53015
  2241
lemma cos_double: "cos(2* x) = ((cos x)\<^sup>2) - ((sin x)\<^sup>2)"
huffman@29165
  2242
  using cos_add [where x=x and y=x]
huffman@29165
  2243
  by (simp add: power2_eq_square)
paulson@15077
  2244
paulson@15077
  2245
huffman@29164
  2246
subsection {* The Constant Pi *}
paulson@15077
  2247
huffman@44308
  2248
definition pi :: "real" where
huffman@23053
  2249
  "pi = 2 * (THE x. 0 \<le> (x::real) & x \<le> 2 & cos x = 0)"
huffman@23043
  2250
hoelzl@41970
  2251
text{*Show that there's a least positive @{term x} with @{term "cos(x) = 0"};
paulson@15077
  2252
   hence define pi.*}
paulson@15077
  2253
paulson@15077
  2254
lemma sin_paired:
hoelzl@41970
  2255
     "(%n. -1 ^ n /(real (fact (2 * n + 1))) * x ^ (2 * n + 1))
paulson@15077
  2256
      sums  sin x"
paulson@15077
  2257
proof -
huffman@31271
  2258
  have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2. sin_coeff k * x ^ k) sums sin x"
huffman@44727
  2259
    by (rule sin_converges [THEN sums_group], simp)
huffman@31271
  2260
  thus ?thesis unfolding One_nat_def sin_coeff_def by (simp add: mult_ac)
paulson@15077
  2261
qed
paulson@15077
  2262
huffman@44728
  2263
lemma sin_gt_zero:
huffman@44728
  2264
  assumes "0 < x" and "x < 2" shows "0 < sin x"
huffman@44728
  2265
proof -
huffman@44728
  2266
  let ?f = "\<lambda>n. \<Sum>k = n*2..<n*2+2. -1 ^ k / real (fact (2*k+1)) * x^(2*k+1)"
huffman@44728
  2267
  have pos: "\<forall>n. 0 < ?f n"
huffman@44728
  2268
  proof
huffman@44728
  2269
    fix n :: nat
huffman@44728
  2270
    let ?k2 = "real (Suc (Suc (4 * n)))"
huffman@44728
  2271
    let ?k3 = "real (Suc (Suc (Suc (4 * n))))"
huffman@44728
  2272
    have "x * x < ?k2 * ?k3"
huffman@44728
  2273
      using assms by (intro mult_strict_mono', simp_all)
huffman@44728
  2274
    hence "x * x * x * x ^ (n * 4) < ?k2 * ?k3 * x * x ^ (n * 4)"
huffman@44728
  2275
      by (intro mult_strict_right_mono zero_less_power `0 < x`)
huffman@44728
  2276
    thus "0 < ?f n"
huffman@44728
  2277
      by (simp del: mult_Suc,
huffman@44728
  2278
        simp add: less_divide_eq mult_pos_pos field_simps del: mult_Suc)
huffman@44728
  2279
  qed
huffman@44728
  2280
  have sums: "?f sums sin x"
huffman@44728
  2281
    by (rule sin_paired [THEN sums_group], simp)
huffman@44728
  2282
  show "0 < sin x"
huffman@44728
  2283
    unfolding sums_unique [OF sums]
huffman@44728
  2284
    using sums_summable [OF sums] pos
huffman@44728
  2285
    by (rule suminf_gt_zero)
huffman@44728
  2286
qed
paulson@15077
  2287
paulson@15077
  2288
lemma cos_double_less_one: "[| 0 < x; x < 2 |] ==> cos (2 * x) < 1"
huffman@44311
  2289
apply (cut_tac x = x in sin_gt_zero)
paulson@15077
  2290
apply (auto simp add: cos_squared_eq cos_double)
paulson@15077
  2291
done
paulson@15077
  2292
paulson@15077
  2293
lemma cos_paired:
huffman@23177
  2294
     "(%n. -1 ^ n /(real (fact (2 * n))) * x ^ (2 * n)) sums cos x"
paulson@15077
  2295
proof -
huffman@31271
  2296
  have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2. cos_coeff k * x ^ k) sums cos x"
huffman@44727
  2297
    by (rule cos_converges [THEN sums_group], simp)
huffman@31271
  2298
  thus ?thesis unfolding cos_coeff_def by (simp add: mult_ac)
paulson@15077
  2299
qed
paulson@15077
  2300
huffman@36824
  2301
lemma real_mult_inverse_cancel:
hoelzl@41970
  2302
     "[|(0::real) < x; 0 < x1; x1 * y < x * u |]
huffman@36824
  2303
      ==> inverse x * y < inverse x1 * u"
hoelzl@41970
  2304
apply (rule_tac c=x in mult_less_imp_less_left)
huffman@36824
  2305
apply (auto simp add: mult_assoc [symmetric])
huffman@36824
  2306
apply (simp (no_asm) add: mult_ac)
hoelzl@41970
  2307
apply (rule_tac c=x1 in mult_less_imp_less_right)
huffman@36824
  2308
apply (auto simp add: mult_ac)
huffman@36824
  2309
done
huffman@36824
  2310
huffman@36824
  2311
lemma real_mult_inverse_cancel2:
huffman@36824
  2312
     "[|(0::real) < x;0 < x1; x1 * y < x * u |] ==> y * inverse x < u * inverse x1"
huffman@36824
  2313
apply (auto dest: real_mult_inverse_cancel simp add: mult_ac)
huffman@36824
  2314
done
huffman@36824
  2315
huffman@36824
  2316
lemma realpow_num_eq_if:
huffman@36824
  2317
  fixes m :: "'a::power"
huffman@36824
  2318
  shows "m ^ n = (if n=0 then 1 else m * m ^ (n - 1))"
huffman@36824
  2319
by (cases n, auto)
huffman@36824
  2320
huffman@23053
  2321
lemma cos_two_less_zero [simp]: "cos (2) < 0"
paulson@15077
  2322
apply (cut_tac x = 2 in cos_paired)
paulson@15077
  2323
apply (drule sums_minus)
hoelzl@41970
  2324
apply (rule neg_less_iff_less [THEN iffD1])
nipkow@15539
  2325
apply (frule sums_unique, auto)
nipkow@15539
  2326
apply (rule_tac y =
huffman@23177
  2327
 "\<Sum>n=0..< Suc(Suc(Suc 0)). - (-1 ^ n / (real(fact (2*n))) * 2 ^ (2*n))"
paulson@15481
  2328
       in order_less_trans)
avigad@32047
  2329
apply (simp (no_asm) add: fact_num_eq_if_nat realpow_num_eq_if del: fact_Suc)
nipkow@15561
  2330
apply (simp (no_asm) add: mult_assoc del: setsum_op_ivl_Suc)
paulson@15077
  2331
apply (rule sumr_pos_lt_pair)
paulson@15077
  2332
apply (erule sums_summable, safe)
huffman@30082
  2333
unfolding One_nat_def
hoelzl@41970
  2334
apply (simp (no_asm) add: divide_inverse real_0_less_add_iff mult_assoc [symmetric]
avigad@32047
  2335
            del: fact_Suc)
huffman@46240
  2336
apply (simp add: inverse_eq_divide less_divide_eq del: fact_Suc)
avigad@32047
  2337
apply (subst fact_Suc [of "Suc (Suc (Suc (Suc (Suc (Suc (Suc (4 * d)))))))"])
paulson@15481
  2338
apply (simp only: real_of_nat_mult)
huffman@23007
  2339
apply (rule mult_strict_mono, force)
huffman@27483
  2340
  apply (rule_tac [3] real_of_nat_ge_zero)
paulson@15481
  2341
 prefer 2 apply force
paulson@15077
  2342
apply (rule real_of_nat_less_iff [THEN iffD2])
avigad@32036
  2343
apply (rule fact_less_mono_nat, auto)
paulson@15077
  2344
done
huffman@23053
  2345
huffman@23053
  2346
lemmas cos_two_neq_zero [simp] = cos_two_less_zero [THEN less_imp_neq]
huffman@23053
  2347
lemmas cos_two_le_zero [simp] = cos_two_less_zero [THEN order_less_imp_le]
paulson@15077
  2348
paulson@15077
  2349
lemma cos_is_zero: "EX! x. 0 \<le> x & x \<le> 2 & cos x = 0"
huffman@44730
  2350
proof (rule ex_ex1I)
huffman@44730
  2351
  show "\<exists>x. 0 \<le> x & x \<le> 2 & cos x = 0"
huffman@44730
  2352
    by (rule IVT2, simp_all)
huffman@44730
  2353
next
huffman@44730
  2354
  fix x y
huffman@44730
  2355
  assume x: "0 \<le> x \<and> x \<le> 2 \<and> cos x = 0"
huffman@44730
  2356
  assume y: "0 \<le> y \<and> y \<le> 2 \<and> cos y = 0"
huffman@44730
  2357
  have [simp]: "\<forall>x. cos differentiable x"
huffman@44730
  2358
    unfolding differentiable_def by (auto intro: DERIV_cos)
huffman@44730
  2359
  from x y show "x = y"
huffman@44730
  2360
    apply (cut_tac less_linear [of x y], auto)
huffman@44730
  2361
    apply (drule_tac f = cos in Rolle)
huffman@44730
  2362
    apply (drule_tac [5] f = cos in Rolle)
huffman@44730
  2363
    apply (auto dest!: DERIV_cos [THEN DERIV_unique])
huffman@44730
  2364
    apply (metis order_less_le_trans less_le sin_gt_zero)
huffman@44730
  2365
    apply (metis order_less_le_trans less_le sin_gt_zero)
huffman@44730
  2366
    done
huffman@44730
  2367
qed
hoelzl@31880
  2368
huffman@23053
  2369
lemma pi_half: "pi/2 = (THE x. 0 \<le> x & x \<le> 2 & cos x = 0)"
paulson@15077
  2370
by (simp add: pi_def)
paulson@15077
  2371
paulson@15077
  2372
lemma cos_pi_half [simp]: "cos (pi / 2) = 0"
huffman@23053
  2373
by (simp add: pi_half cos_is_zero [THEN theI'])
huffman@23053
  2374
huffman@23053
  2375
lemma pi_half_gt_zero [simp]: "0 < pi / 2"
huffman@23053
  2376
apply (rule order_le_neq_trans)
huffman@23053
  2377
apply (simp add: pi_half cos_is_zero [THEN theI'])
huffman@23053
  2378
apply (rule notI, drule arg_cong [where f=cos], simp)
paulson@15077
  2379
done
paulson@15077
  2380
huffman@23053
  2381
lemmas pi_half_neq_zero [simp] = pi_half_gt_zero [THEN less_imp_neq, symmetric]
huffman@23053
  2382
lemmas pi_half_ge_zero [simp] = pi_half_gt_zero [THEN order_less_imp_le]
paulson@15077
  2383
huffman@23053
  2384
lemma pi_half_less_two [simp]: "pi / 2 < 2"
huffman@23053
  2385
apply (rule order_le_neq_trans)
huffman@23053
  2386
apply (simp add: pi_half cos_is_zero [THEN theI'])
huffman@23053
  2387
apply (rule notI, drule arg_cong [where f=cos], simp)
paulson@15077
  2388
done
huffman@23053
  2389
huffman@23053
  2390
lemmas pi_half_neq_two [simp] = pi_half_less_two [THEN less_imp_neq]
huffman@23053
  2391
lemmas pi_half_le_two [simp] =  pi_half_less_two [THEN order_less_imp_le]
paulson@15077
  2392
paulson@15077
  2393
lemma pi_gt_zero [simp]: "0 < pi"
huffman@23053
  2394
by (insert pi_half_gt_zero, simp)
huffman@23053
  2395
huffman@23053
  2396
lemma pi_ge_zero [simp]: "0 \<le> pi"
huffman@23053
  2397
by (rule pi_gt_zero [THEN order_less_imp_le])
paulson@15077
  2398
paulson@15077
  2399
lemma pi_neq_zero [simp]: "pi \<noteq> 0"
huffman@22998
  2400
by (rule pi_gt_zero [THEN less_imp_neq, THEN not_sym])
paulson@15077
  2401
huffman@23053
  2402
lemma pi_not_less_zero [simp]: "\<not> pi < 0"
huffman@23053
  2403
by (simp add: linorder_not_less)
paulson@15077
  2404
huffman@29165
  2405
lemma minus_pi_half_less_zero: "-(pi/2) < 0"
huffman@29