src/HOL/Transcendental.thy
author huffman
Wed Dec 24 08:40:16 2008 -0800 (2008-12-24)
changeset 29167 37a952bb9ebc
parent 29166 c23b2d108612
child 29170 dad3933c88dd
permissions -rw-r--r--
rearranged subsections; cleaned up some proofs
paulson@12196
     1
(*  Title       : Transcendental.thy
paulson@12196
     2
    Author      : Jacques D. Fleuriot
paulson@12196
     3
    Copyright   : 1998,1999 University of Cambridge
paulson@13958
     4
                  1999,2001 University of Edinburgh
paulson@15077
     5
    Conversion to Isar and new proofs by Lawrence C Paulson, 2004
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:
huffman@23082
    17
  fixes y :: "'a::recpower"
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@23082
    22
  thus ?thesis by (simp add: power_Suc power_commutes)
huffman@23082
    23
qed
paulson@15077
    24
paulson@15077
    25
lemma lemma_realpow_diff_sumr:
huffman@23082
    26
  fixes y :: "'a::{recpower,comm_semiring_0}" shows
huffman@23082
    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
huffman@29163
    30
         del: setsum_op_ivl_Suc cong: strong_setsum_cong)
paulson@15077
    31
paulson@15229
    32
lemma lemma_realpow_diff_sumr2:
huffman@23082
    33
  fixes y :: "'a::{recpower,comm_ring}" shows
paulson@15229
    34
     "x ^ (Suc n) - y ^ (Suc n) =  
huffman@23082
    35
      (x - y) * (\<Sum>p=0..<Suc n. (x ^ p) * y ^ (n - p))"
haftmann@25153
    36
apply (induct n, simp add: power_Suc)
huffman@23082
    37
apply (simp add: power_Suc del: setsum_op_ivl_Suc)
nipkow@15561
    38
apply (subst setsum_op_ivl_Suc)
huffman@23082
    39
apply (subst lemma_realpow_diff_sumr)
huffman@23082
    40
apply (simp add: right_distrib del: setsum_op_ivl_Suc)
huffman@23082
    41
apply (subst mult_left_commute [where a="x - y"])
huffman@23082
    42
apply (erule subst)
nipkow@23477
    43
apply (simp add: power_Suc ring_simps)
paulson@15077
    44
done
paulson@15077
    45
paulson@15229
    46
lemma lemma_realpow_rev_sumr:
nipkow@15539
    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@23082
    59
  fixes x z :: "'a::{real_normed_field,banach,recpower}"
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@20849
    70
    by (simp add: Cauchy_convergent_iff)
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:
huffman@23082
   111
  fixes f :: "nat \<Rightarrow> 'a::{real_normed_field,banach,recpower}" shows
huffman@23082
   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
paulson@15077
   116
huffman@29164
   117
subsection {* Term-by-Term Differentiability of Power Series *}
huffman@23043
   118
huffman@23043
   119
definition
huffman@23082
   120
  diffs :: "(nat => 'a::ring_1) => nat => 'a" where
huffman@23082
   121
  "diffs c = (%n. of_nat (Suc n) * c(Suc n))"
paulson@15077
   122
paulson@15077
   123
text{*Lemma about distributing negation over it*}
paulson@15077
   124
lemma diffs_minus: "diffs (%n. - c n) = (%n. - diffs c n)"
paulson@15077
   125
by (simp add: diffs_def)
paulson@15077
   126
huffman@29163
   127
lemma sums_Suc_imp:
huffman@29163
   128
  assumes f: "f 0 = 0"
huffman@29163
   129
  shows "(\<lambda>n. f (Suc n)) sums s \<Longrightarrow> (\<lambda>n. f n) sums s"
huffman@29163
   130
unfolding sums_def
huffman@29163
   131
apply (rule LIMSEQ_imp_Suc)
huffman@29163
   132
apply (subst setsum_shift_lb_Suc0_0_upt [where f=f, OF f, symmetric])
huffman@29163
   133
apply (simp only: setsum_shift_bounds_Suc_ivl)
paulson@15077
   134
done
paulson@15077
   135
paulson@15229
   136
lemma diffs_equiv:
paulson@15229
   137
     "summable (%n. (diffs c)(n) * (x ^ n)) ==>  
huffman@23082
   138
      (%n. of_nat n * c(n) * (x ^ (n - Suc 0))) sums  
nipkow@15546
   139
         (\<Sum>n. (diffs c)(n) * (x ^ n))"
huffman@29163
   140
unfolding diffs_def
huffman@29163
   141
apply (drule summable_sums)
huffman@29163
   142
apply (rule sums_Suc_imp, simp_all)
paulson@15077
   143
done
paulson@15077
   144
paulson@15077
   145
lemma lemma_termdiff1:
huffman@23082
   146
  fixes z :: "'a :: {recpower,comm_ring}" shows
nipkow@15539
   147
  "(\<Sum>p=0..<m. (((z + h) ^ (m - p)) * (z ^ p)) - (z ^ m)) =  
huffman@23082
   148
   (\<Sum>p=0..<m. (z ^ p) * (((z + h) ^ (m - p)) - (z ^ (m - p))))"
berghofe@16641
   149
by (auto simp add: right_distrib diff_minus power_add [symmetric] mult_ac
berghofe@16641
   150
  cong: strong_setsum_cong)
paulson@15077
   151
huffman@23082
   152
lemma sumr_diff_mult_const2:
huffman@23082
   153
  "setsum f {0..<n} - of_nat n * (r::'a::ring_1) = (\<Sum>i = 0..<n. f i - r)"
huffman@23082
   154
by (simp add: setsum_subtractf)
huffman@23082
   155
paulson@15229
   156
lemma lemma_termdiff2:
huffman@23112
   157
  fixes h :: "'a :: {recpower,field}"
huffman@20860
   158
  assumes h: "h \<noteq> 0" shows
huffman@23082
   159
  "((z + h) ^ n - z ^ n) / h - of_nat n * z ^ (n - Suc 0) =
huffman@20860
   160
   h * (\<Sum>p=0..< n - Suc 0. \<Sum>q=0..< n - Suc 0 - p.
huffman@23082
   161
        (z + h) ^ q * z ^ (n - 2 - q))" (is "?lhs = ?rhs")
huffman@23082
   162
apply (subgoal_tac "h * ?lhs = h * ?rhs", simp add: h)
huffman@20860
   163
apply (simp add: right_diff_distrib diff_divide_distrib h)
paulson@15077
   164
apply (simp add: mult_assoc [symmetric])
huffman@20860
   165
apply (cases "n", simp)
huffman@20860
   166
apply (simp add: lemma_realpow_diff_sumr2 h
huffman@20860
   167
                 right_diff_distrib [symmetric] mult_assoc
huffman@23082
   168
            del: realpow_Suc setsum_op_ivl_Suc of_nat_Suc)
huffman@20860
   169
apply (subst lemma_realpow_rev_sumr)
huffman@23082
   170
apply (subst sumr_diff_mult_const2)
huffman@20860
   171
apply simp
huffman@20860
   172
apply (simp only: lemma_termdiff1 setsum_right_distrib)
huffman@20860
   173
apply (rule setsum_cong [OF refl])
nipkow@15539
   174
apply (simp add: diff_minus [symmetric] less_iff_Suc_add)
huffman@20860
   175
apply (clarify)
huffman@20860
   176
apply (simp add: setsum_right_distrib lemma_realpow_diff_sumr2 mult_ac
huffman@20860
   177
            del: setsum_op_ivl_Suc realpow_Suc)
huffman@20860
   178
apply (subst mult_assoc [symmetric], subst power_add [symmetric])
huffman@20860
   179
apply (simp add: mult_ac)
huffman@20860
   180
done
huffman@20860
   181
huffman@20860
   182
lemma real_setsum_nat_ivl_bounded2:
huffman@23082
   183
  fixes K :: "'a::ordered_semidom"
huffman@23082
   184
  assumes f: "\<And>p::nat. p < n \<Longrightarrow> f p \<le> K"
huffman@23082
   185
  assumes K: "0 \<le> K"
huffman@23082
   186
  shows "setsum f {0..<n-k} \<le> of_nat n * K"
huffman@23082
   187
apply (rule order_trans [OF setsum_mono])
huffman@23082
   188
apply (rule f, simp)
huffman@23082
   189
apply (simp add: mult_right_mono K)
paulson@15077
   190
done
paulson@15077
   191
paulson@15229
   192
lemma lemma_termdiff3:
huffman@23112
   193
  fixes h z :: "'a::{real_normed_field,recpower}"
huffman@20860
   194
  assumes 1: "h \<noteq> 0"
huffman@23082
   195
  assumes 2: "norm z \<le> K"
huffman@23082
   196
  assumes 3: "norm (z + h) \<le> K"
huffman@23082
   197
  shows "norm (((z + h) ^ n - z ^ n) / h - of_nat n * z ^ (n - Suc 0))
huffman@23082
   198
          \<le> of_nat n * of_nat (n - Suc 0) * K ^ (n - 2) * norm h"
huffman@20860
   199
proof -
huffman@23082
   200
  have "norm (((z + h) ^ n - z ^ n) / h - of_nat n * z ^ (n - Suc 0)) =
huffman@23082
   201
        norm (\<Sum>p = 0..<n - Suc 0. \<Sum>q = 0..<n - Suc 0 - p.
huffman@23082
   202
          (z + h) ^ q * z ^ (n - 2 - q)) * norm h"
huffman@20860
   203
    apply (subst lemma_termdiff2 [OF 1])
huffman@23082
   204
    apply (subst norm_mult)
huffman@20860
   205
    apply (rule mult_commute)
huffman@20860
   206
    done
huffman@23082
   207
  also have "\<dots> \<le> of_nat n * (of_nat (n - Suc 0) * K ^ (n - 2)) * norm h"
huffman@23082
   208
  proof (rule mult_right_mono [OF _ norm_ge_zero])
huffman@23082
   209
    from norm_ge_zero 2 have K: "0 \<le> K" by (rule order_trans)
huffman@23082
   210
    have le_Kn: "\<And>i j n. i + j = n \<Longrightarrow> norm ((z + h) ^ i * z ^ j) \<le> K ^ n"
huffman@20860
   211
      apply (erule subst)
huffman@23082
   212
      apply (simp only: norm_mult norm_power power_add)
huffman@23082
   213
      apply (intro mult_mono power_mono 2 3 norm_ge_zero zero_le_power K)
huffman@20860
   214
      done
huffman@23082
   215
    show "norm (\<Sum>p = 0..<n - Suc 0. \<Sum>q = 0..<n - Suc 0 - p.
huffman@23082
   216
              (z + h) ^ q * z ^ (n - 2 - q))
huffman@23082
   217
          \<le> of_nat n * (of_nat (n - Suc 0) * K ^ (n - 2))"
huffman@20860
   218
      apply (intro
huffman@23082
   219
         order_trans [OF norm_setsum]
huffman@20860
   220
         real_setsum_nat_ivl_bounded2
huffman@20860
   221
         mult_nonneg_nonneg
huffman@23082
   222
         zero_le_imp_of_nat
huffman@20860
   223
         zero_le_power K)
huffman@20860
   224
      apply (rule le_Kn, simp)
huffman@20860
   225
      done
huffman@20860
   226
  qed
huffman@23082
   227
  also have "\<dots> = of_nat n * of_nat (n - Suc 0) * K ^ (n - 2) * norm h"
huffman@20860
   228
    by (simp only: mult_assoc)
huffman@20860
   229
  finally show ?thesis .
huffman@20860
   230
qed
paulson@15077
   231
huffman@20860
   232
lemma lemma_termdiff4:
huffman@23112
   233
  fixes f :: "'a::{real_normed_field,recpower} \<Rightarrow>
huffman@23082
   234
              'b::real_normed_vector"
huffman@20860
   235
  assumes k: "0 < (k::real)"
huffman@23082
   236
  assumes le: "\<And>h. \<lbrakk>h \<noteq> 0; norm h < k\<rbrakk> \<Longrightarrow> norm (f h) \<le> K * norm h"
huffman@20860
   237
  shows "f -- 0 --> 0"
huffman@29163
   238
unfolding LIM_def diff_0_right
huffman@29163
   239
proof (safe)
huffman@29163
   240
  let ?h = "of_real (k / 2)::'a"
huffman@29163
   241
  have "?h \<noteq> 0" and "norm ?h < k" using k by simp_all
huffman@29163
   242
  hence "norm (f ?h) \<le> K * norm ?h" by (rule le)
huffman@29163
   243
  hence "0 \<le> K * norm ?h" by (rule order_trans [OF norm_ge_zero])
huffman@29163
   244
  hence zero_le_K: "0 \<le> K" using k by (simp add: zero_le_mult_iff)
huffman@29163
   245
huffman@20860
   246
  fix r::real assume r: "0 < r"
huffman@23082
   247
  show "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> 0 \<and> norm x < s \<longrightarrow> norm (f x) < r)"
huffman@20860
   248
  proof (cases)
huffman@20860
   249
    assume "K = 0"
huffman@23082
   250
    with k r le have "0 < k \<and> (\<forall>x. x \<noteq> 0 \<and> norm x < k \<longrightarrow> norm (f x) < r)"
huffman@20860
   251
      by simp
huffman@23082
   252
    thus "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> 0 \<and> norm x < s \<longrightarrow> norm (f x) < r)" ..
huffman@20860
   253
  next
huffman@20860
   254
    assume K_neq_zero: "K \<noteq> 0"
huffman@20860
   255
    with zero_le_K have K: "0 < K" by simp
huffman@23082
   256
    show "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> 0 \<and> norm x < s \<longrightarrow> norm (f x) < r)"
huffman@20860
   257
    proof (rule exI, safe)
huffman@20860
   258
      from k r K show "0 < min k (r * inverse K / 2)"
huffman@20860
   259
        by (simp add: mult_pos_pos positive_imp_inverse_positive)
huffman@20860
   260
    next
huffman@23082
   261
      fix x::'a
huffman@23082
   262
      assume x1: "x \<noteq> 0" and x2: "norm x < min k (r * inverse K / 2)"
huffman@23082
   263
      from x2 have x3: "norm x < k" and x4: "norm x < r * inverse K / 2"
huffman@20860
   264
        by simp_all
huffman@23082
   265
      from x1 x3 le have "norm (f x) \<le> K * norm x" by simp
huffman@23082
   266
      also from x4 K have "K * norm x < K * (r * inverse K / 2)"
huffman@20860
   267
        by (rule mult_strict_left_mono)
huffman@20860
   268
      also have "\<dots> = r / 2"
huffman@20860
   269
        using K_neq_zero by simp
huffman@20860
   270
      also have "r / 2 < r"
huffman@20860
   271
        using r by simp
huffman@23082
   272
      finally show "norm (f x) < r" .
huffman@20860
   273
    qed
huffman@20860
   274
  qed
huffman@20860
   275
qed
paulson@15077
   276
paulson@15229
   277
lemma lemma_termdiff5:
huffman@23112
   278
  fixes g :: "'a::{recpower,real_normed_field} \<Rightarrow>
huffman@23082
   279
              nat \<Rightarrow> 'b::banach"
huffman@20860
   280
  assumes k: "0 < (k::real)"
huffman@20860
   281
  assumes f: "summable f"
huffman@23082
   282
  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
   283
  shows "(\<lambda>h. suminf (g h)) -- 0 --> 0"
huffman@20860
   284
proof (rule lemma_termdiff4 [OF k])
huffman@23082
   285
  fix h::'a assume "h \<noteq> 0" and "norm h < k"
huffman@23082
   286
  hence A: "\<forall>n. norm (g h n) \<le> f n * norm h"
huffman@20860
   287
    by (simp add: le)
huffman@23082
   288
  hence "\<exists>N. \<forall>n\<ge>N. norm (norm (g h n)) \<le> f n * norm h"
huffman@20860
   289
    by simp
huffman@23082
   290
  moreover from f have B: "summable (\<lambda>n. f n * norm h)"
huffman@20860
   291
    by (rule summable_mult2)
huffman@23082
   292
  ultimately have C: "summable (\<lambda>n. norm (g h n))"
huffman@20860
   293
    by (rule summable_comparison_test)
huffman@23082
   294
  hence "norm (suminf (g h)) \<le> (\<Sum>n. norm (g h n))"
huffman@23082
   295
    by (rule summable_norm)
huffman@23082
   296
  also from A C B have "(\<Sum>n. norm (g h n)) \<le> (\<Sum>n. f n * norm h)"
huffman@20860
   297
    by (rule summable_le)
huffman@23082
   298
  also from f have "(\<Sum>n. f n * norm h) = suminf f * norm h"
huffman@20860
   299
    by (rule suminf_mult2 [symmetric])
huffman@23082
   300
  finally show "norm (suminf (g h)) \<le> suminf f * norm h" .
huffman@20860
   301
qed
paulson@15077
   302
paulson@15077
   303
paulson@15077
   304
text{* FIXME: Long proofs*}
paulson@15077
   305
paulson@15077
   306
lemma termdiffs_aux:
huffman@23112
   307
  fixes x :: "'a::{recpower,real_normed_field,banach}"
huffman@20849
   308
  assumes 1: "summable (\<lambda>n. diffs (diffs c) n * K ^ n)"
huffman@23082
   309
  assumes 2: "norm x < norm K"
huffman@20860
   310
  shows "(\<lambda>h. \<Sum>n. c n * (((x + h) ^ n - x ^ n) / h
huffman@23082
   311
             - of_nat n * x ^ (n - Suc 0))) -- 0 --> 0"
huffman@20849
   312
proof -
huffman@20860
   313
  from dense [OF 2]
huffman@23082
   314
  obtain r where r1: "norm x < r" and r2: "r < norm K" by fast
huffman@23082
   315
  from norm_ge_zero r1 have r: "0 < r"
huffman@20860
   316
    by (rule order_le_less_trans)
huffman@20860
   317
  hence r_neq_0: "r \<noteq> 0" by simp
huffman@20860
   318
  show ?thesis
huffman@20849
   319
  proof (rule lemma_termdiff5)
huffman@23082
   320
    show "0 < r - norm x" using r1 by simp
huffman@20849
   321
  next
huffman@23082
   322
    from r r2 have "norm (of_real r::'a) < norm K"
huffman@23082
   323
      by simp
huffman@23082
   324
    with 1 have "summable (\<lambda>n. norm (diffs (diffs c) n * (of_real r ^ n)))"
huffman@20860
   325
      by (rule powser_insidea)
huffman@23082
   326
    hence "summable (\<lambda>n. diffs (diffs (\<lambda>n. norm (c n))) n * r ^ n)"
huffman@23082
   327
      using r
huffman@23082
   328
      by (simp add: diffs_def norm_mult norm_power del: of_nat_Suc)
huffman@23082
   329
    hence "summable (\<lambda>n. of_nat n * diffs (\<lambda>n. norm (c n)) n * r ^ (n - Suc 0))"
huffman@20860
   330
      by (rule diffs_equiv [THEN sums_summable])
huffman@23082
   331
    also have "(\<lambda>n. of_nat n * diffs (\<lambda>n. norm (c n)) n * r ^ (n - Suc 0))
huffman@23082
   332
      = (\<lambda>n. diffs (%m. of_nat (m - Suc 0) * norm (c m) * inverse r) n * (r ^ n))"
huffman@20849
   333
      apply (rule ext)
huffman@20849
   334
      apply (simp add: diffs_def)
huffman@20849
   335
      apply (case_tac n, simp_all add: r_neq_0)
huffman@20849
   336
      done
huffman@20860
   337
    finally have "summable 
huffman@23082
   338
      (\<lambda>n. of_nat n * (of_nat (n - Suc 0) * norm (c n) * inverse r) * r ^ (n - Suc 0))"
huffman@20860
   339
      by (rule diffs_equiv [THEN sums_summable])
huffman@20860
   340
    also have
huffman@23082
   341
      "(\<lambda>n. of_nat n * (of_nat (n - Suc 0) * norm (c n) * inverse r) *
huffman@20860
   342
           r ^ (n - Suc 0)) =
huffman@23082
   343
       (\<lambda>n. norm (c n) * of_nat n * of_nat (n - Suc 0) * r ^ (n - 2))"
huffman@20849
   344
      apply (rule ext)
huffman@20849
   345
      apply (case_tac "n", simp)
huffman@20849
   346
      apply (case_tac "nat", simp)
huffman@20849
   347
      apply (simp add: r_neq_0)
huffman@20849
   348
      done
huffman@20860
   349
    finally show
huffman@23082
   350
      "summable (\<lambda>n. norm (c n) * of_nat n * of_nat (n - Suc 0) * r ^ (n - 2))" .
huffman@20849
   351
  next
huffman@23082
   352
    fix h::'a and n::nat
huffman@20860
   353
    assume h: "h \<noteq> 0"
huffman@23082
   354
    assume "norm h < r - norm x"
huffman@23082
   355
    hence "norm x + norm h < r" by simp
huffman@23082
   356
    with norm_triangle_ineq have xh: "norm (x + h) < r"
huffman@20860
   357
      by (rule order_le_less_trans)
huffman@23082
   358
    show "norm (c n * (((x + h) ^ n - x ^ n) / h - of_nat n * x ^ (n - Suc 0)))
huffman@23082
   359
          \<le> norm (c n) * of_nat n * of_nat (n - Suc 0) * r ^ (n - 2) * norm h"
huffman@23082
   360
      apply (simp only: norm_mult mult_assoc)
huffman@23082
   361
      apply (rule mult_left_mono [OF _ norm_ge_zero])
huffman@20860
   362
      apply (simp (no_asm) add: mult_assoc [symmetric])
huffman@20860
   363
      apply (rule lemma_termdiff3)
huffman@20860
   364
      apply (rule h)
huffman@20860
   365
      apply (rule r1 [THEN order_less_imp_le])
huffman@20860
   366
      apply (rule xh [THEN order_less_imp_le])
huffman@20860
   367
      done
huffman@20849
   368
  qed
huffman@20849
   369
qed
webertj@20217
   370
huffman@20860
   371
lemma termdiffs:
huffman@23112
   372
  fixes K x :: "'a::{recpower,real_normed_field,banach}"
huffman@20860
   373
  assumes 1: "summable (\<lambda>n. c n * K ^ n)"
huffman@20860
   374
  assumes 2: "summable (\<lambda>n. (diffs c) n * K ^ n)"
huffman@20860
   375
  assumes 3: "summable (\<lambda>n. (diffs (diffs c)) n * K ^ n)"
huffman@23082
   376
  assumes 4: "norm x < norm K"
huffman@20860
   377
  shows "DERIV (\<lambda>x. \<Sum>n. c n * x ^ n) x :> (\<Sum>n. (diffs c) n * x ^ n)"
huffman@29163
   378
unfolding deriv_def
huffman@29163
   379
proof (rule LIM_zero_cancel)
huffman@20860
   380
  show "(\<lambda>h. (suminf (\<lambda>n. c n * (x + h) ^ n) - suminf (\<lambda>n. c n * x ^ n)) / h
huffman@20860
   381
            - suminf (\<lambda>n. diffs c n * x ^ n)) -- 0 --> 0"
huffman@20860
   382
  proof (rule LIM_equal2)
huffman@29163
   383
    show "0 < norm K - norm x" using 4 by (simp add: less_diff_eq)
huffman@20860
   384
  next
huffman@23082
   385
    fix h :: 'a
huffman@20860
   386
    assume "h \<noteq> 0"
huffman@23082
   387
    assume "norm (h - 0) < norm K - norm x"
huffman@23082
   388
    hence "norm x + norm h < norm K" by simp
huffman@23082
   389
    hence 5: "norm (x + h) < norm K"
huffman@23082
   390
      by (rule norm_triangle_ineq [THEN order_le_less_trans])
huffman@20860
   391
    have A: "summable (\<lambda>n. c n * x ^ n)"
huffman@20860
   392
      by (rule powser_inside [OF 1 4])
huffman@20860
   393
    have B: "summable (\<lambda>n. c n * (x + h) ^ n)"
huffman@20860
   394
      by (rule powser_inside [OF 1 5])
huffman@20860
   395
    have C: "summable (\<lambda>n. diffs c n * x ^ n)"
huffman@20860
   396
      by (rule powser_inside [OF 2 4])
huffman@20860
   397
    show "((\<Sum>n. c n * (x + h) ^ n) - (\<Sum>n. c n * x ^ n)) / h
huffman@20860
   398
             - (\<Sum>n. diffs c n * x ^ n) = 
huffman@23082
   399
          (\<Sum>n. c n * (((x + h) ^ n - x ^ n) / h - of_nat n * x ^ (n - Suc 0)))"
huffman@20860
   400
      apply (subst sums_unique [OF diffs_equiv [OF C]])
huffman@20860
   401
      apply (subst suminf_diff [OF B A])
huffman@20860
   402
      apply (subst suminf_divide [symmetric])
huffman@20860
   403
      apply (rule summable_diff [OF B A])
huffman@20860
   404
      apply (subst suminf_diff)
huffman@20860
   405
      apply (rule summable_divide)
huffman@20860
   406
      apply (rule summable_diff [OF B A])
huffman@20860
   407
      apply (rule sums_summable [OF diffs_equiv [OF C]])
huffman@29163
   408
      apply (rule arg_cong [where f="suminf"], rule ext)
nipkow@23477
   409
      apply (simp add: ring_simps)
huffman@20860
   410
      done
huffman@20860
   411
  next
huffman@20860
   412
    show "(\<lambda>h. \<Sum>n. c n * (((x + h) ^ n - x ^ n) / h -
huffman@23082
   413
               of_nat n * x ^ (n - Suc 0))) -- 0 --> 0"
huffman@20860
   414
        by (rule termdiffs_aux [OF 3 4])
huffman@20860
   415
  qed
huffman@20860
   416
qed
huffman@20860
   417
paulson@15077
   418
huffman@29164
   419
subsection {* Exponential Function *}
huffman@23043
   420
huffman@23043
   421
definition
huffman@23115
   422
  exp :: "'a \<Rightarrow> 'a::{recpower,real_normed_field,banach}" where
haftmann@25062
   423
  "exp x = (\<Sum>n. x ^ n /\<^sub>R real (fact n))"
huffman@23043
   424
huffman@23115
   425
lemma summable_exp_generic:
huffman@23115
   426
  fixes x :: "'a::{real_normed_algebra_1,recpower,banach}"
haftmann@25062
   427
  defines S_def: "S \<equiv> \<lambda>n. x ^ n /\<^sub>R real (fact n)"
huffman@23115
   428
  shows "summable S"
huffman@23115
   429
proof -
haftmann@25062
   430
  have S_Suc: "\<And>n. S (Suc n) = (x * S n) /\<^sub>R real (Suc n)"
huffman@23115
   431
    unfolding S_def by (simp add: power_Suc del: mult_Suc)
huffman@23115
   432
  obtain r :: real where r0: "0 < r" and r1: "r < 1"
huffman@23115
   433
    using dense [OF zero_less_one] by fast
huffman@23115
   434
  obtain N :: nat where N: "norm x < real N * r"
huffman@23115
   435
    using reals_Archimedean3 [OF r0] by fast
huffman@23115
   436
  from r1 show ?thesis
huffman@23115
   437
  proof (rule ratio_test [rule_format])
huffman@23115
   438
    fix n :: nat
huffman@23115
   439
    assume n: "N \<le> n"
huffman@23115
   440
    have "norm x \<le> real N * r"
huffman@23115
   441
      using N by (rule order_less_imp_le)
huffman@23115
   442
    also have "real N * r \<le> real (Suc n) * r"
huffman@23115
   443
      using r0 n by (simp add: mult_right_mono)
huffman@23115
   444
    finally have "norm x * norm (S n) \<le> real (Suc n) * r * norm (S n)"
huffman@23115
   445
      using norm_ge_zero by (rule mult_right_mono)
huffman@23115
   446
    hence "norm (x * S n) \<le> real (Suc n) * r * norm (S n)"
huffman@23115
   447
      by (rule order_trans [OF norm_mult_ineq])
huffman@23115
   448
    hence "norm (x * S n) / real (Suc n) \<le> r * norm (S n)"
huffman@23115
   449
      by (simp add: pos_divide_le_eq mult_ac)
huffman@23115
   450
    thus "norm (S (Suc n)) \<le> r * norm (S n)"
huffman@23115
   451
      by (simp add: S_Suc norm_scaleR inverse_eq_divide)
huffman@23115
   452
  qed
huffman@23115
   453
qed
huffman@23115
   454
huffman@23115
   455
lemma summable_norm_exp:
huffman@23115
   456
  fixes x :: "'a::{real_normed_algebra_1,recpower,banach}"
haftmann@25062
   457
  shows "summable (\<lambda>n. norm (x ^ n /\<^sub>R real (fact n)))"
huffman@23115
   458
proof (rule summable_norm_comparison_test [OF exI, rule_format])
haftmann@25062
   459
  show "summable (\<lambda>n. norm x ^ n /\<^sub>R real (fact n))"
huffman@23115
   460
    by (rule summable_exp_generic)
huffman@23115
   461
next
haftmann@25062
   462
  fix n show "norm (x ^ n /\<^sub>R real (fact n)) \<le> norm x ^ n /\<^sub>R real (fact n)"
huffman@23115
   463
    by (simp add: norm_scaleR norm_power_ineq)
huffman@23115
   464
qed
huffman@23115
   465
huffman@23043
   466
lemma summable_exp: "summable (%n. inverse (real (fact n)) * x ^ n)"
huffman@23115
   467
by (insert summable_exp_generic [where x=x], simp)
huffman@23043
   468
haftmann@25062
   469
lemma exp_converges: "(\<lambda>n. x ^ n /\<^sub>R real (fact n)) sums exp x"
huffman@23115
   470
unfolding exp_def by (rule summable_exp_generic [THEN summable_sums])
huffman@23043
   471
huffman@23043
   472
paulson@15077
   473
lemma exp_fdiffs: 
paulson@15077
   474
      "diffs (%n. inverse(real (fact n))) = (%n. inverse(real (fact n)))"
huffman@23431
   475
by (simp add: diffs_def mult_assoc [symmetric] real_of_nat_def of_nat_mult
huffman@23082
   476
         del: mult_Suc of_nat_Suc)
paulson@15077
   477
huffman@23115
   478
lemma diffs_of_real: "diffs (\<lambda>n. of_real (f n)) = (\<lambda>n. of_real (diffs f n))"
huffman@23115
   479
by (simp add: diffs_def)
huffman@23115
   480
haftmann@25062
   481
lemma lemma_exp_ext: "exp = (\<lambda>x. \<Sum>n. x ^ n /\<^sub>R real (fact n))"
paulson@15077
   482
by (auto intro!: ext simp add: exp_def)
paulson@15077
   483
paulson@15077
   484
lemma DERIV_exp [simp]: "DERIV exp x :> exp(x)"
paulson@15229
   485
apply (simp add: exp_def)
paulson@15077
   486
apply (subst lemma_exp_ext)
huffman@23115
   487
apply (subgoal_tac "DERIV (\<lambda>u. \<Sum>n. of_real (inverse (real (fact n))) * u ^ n) x :> (\<Sum>n. diffs (\<lambda>n. of_real (inverse (real (fact n)))) n * x ^ n)")
huffman@23115
   488
apply (rule_tac [2] K = "of_real (1 + norm x)" in termdiffs)
huffman@23115
   489
apply (simp_all only: diffs_of_real scaleR_conv_of_real exp_fdiffs)
huffman@23115
   490
apply (rule exp_converges [THEN sums_summable, unfolded scaleR_conv_of_real])+
huffman@23115
   491
apply (simp del: of_real_add)
paulson@15077
   492
done
paulson@15077
   493
huffman@23045
   494
lemma isCont_exp [simp]: "isCont exp x"
huffman@23045
   495
by (rule DERIV_exp [THEN DERIV_isCont])
huffman@23045
   496
huffman@23045
   497
huffman@29167
   498
subsubsection {* Properties of the Exponential Function *}
paulson@15077
   499
huffman@23278
   500
lemma powser_zero:
huffman@23278
   501
  fixes f :: "nat \<Rightarrow> 'a::{real_normed_algebra_1,recpower}"
huffman@23278
   502
  shows "(\<Sum>n. f n * 0 ^ n) = f 0"
paulson@15077
   503
proof -
huffman@23278
   504
  have "(\<Sum>n = 0..<1. f n * 0 ^ n) = (\<Sum>n. f n * 0 ^ n)"
huffman@23115
   505
    by (rule sums_unique [OF series_zero], simp add: power_0_left)
huffman@23278
   506
  thus ?thesis by simp
paulson@15077
   507
qed
paulson@15077
   508
huffman@23278
   509
lemma exp_zero [simp]: "exp 0 = 1"
huffman@23278
   510
unfolding exp_def by (simp add: scaleR_conv_of_real powser_zero)
huffman@23278
   511
huffman@23115
   512
lemma setsum_cl_ivl_Suc2:
huffman@23115
   513
  "(\<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
   514
by (simp add: setsum_head_Suc setsum_shift_bounds_cl_Suc_ivl
huffman@23115
   515
         del: setsum_cl_ivl_Suc)
huffman@23115
   516
huffman@23115
   517
lemma exp_series_add:
huffman@23115
   518
  fixes x y :: "'a::{real_field,recpower}"
haftmann@25062
   519
  defines S_def: "S \<equiv> \<lambda>x n. x ^ n /\<^sub>R real (fact n)"
huffman@23115
   520
  shows "S (x + y) n = (\<Sum>i=0..n. S x i * S y (n - i))"
huffman@23115
   521
proof (induct n)
huffman@23115
   522
  case 0
huffman@23115
   523
  show ?case
huffman@23115
   524
    unfolding S_def by simp
huffman@23115
   525
next
huffman@23115
   526
  case (Suc n)
haftmann@25062
   527
  have S_Suc: "\<And>x n. S x (Suc n) = (x * S x n) /\<^sub>R real (Suc n)"
huffman@23115
   528
    unfolding S_def by (simp add: power_Suc del: mult_Suc)
haftmann@25062
   529
  hence times_S: "\<And>x n. x * S x n = real (Suc n) *\<^sub>R S x (Suc n)"
huffman@23115
   530
    by simp
huffman@23115
   531
haftmann@25062
   532
  have "real (Suc n) *\<^sub>R S (x + y) (Suc n) = (x + y) * S (x + y) n"
huffman@23115
   533
    by (simp only: times_S)
huffman@23115
   534
  also have "\<dots> = (x + y) * (\<Sum>i=0..n. S x i * S y (n-i))"
huffman@23115
   535
    by (simp only: Suc)
huffman@23115
   536
  also have "\<dots> = x * (\<Sum>i=0..n. S x i * S y (n-i))
huffman@23115
   537
                + y * (\<Sum>i=0..n. S x i * S y (n-i))"
huffman@23115
   538
    by (rule left_distrib)
huffman@23115
   539
  also have "\<dots> = (\<Sum>i=0..n. (x * S x i) * S y (n-i))
huffman@23115
   540
                + (\<Sum>i=0..n. S x i * (y * S y (n-i)))"
huffman@23115
   541
    by (simp only: setsum_right_distrib mult_ac)
haftmann@25062
   542
  also have "\<dots> = (\<Sum>i=0..n. real (Suc i) *\<^sub>R (S x (Suc i) * S y (n-i)))
haftmann@25062
   543
                + (\<Sum>i=0..n. real (Suc n-i) *\<^sub>R (S x i * S y (Suc n-i)))"
huffman@23115
   544
    by (simp add: times_S Suc_diff_le)
haftmann@25062
   545
  also have "(\<Sum>i=0..n. real (Suc i) *\<^sub>R (S x (Suc i) * S y (n-i))) =
haftmann@25062
   546
             (\<Sum>i=0..Suc n. real i *\<^sub>R (S x i * S y (Suc n-i)))"
huffman@23115
   547
    by (subst setsum_cl_ivl_Suc2, simp)
haftmann@25062
   548
  also have "(\<Sum>i=0..n. real (Suc n-i) *\<^sub>R (S x i * S y (Suc n-i))) =
haftmann@25062
   549
             (\<Sum>i=0..Suc n. real (Suc n-i) *\<^sub>R (S x i * S y (Suc n-i)))"
huffman@23115
   550
    by (subst setsum_cl_ivl_Suc, simp)
haftmann@25062
   551
  also have "(\<Sum>i=0..Suc n. real i *\<^sub>R (S x i * S y (Suc n-i))) +
haftmann@25062
   552
             (\<Sum>i=0..Suc n. real (Suc n-i) *\<^sub>R (S x i * S y (Suc n-i))) =
haftmann@25062
   553
             (\<Sum>i=0..Suc n. real (Suc n) *\<^sub>R (S x i * S y (Suc n-i)))"
huffman@23115
   554
    by (simp only: setsum_addf [symmetric] scaleR_left_distrib [symmetric]
huffman@23115
   555
              real_of_nat_add [symmetric], simp)
haftmann@25062
   556
  also have "\<dots> = real (Suc n) *\<^sub>R (\<Sum>i=0..Suc n. S x i * S y (Suc n-i))"
huffman@23127
   557
    by (simp only: scaleR_right.setsum)
huffman@23115
   558
  finally show
huffman@23115
   559
    "S (x + y) (Suc n) = (\<Sum>i=0..Suc n. S x i * S y (Suc n - i))"
huffman@23115
   560
    by (simp add: scaleR_cancel_left del: setsum_cl_ivl_Suc)
huffman@23115
   561
qed
huffman@23115
   562
huffman@23115
   563
lemma exp_add: "exp (x + y) = exp x * exp y"
huffman@23115
   564
unfolding exp_def
huffman@23115
   565
by (simp only: Cauchy_product summable_norm_exp exp_series_add)
huffman@23115
   566
huffman@23241
   567
lemma exp_of_real: "exp (of_real x) = of_real (exp x)"
huffman@23241
   568
unfolding exp_def
huffman@23241
   569
apply (subst of_real.suminf)
huffman@23241
   570
apply (rule summable_exp_generic)
huffman@23241
   571
apply (simp add: scaleR_conv_of_real)
huffman@23241
   572
done
huffman@23241
   573
paulson@15077
   574
lemma DERIV_exp_add_const: "DERIV (%x. exp (x + y)) x :> exp(x + y)"
paulson@15077
   575
proof -
paulson@15077
   576
  have "DERIV (exp \<circ> (\<lambda>x. x + y)) x :> exp (x + y) * (1+0)"
huffman@23069
   577
    by (fast intro: DERIV_chain DERIV_add DERIV_exp DERIV_ident DERIV_const) 
paulson@15077
   578
  thus ?thesis by (simp add: o_def)
paulson@15077
   579
qed
paulson@15077
   580
paulson@15077
   581
lemma DERIV_exp_minus [simp]: "DERIV (%x. exp (-x)) x :> - exp(-x)"
paulson@15077
   582
proof -
paulson@15077
   583
  have "DERIV (exp \<circ> uminus) x :> exp (- x) * - 1"
huffman@23069
   584
    by (fast intro: DERIV_chain DERIV_minus DERIV_exp DERIV_ident)
paulson@15077
   585
  thus ?thesis by (simp add: o_def)
paulson@15077
   586
qed
paulson@15077
   587
paulson@15077
   588
lemma DERIV_exp_exp_zero [simp]: "DERIV (%x. exp (x + y) * exp (- x)) x :> 0"
paulson@15077
   589
proof -
paulson@15077
   590
  have "DERIV (\<lambda>x. exp (x + y) * exp (- x)) x
paulson@15077
   591
       :> exp (x + y) * exp (- x) + - exp (- x) * exp (x + y)"
paulson@15077
   592
    by (fast intro: DERIV_exp_add_const DERIV_exp_minus DERIV_mult) 
huffman@23115
   593
  thus ?thesis by (simp add: mult_commute)
paulson@15077
   594
qed
paulson@15077
   595
paulson@15077
   596
lemma exp_mult_minus [simp]: "exp x * exp(-x) = 1"
huffman@23115
   597
by (simp add: exp_add [symmetric])
paulson@15077
   598
paulson@15077
   599
lemma exp_mult_minus2 [simp]: "exp(-x)*exp(x) = 1"
paulson@15077
   600
by (simp add: mult_commute)
paulson@15077
   601
paulson@15077
   602
lemma exp_minus: "exp(-x) = inverse(exp(x))"
paulson@15077
   603
by (auto intro: inverse_unique [symmetric])
paulson@15077
   604
huffman@29167
   605
lemma exp_diff: "exp(x - y) = exp(x)/(exp y)"
huffman@29167
   606
apply (simp add: diff_minus divide_inverse)
huffman@29167
   607
apply (simp add: exp_add exp_minus)
paulson@15077
   608
done
paulson@15077
   609
paulson@15077
   610
lemma exp_not_eq_zero [simp]: "exp x \<noteq> 0"
paulson@15077
   611
apply (cut_tac x = x in exp_mult_minus2)
paulson@15077
   612
apply (auto simp del: exp_mult_minus2)
paulson@15077
   613
done
paulson@15077
   614
huffman@29167
   615
huffman@29167
   616
subsubsection {* Properties of the Exponential Function on Reals *}
huffman@29167
   617
huffman@29167
   618
lemma exp_ge_add_one_self_aux: "0 \<le> (x::real) ==> (1 + x) \<le> exp(x)"
huffman@29167
   619
apply (drule order_le_imp_less_or_eq, auto)
huffman@29167
   620
apply (simp add: exp_def)
huffman@29167
   621
apply (rule real_le_trans)
huffman@29167
   622
apply (rule_tac [2] n = 2 and f = "(%n. inverse (real (fact n)) * x ^ n)" in series_pos_le)
huffman@29167
   623
apply (auto intro: summable_exp simp add: numeral_2_eq_2 zero_le_mult_iff)
huffman@29167
   624
done
huffman@29167
   625
huffman@29167
   626
lemma exp_gt_one [simp]: "0 < (x::real) ==> 1 < exp x"
huffman@29167
   627
apply (rule order_less_le_trans)
huffman@29167
   628
apply (rule_tac [2] exp_ge_add_one_self_aux, auto)
huffman@29167
   629
done
huffman@29167
   630
huffman@29167
   631
lemma exp_add_mult_minus [simp]: "exp(x + y)*exp(-x) = exp(y::real)"
huffman@29167
   632
by (simp add: exp_add [symmetric])
huffman@29167
   633
huffman@29167
   634
text{*Proof: because every exponential can be seen as a square.*}
huffman@29167
   635
lemma exp_ge_zero [simp]: "0 \<le> exp (x::real)"
huffman@29167
   636
proof -
huffman@29167
   637
  have "0 \<le> exp (x/2) * exp (x/2)" by simp
huffman@29167
   638
  thus ?thesis by (simp add: exp_add [symmetric])
huffman@29167
   639
qed
huffman@29167
   640
huffman@23115
   641
lemma exp_gt_zero [simp]: "0 < exp (x::real)"
paulson@15077
   642
by (simp add: order_less_le)
paulson@15077
   643
huffman@29165
   644
lemma inv_exp_gt_zero: "0 < inverse(exp x::real)"
huffman@29165
   645
by simp
paulson@15077
   646
huffman@23115
   647
lemma abs_exp_cancel [simp]: "\<bar>exp x::real\<bar> = exp x"
huffman@29165
   648
by simp
paulson@15077
   649
paulson@15077
   650
lemma exp_real_of_nat_mult: "exp(real n * x) = exp(x) ^ n"
paulson@15251
   651
apply (induct "n")
paulson@15077
   652
apply (auto simp add: real_of_nat_Suc right_distrib exp_add mult_commute)
paulson@15077
   653
done
paulson@15077
   654
paulson@15077
   655
lemma exp_less_mono:
huffman@23115
   656
  fixes x y :: real
huffman@29165
   657
  assumes "x < y" shows "exp x < exp y"
paulson@15077
   658
proof -
huffman@29165
   659
  from `x < y` have "0 < y - x" by simp
huffman@29165
   660
  hence "1 < exp (y - x)" by (rule exp_gt_one)
huffman@29165
   661
  hence "1 < exp y / exp x" by (simp only: exp_diff)
huffman@29165
   662
  thus "exp x < exp y" by simp
paulson@15077
   663
qed
paulson@15077
   664
huffman@23115
   665
lemma exp_less_cancel: "exp (x::real) < exp y ==> x < y"
paulson@15228
   666
apply (simp add: linorder_not_le [symmetric]) 
paulson@15228
   667
apply (auto simp add: order_le_less exp_less_mono) 
paulson@15077
   668
done
paulson@15077
   669
huffman@23115
   670
lemma exp_less_cancel_iff [iff]: "(exp(x::real) < exp(y)) = (x < y)"
paulson@15077
   671
by (auto intro: exp_less_mono exp_less_cancel)
paulson@15077
   672
huffman@23115
   673
lemma exp_le_cancel_iff [iff]: "(exp(x::real) \<le> exp(y)) = (x \<le> y)"
paulson@15077
   674
by (auto simp add: linorder_not_less [symmetric])
paulson@15077
   675
huffman@23115
   676
lemma exp_inj_iff [iff]: "(exp (x::real) = exp y) = (x = y)"
paulson@15077
   677
by (simp add: order_eq_iff)
paulson@15077
   678
huffman@23115
   679
lemma lemma_exp_total: "1 \<le> y ==> \<exists>x. 0 \<le> x & x \<le> y - 1 & exp(x::real) = y"
paulson@15077
   680
apply (rule IVT)
huffman@23045
   681
apply (auto intro: isCont_exp simp add: le_diff_eq)
paulson@15077
   682
apply (subgoal_tac "1 + (y - 1) \<le> exp (y - 1)") 
huffman@29165
   683
apply simp
avigad@17014
   684
apply (rule exp_ge_add_one_self_aux, simp)
paulson@15077
   685
done
paulson@15077
   686
huffman@23115
   687
lemma exp_total: "0 < (y::real) ==> \<exists>x. exp x = y"
paulson@15077
   688
apply (rule_tac x = 1 and y = y in linorder_cases)
paulson@15077
   689
apply (drule order_less_imp_le [THEN lemma_exp_total])
paulson@15077
   690
apply (rule_tac [2] x = 0 in exI)
paulson@15077
   691
apply (frule_tac [3] real_inverse_gt_one)
paulson@15077
   692
apply (drule_tac [4] order_less_imp_le [THEN lemma_exp_total], auto)
paulson@15077
   693
apply (rule_tac x = "-x" in exI)
paulson@15077
   694
apply (simp add: exp_minus)
paulson@15077
   695
done
paulson@15077
   696
paulson@15077
   697
huffman@29164
   698
subsection {* Natural Logarithm *}
paulson@15077
   699
huffman@23043
   700
definition
huffman@23043
   701
  ln :: "real => real" where
huffman@23043
   702
  "ln x = (THE u. exp u = x)"
huffman@23043
   703
huffman@23043
   704
lemma ln_exp [simp]: "ln (exp x) = x"
paulson@15077
   705
by (simp add: ln_def)
paulson@15077
   706
huffman@22654
   707
lemma exp_ln [simp]: "0 < x \<Longrightarrow> exp (ln x) = x"
huffman@22654
   708
by (auto dest: exp_total)
huffman@22654
   709
huffman@23043
   710
lemma exp_ln_iff [simp]: "(exp (ln x) = x) = (0 < x)"
paulson@15077
   711
apply (auto dest: exp_total)
paulson@15077
   712
apply (erule subst, simp) 
paulson@15077
   713
done
paulson@15077
   714
paulson@15077
   715
lemma ln_mult: "[| 0 < x; 0 < y |] ==> ln(x * y) = ln(x) + ln(y)"
paulson@15077
   716
apply (rule exp_inj_iff [THEN iffD1])
huffman@22654
   717
apply (simp add: exp_add exp_ln mult_pos_pos)
paulson@15077
   718
done
paulson@15077
   719
paulson@15077
   720
lemma ln_inj_iff[simp]: "[| 0 < x; 0 < y |] ==> (ln x = ln y) = (x = y)"
paulson@15077
   721
apply (simp only: exp_ln_iff [symmetric])
paulson@15077
   722
apply (erule subst)+
paulson@15077
   723
apply simp 
paulson@15077
   724
done
paulson@15077
   725
paulson@15077
   726
lemma ln_one[simp]: "ln 1 = 0"
paulson@15077
   727
by (rule exp_inj_iff [THEN iffD1], auto)
paulson@15077
   728
paulson@15077
   729
lemma ln_inverse: "0 < x ==> ln(inverse x) = - ln x"
paulson@15077
   730
apply (rule_tac a1 = "ln x" in add_left_cancel [THEN iffD1])
paulson@15077
   731
apply (auto simp add: positive_imp_inverse_positive ln_mult [symmetric])
paulson@15077
   732
done
paulson@15077
   733
paulson@15077
   734
lemma ln_div: 
paulson@15077
   735
    "[|0 < x; 0 < y|] ==> ln(x/y) = ln x - ln y"
paulson@15229
   736
apply (simp add: divide_inverse)
paulson@15077
   737
apply (auto simp add: positive_imp_inverse_positive ln_mult ln_inverse)
paulson@15077
   738
done
paulson@15077
   739
paulson@15077
   740
lemma ln_less_cancel_iff[simp]: "[| 0 < x; 0 < y|] ==> (ln x < ln y) = (x < y)"
paulson@15077
   741
apply (simp only: exp_ln_iff [symmetric])
paulson@15077
   742
apply (erule subst)+
paulson@15077
   743
apply simp 
paulson@15077
   744
done
paulson@15077
   745
paulson@15077
   746
lemma ln_le_cancel_iff[simp]: "[| 0 < x; 0 < y|] ==> (ln x \<le> ln y) = (x \<le> y)"
paulson@15077
   747
by (auto simp add: linorder_not_less [symmetric])
paulson@15077
   748
paulson@15077
   749
lemma ln_realpow: "0 < x ==> ln(x ^ n) = real n * ln(x)"
paulson@15077
   750
by (auto dest!: exp_total simp add: exp_real_of_nat_mult [symmetric])
paulson@15077
   751
paulson@15077
   752
lemma ln_add_one_self_le_self [simp]: "0 \<le> x ==> ln(1 + x) \<le> x"
paulson@15077
   753
apply (rule ln_exp [THEN subst])
avigad@17014
   754
apply (rule ln_le_cancel_iff [THEN iffD2]) 
avigad@17014
   755
apply (auto simp add: exp_ge_add_one_self_aux)
paulson@15077
   756
done
paulson@15077
   757
paulson@15077
   758
lemma ln_less_self [simp]: "0 < x ==> ln x < x"
paulson@15077
   759
apply (rule order_less_le_trans)
paulson@15077
   760
apply (rule_tac [2] ln_add_one_self_le_self)
paulson@15077
   761
apply (rule ln_less_cancel_iff [THEN iffD2], auto)
paulson@15077
   762
done
paulson@15077
   763
paulson@15234
   764
lemma ln_ge_zero [simp]:
paulson@15077
   765
  assumes x: "1 \<le> x" shows "0 \<le> ln x"
paulson@15077
   766
proof -
paulson@15077
   767
  have "0 < x" using x by arith
paulson@15077
   768
  hence "exp 0 \<le> exp (ln x)"
huffman@22915
   769
    by (simp add: x)
paulson@15077
   770
  thus ?thesis by (simp only: exp_le_cancel_iff)
paulson@15077
   771
qed
paulson@15077
   772
paulson@15077
   773
lemma ln_ge_zero_imp_ge_one:
paulson@15077
   774
  assumes ln: "0 \<le> ln x" 
paulson@15077
   775
      and x:  "0 < x"
paulson@15077
   776
  shows "1 \<le> x"
paulson@15077
   777
proof -
paulson@15077
   778
  from ln have "ln 1 \<le> ln x" by simp
paulson@15077
   779
  thus ?thesis by (simp add: x del: ln_one) 
paulson@15077
   780
qed
paulson@15077
   781
paulson@15077
   782
lemma ln_ge_zero_iff [simp]: "0 < x ==> (0 \<le> ln x) = (1 \<le> x)"
paulson@15077
   783
by (blast intro: ln_ge_zero ln_ge_zero_imp_ge_one)
paulson@15077
   784
paulson@15234
   785
lemma ln_less_zero_iff [simp]: "0 < x ==> (ln x < 0) = (x < 1)"
paulson@15234
   786
by (insert ln_ge_zero_iff [of x], arith)
paulson@15234
   787
paulson@15077
   788
lemma ln_gt_zero:
paulson@15077
   789
  assumes x: "1 < x" shows "0 < ln x"
paulson@15077
   790
proof -
paulson@15077
   791
  have "0 < x" using x by arith
huffman@22915
   792
  hence "exp 0 < exp (ln x)" by (simp add: x)
paulson@15077
   793
  thus ?thesis  by (simp only: exp_less_cancel_iff)
paulson@15077
   794
qed
paulson@15077
   795
paulson@15077
   796
lemma ln_gt_zero_imp_gt_one:
paulson@15077
   797
  assumes ln: "0 < ln x" 
paulson@15077
   798
      and x:  "0 < x"
paulson@15077
   799
  shows "1 < x"
paulson@15077
   800
proof -
paulson@15077
   801
  from ln have "ln 1 < ln x" by simp
paulson@15077
   802
  thus ?thesis by (simp add: x del: ln_one) 
paulson@15077
   803
qed
paulson@15077
   804
paulson@15077
   805
lemma ln_gt_zero_iff [simp]: "0 < x ==> (0 < ln x) = (1 < x)"
paulson@15077
   806
by (blast intro: ln_gt_zero ln_gt_zero_imp_gt_one)
paulson@15077
   807
paulson@15234
   808
lemma ln_eq_zero_iff [simp]: "0 < x ==> (ln x = 0) = (x = 1)"
paulson@15234
   809
by (insert ln_less_zero_iff [of x] ln_gt_zero_iff [of x], arith)
paulson@15077
   810
paulson@15077
   811
lemma ln_less_zero: "[| 0 < x; x < 1 |] ==> ln x < 0"
paulson@15234
   812
by simp
paulson@15077
   813
paulson@15077
   814
lemma exp_ln_eq: "exp u = x ==> ln x = u"
paulson@15077
   815
by auto
paulson@15077
   816
huffman@23045
   817
lemma isCont_ln: "0 < x \<Longrightarrow> isCont ln x"
huffman@23045
   818
apply (subgoal_tac "isCont ln (exp (ln x))", simp)
huffman@23045
   819
apply (rule isCont_inverse_function [where f=exp], simp_all)
huffman@23045
   820
done
huffman@23045
   821
huffman@23045
   822
lemma DERIV_ln: "0 < x \<Longrightarrow> DERIV ln x :> inverse x"
huffman@23045
   823
apply (rule DERIV_inverse_function [where f=exp and a=0 and b="x+1"])
huffman@23045
   824
apply (erule lemma_DERIV_subst [OF DERIV_exp exp_ln])
huffman@23045
   825
apply (simp_all add: abs_if isCont_ln)
huffman@23045
   826
done
huffman@23045
   827
paulson@15077
   828
huffman@29164
   829
subsection {* Sine and Cosine *}
huffman@29164
   830
huffman@29164
   831
definition
huffman@29164
   832
  sin :: "real => real" where
huffman@29164
   833
  "sin x = (\<Sum>n. (if even(n) then 0 else
huffman@29164
   834
             (-1 ^ ((n - Suc 0) div 2))/(real (fact n))) * x ^ n)"
huffman@29164
   835
 
huffman@29164
   836
definition
huffman@29164
   837
  cos :: "real => real" where
huffman@29164
   838
  "cos x = (\<Sum>n. (if even(n) then (-1 ^ (n div 2))/(real (fact n)) 
huffman@29164
   839
                            else 0) * x ^ n)"
huffman@29164
   840
huffman@29164
   841
lemma summable_sin: 
huffman@29164
   842
     "summable (%n.  
huffman@29164
   843
           (if even n then 0  
huffman@29164
   844
           else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) *  
huffman@29164
   845
                x ^ n)"
huffman@29164
   846
apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test)
huffman@29164
   847
apply (rule_tac [2] summable_exp)
huffman@29164
   848
apply (rule_tac x = 0 in exI)
huffman@29164
   849
apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
huffman@29164
   850
done
huffman@29164
   851
huffman@29164
   852
lemma summable_cos: 
huffman@29164
   853
      "summable (%n.  
huffman@29164
   854
           (if even n then  
huffman@29164
   855
           -1 ^ (n div 2)/(real (fact n)) else 0) * x ^ n)"
huffman@29164
   856
apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test)
huffman@29164
   857
apply (rule_tac [2] summable_exp)
huffman@29164
   858
apply (rule_tac x = 0 in exI)
huffman@29164
   859
apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
huffman@29164
   860
done
huffman@29164
   861
huffman@29164
   862
lemma lemma_STAR_sin:
huffman@29164
   863
     "(if even n then 0  
huffman@29164
   864
       else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * 0 ^ n = 0"
huffman@29164
   865
by (induct "n", auto)
huffman@29164
   866
huffman@29164
   867
lemma lemma_STAR_cos:
huffman@29164
   868
     "0 < n -->  
huffman@29164
   869
      -1 ^ (n div 2)/(real (fact n)) * 0 ^ n = 0"
huffman@29164
   870
by (induct "n", auto)
huffman@29164
   871
huffman@29164
   872
lemma lemma_STAR_cos1:
huffman@29164
   873
     "0 < n -->  
huffman@29164
   874
      (-1) ^ (n div 2)/(real (fact n)) * 0 ^ n = 0"
huffman@29164
   875
by (induct "n", auto)
huffman@29164
   876
huffman@29164
   877
lemma lemma_STAR_cos2:
huffman@29164
   878
  "(\<Sum>n=1..<n. if even n then -1 ^ (n div 2)/(real (fact n)) *  0 ^ n 
huffman@29164
   879
                         else 0) = 0"
huffman@29164
   880
apply (induct "n")
huffman@29164
   881
apply (case_tac [2] "n", auto)
huffman@29164
   882
done
huffman@29164
   883
huffman@29164
   884
lemma sin_converges: 
huffman@29164
   885
      "(%n. (if even n then 0  
huffman@29164
   886
            else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) *  
huffman@29164
   887
                 x ^ n) sums sin(x)"
huffman@29164
   888
unfolding sin_def by (rule summable_sin [THEN summable_sums])
huffman@29164
   889
huffman@29164
   890
lemma cos_converges: 
huffman@29164
   891
      "(%n. (if even n then  
huffman@29164
   892
           -1 ^ (n div 2)/(real (fact n))  
huffman@29164
   893
           else 0) * x ^ n) sums cos(x)"
huffman@29164
   894
unfolding cos_def by (rule summable_cos [THEN summable_sums])
huffman@29164
   895
huffman@29164
   896
lemma sin_fdiffs: 
huffman@29164
   897
      "diffs(%n. if even n then 0  
huffman@29164
   898
           else -1 ^ ((n - Suc 0) div 2)/(real (fact n)))  
huffman@29164
   899
       = (%n. if even n then  
huffman@29164
   900
                 -1 ^ (n div 2)/(real (fact n))  
huffman@29164
   901
              else 0)"
huffman@29164
   902
by (auto intro!: ext 
huffman@29164
   903
         simp add: diffs_def divide_inverse real_of_nat_def of_nat_mult
huffman@29164
   904
         simp del: mult_Suc of_nat_Suc)
huffman@29164
   905
huffman@29164
   906
lemma sin_fdiffs2: 
huffman@29164
   907
       "diffs(%n. if even n then 0  
huffman@29164
   908
           else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) n  
huffman@29164
   909
       = (if even n then  
huffman@29164
   910
                 -1 ^ (n div 2)/(real (fact n))  
huffman@29164
   911
              else 0)"
huffman@29164
   912
by (simp only: sin_fdiffs)
huffman@29164
   913
huffman@29164
   914
lemma cos_fdiffs: 
huffman@29164
   915
      "diffs(%n. if even n then  
huffman@29164
   916
                 -1 ^ (n div 2)/(real (fact n)) else 0)  
huffman@29164
   917
       = (%n. - (if even n then 0  
huffman@29164
   918
           else -1 ^ ((n - Suc 0)div 2)/(real (fact n))))"
huffman@29164
   919
by (auto intro!: ext 
huffman@29164
   920
         simp add: diffs_def divide_inverse odd_Suc_mult_two_ex real_of_nat_def of_nat_mult
huffman@29164
   921
         simp del: mult_Suc of_nat_Suc)
huffman@29164
   922
huffman@29164
   923
huffman@29164
   924
lemma cos_fdiffs2: 
huffman@29164
   925
      "diffs(%n. if even n then  
huffman@29164
   926
                 -1 ^ (n div 2)/(real (fact n)) else 0) n 
huffman@29164
   927
       = - (if even n then 0  
huffman@29164
   928
           else -1 ^ ((n - Suc 0)div 2)/(real (fact n)))"
huffman@29164
   929
by (simp only: cos_fdiffs)
huffman@29164
   930
huffman@29164
   931
text{*Now at last we can get the derivatives of exp, sin and cos*}
huffman@29164
   932
huffman@29164
   933
lemma lemma_sin_minus:
huffman@29164
   934
     "- sin x = (\<Sum>n. - ((if even n then 0 
huffman@29164
   935
                  else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * x ^ n))"
huffman@29164
   936
by (auto intro!: sums_unique sums_minus sin_converges)
huffman@29164
   937
huffman@29164
   938
lemma lemma_sin_ext:
huffman@29164
   939
     "sin = (%x. \<Sum>n. 
huffman@29164
   940
                   (if even n then 0  
huffman@29164
   941
                       else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) *  
huffman@29164
   942
                   x ^ n)"
huffman@29164
   943
by (auto intro!: ext simp add: sin_def)
huffman@29164
   944
huffman@29164
   945
lemma lemma_cos_ext:
huffman@29164
   946
     "cos = (%x. \<Sum>n. 
huffman@29164
   947
                   (if even n then -1 ^ (n div 2)/(real (fact n)) else 0) *
huffman@29164
   948
                   x ^ n)"
huffman@29164
   949
by (auto intro!: ext simp add: cos_def)
huffman@29164
   950
huffman@29164
   951
lemma DERIV_sin [simp]: "DERIV sin x :> cos(x)"
huffman@29164
   952
apply (simp add: cos_def)
huffman@29164
   953
apply (subst lemma_sin_ext)
huffman@29164
   954
apply (auto simp add: sin_fdiffs2 [symmetric])
huffman@29164
   955
apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs)
huffman@29164
   956
apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs)
huffman@29164
   957
done
huffman@29164
   958
huffman@29164
   959
lemma DERIV_cos [simp]: "DERIV cos x :> -sin(x)"
huffman@29164
   960
apply (subst lemma_cos_ext)
huffman@29164
   961
apply (auto simp add: lemma_sin_minus cos_fdiffs2 [symmetric] minus_mult_left)
huffman@29164
   962
apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs)
huffman@29164
   963
apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs diffs_minus)
huffman@29164
   964
done
huffman@29164
   965
huffman@29164
   966
lemma isCont_sin [simp]: "isCont sin x"
huffman@29164
   967
by (rule DERIV_sin [THEN DERIV_isCont])
huffman@29164
   968
huffman@29164
   969
lemma isCont_cos [simp]: "isCont cos x"
huffman@29164
   970
by (rule DERIV_cos [THEN DERIV_isCont])
huffman@29164
   971
huffman@29164
   972
huffman@29164
   973
subsection {* Properties of Sine and Cosine *}
paulson@15077
   974
paulson@15077
   975
lemma sin_zero [simp]: "sin 0 = 0"
huffman@23278
   976
unfolding sin_def by (simp add: powser_zero)
paulson@15077
   977
paulson@15077
   978
lemma cos_zero [simp]: "cos 0 = 1"
huffman@23278
   979
unfolding cos_def by (simp add: powser_zero)
paulson@15077
   980
paulson@15077
   981
lemma DERIV_sin_sin_mult [simp]:
paulson@15077
   982
     "DERIV (%x. sin(x)*sin(x)) x :> cos(x) * sin(x) + cos(x) * sin(x)"
paulson@15077
   983
by (rule DERIV_mult, auto)
paulson@15077
   984
paulson@15077
   985
lemma DERIV_sin_sin_mult2 [simp]:
paulson@15077
   986
     "DERIV (%x. sin(x)*sin(x)) x :> 2 * cos(x) * sin(x)"
paulson@15077
   987
apply (cut_tac x = x in DERIV_sin_sin_mult)
paulson@15077
   988
apply (auto simp add: mult_assoc)
paulson@15077
   989
done
paulson@15077
   990
paulson@15077
   991
lemma DERIV_sin_realpow2 [simp]:
paulson@15077
   992
     "DERIV (%x. (sin x)\<twosuperior>) x :> cos(x) * sin(x) + cos(x) * sin(x)"
paulson@15077
   993
by (auto simp add: numeral_2_eq_2 real_mult_assoc [symmetric])
paulson@15077
   994
paulson@15077
   995
lemma DERIV_sin_realpow2a [simp]:
paulson@15077
   996
     "DERIV (%x. (sin x)\<twosuperior>) x :> 2 * cos(x) * sin(x)"
paulson@15077
   997
by (auto simp add: numeral_2_eq_2)
paulson@15077
   998
paulson@15077
   999
lemma DERIV_cos_cos_mult [simp]:
paulson@15077
  1000
     "DERIV (%x. cos(x)*cos(x)) x :> -sin(x) * cos(x) + -sin(x) * cos(x)"
paulson@15077
  1001
by (rule DERIV_mult, auto)
paulson@15077
  1002
paulson@15077
  1003
lemma DERIV_cos_cos_mult2 [simp]:
paulson@15077
  1004
     "DERIV (%x. cos(x)*cos(x)) x :> -2 * cos(x) * sin(x)"
paulson@15077
  1005
apply (cut_tac x = x in DERIV_cos_cos_mult)
paulson@15077
  1006
apply (auto simp add: mult_ac)
paulson@15077
  1007
done
paulson@15077
  1008
paulson@15077
  1009
lemma DERIV_cos_realpow2 [simp]:
paulson@15077
  1010
     "DERIV (%x. (cos x)\<twosuperior>) x :> -sin(x) * cos(x) + -sin(x) * cos(x)"
paulson@15077
  1011
by (auto simp add: numeral_2_eq_2 real_mult_assoc [symmetric])
paulson@15077
  1012
paulson@15077
  1013
lemma DERIV_cos_realpow2a [simp]:
paulson@15077
  1014
     "DERIV (%x. (cos x)\<twosuperior>) x :> -2 * cos(x) * sin(x)"
paulson@15077
  1015
by (auto simp add: numeral_2_eq_2)
paulson@15077
  1016
paulson@15077
  1017
lemma lemma_DERIV_subst: "[| DERIV f x :> D; D = E |] ==> DERIV f x :> E"
paulson@15077
  1018
by auto
paulson@15077
  1019
paulson@15077
  1020
lemma DERIV_cos_realpow2b: "DERIV (%x. (cos x)\<twosuperior>) x :> -(2 * cos(x) * sin(x))"
paulson@15077
  1021
apply (rule lemma_DERIV_subst)
paulson@15077
  1022
apply (rule DERIV_cos_realpow2a, auto)
paulson@15077
  1023
done
paulson@15077
  1024
paulson@15077
  1025
(* most useful *)
paulson@15229
  1026
lemma DERIV_cos_cos_mult3 [simp]:
paulson@15229
  1027
     "DERIV (%x. cos(x)*cos(x)) x :> -(2 * cos(x) * sin(x))"
paulson@15077
  1028
apply (rule lemma_DERIV_subst)
paulson@15077
  1029
apply (rule DERIV_cos_cos_mult2, auto)
paulson@15077
  1030
done
paulson@15077
  1031
paulson@15077
  1032
lemma DERIV_sin_circle_all: 
paulson@15077
  1033
     "\<forall>x. DERIV (%x. (sin x)\<twosuperior> + (cos x)\<twosuperior>) x :>  
paulson@15077
  1034
             (2*cos(x)*sin(x) - 2*cos(x)*sin(x))"
paulson@15229
  1035
apply (simp only: diff_minus, safe)
paulson@15229
  1036
apply (rule DERIV_add) 
paulson@15077
  1037
apply (auto simp add: numeral_2_eq_2)
paulson@15077
  1038
done
paulson@15077
  1039
paulson@15229
  1040
lemma DERIV_sin_circle_all_zero [simp]:
paulson@15229
  1041
     "\<forall>x. DERIV (%x. (sin x)\<twosuperior> + (cos x)\<twosuperior>) x :> 0"
paulson@15077
  1042
by (cut_tac DERIV_sin_circle_all, auto)
paulson@15077
  1043
paulson@15077
  1044
lemma sin_cos_squared_add [simp]: "((sin x)\<twosuperior>) + ((cos x)\<twosuperior>) = 1"
paulson@15077
  1045
apply (cut_tac x = x and y = 0 in DERIV_sin_circle_all_zero [THEN DERIV_isconst_all])
paulson@15077
  1046
apply (auto simp add: numeral_2_eq_2)
paulson@15077
  1047
done
paulson@15077
  1048
paulson@15077
  1049
lemma sin_cos_squared_add2 [simp]: "((cos x)\<twosuperior>) + ((sin x)\<twosuperior>) = 1"
huffman@23286
  1050
apply (subst add_commute)
paulson@15077
  1051
apply (simp (no_asm) del: realpow_Suc)
paulson@15077
  1052
done
paulson@15077
  1053
paulson@15077
  1054
lemma sin_cos_squared_add3 [simp]: "cos x * cos x + sin x * sin x = 1"
paulson@15077
  1055
apply (cut_tac x = x in sin_cos_squared_add2)
paulson@15077
  1056
apply (auto simp add: numeral_2_eq_2)
paulson@15077
  1057
done
paulson@15077
  1058
paulson@15077
  1059
lemma sin_squared_eq: "(sin x)\<twosuperior> = 1 - (cos x)\<twosuperior>"
paulson@15229
  1060
apply (rule_tac a1 = "(cos x)\<twosuperior>" in add_right_cancel [THEN iffD1])
paulson@15077
  1061
apply (simp del: realpow_Suc)
paulson@15077
  1062
done
paulson@15077
  1063
paulson@15077
  1064
lemma cos_squared_eq: "(cos x)\<twosuperior> = 1 - (sin x)\<twosuperior>"
paulson@15077
  1065
apply (rule_tac a1 = "(sin x)\<twosuperior>" in add_right_cancel [THEN iffD1])
paulson@15077
  1066
apply (simp del: realpow_Suc)
paulson@15077
  1067
done
paulson@15077
  1068
paulson@15081
  1069
lemma abs_sin_le_one [simp]: "\<bar>sin x\<bar> \<le> 1"
huffman@23097
  1070
by (rule power2_le_imp_le, simp_all add: sin_squared_eq)
paulson@15077
  1071
paulson@15077
  1072
lemma sin_ge_minus_one [simp]: "-1 \<le> sin x"
paulson@15077
  1073
apply (insert abs_sin_le_one [of x]) 
huffman@22998
  1074
apply (simp add: abs_le_iff del: abs_sin_le_one) 
paulson@15077
  1075
done
paulson@15077
  1076
paulson@15077
  1077
lemma sin_le_one [simp]: "sin x \<le> 1"
paulson@15077
  1078
apply (insert abs_sin_le_one [of x]) 
huffman@22998
  1079
apply (simp add: abs_le_iff del: abs_sin_le_one) 
paulson@15077
  1080
done
paulson@15077
  1081
paulson@15081
  1082
lemma abs_cos_le_one [simp]: "\<bar>cos x\<bar> \<le> 1"
huffman@23097
  1083
by (rule power2_le_imp_le, simp_all add: cos_squared_eq)
paulson@15077
  1084
paulson@15077
  1085
lemma cos_ge_minus_one [simp]: "-1 \<le> cos x"
paulson@15077
  1086
apply (insert abs_cos_le_one [of x]) 
huffman@22998
  1087
apply (simp add: abs_le_iff del: abs_cos_le_one) 
paulson@15077
  1088
done
paulson@15077
  1089
paulson@15077
  1090
lemma cos_le_one [simp]: "cos x \<le> 1"
paulson@15077
  1091
apply (insert abs_cos_le_one [of x]) 
huffman@22998
  1092
apply (simp add: abs_le_iff del: abs_cos_le_one)
paulson@15077
  1093
done
paulson@15077
  1094
paulson@15077
  1095
lemma DERIV_fun_pow: "DERIV g x :> m ==>  
paulson@15077
  1096
      DERIV (%x. (g x) ^ n) x :> real n * (g x) ^ (n - 1) * m"
paulson@15077
  1097
apply (rule lemma_DERIV_subst)
paulson@15229
  1098
apply (rule_tac f = "(%x. x ^ n)" in DERIV_chain2)
paulson@15077
  1099
apply (rule DERIV_pow, auto)
paulson@15077
  1100
done
paulson@15077
  1101
paulson@15229
  1102
lemma DERIV_fun_exp:
paulson@15229
  1103
     "DERIV g x :> m ==> DERIV (%x. exp(g x)) x :> exp(g x) * m"
paulson@15077
  1104
apply (rule lemma_DERIV_subst)
paulson@15077
  1105
apply (rule_tac f = exp in DERIV_chain2)
paulson@15077
  1106
apply (rule DERIV_exp, auto)
paulson@15077
  1107
done
paulson@15077
  1108
paulson@15229
  1109
lemma DERIV_fun_sin:
paulson@15229
  1110
     "DERIV g x :> m ==> DERIV (%x. sin(g x)) x :> cos(g x) * m"
paulson@15077
  1111
apply (rule lemma_DERIV_subst)
paulson@15077
  1112
apply (rule_tac f = sin in DERIV_chain2)
paulson@15077
  1113
apply (rule DERIV_sin, auto)
paulson@15077
  1114
done
paulson@15077
  1115
paulson@15229
  1116
lemma DERIV_fun_cos:
paulson@15229
  1117
     "DERIV g x :> m ==> DERIV (%x. cos(g x)) x :> -sin(g x) * m"
paulson@15077
  1118
apply (rule lemma_DERIV_subst)
paulson@15077
  1119
apply (rule_tac f = cos in DERIV_chain2)
paulson@15077
  1120
apply (rule DERIV_cos, auto)
paulson@15077
  1121
done
paulson@15077
  1122
huffman@23069
  1123
lemmas DERIV_intros = DERIV_ident DERIV_const DERIV_cos DERIV_cmult 
paulson@15077
  1124
                    DERIV_sin  DERIV_exp  DERIV_inverse DERIV_pow 
paulson@15077
  1125
                    DERIV_add  DERIV_diff  DERIV_mult  DERIV_minus 
paulson@15077
  1126
                    DERIV_inverse_fun DERIV_quotient DERIV_fun_pow 
paulson@15077
  1127
                    DERIV_fun_exp DERIV_fun_sin DERIV_fun_cos 
paulson@15077
  1128
paulson@15077
  1129
(* lemma *)
paulson@15229
  1130
lemma lemma_DERIV_sin_cos_add:
paulson@15229
  1131
     "\<forall>x.  
paulson@15077
  1132
         DERIV (%x. (sin (x + y) - (sin x * cos y + cos x * sin y)) ^ 2 +  
paulson@15077
  1133
               (cos (x + y) - (cos x * cos y - sin x * sin y)) ^ 2) x :> 0"
paulson@15077
  1134
apply (safe, rule lemma_DERIV_subst)
paulson@15077
  1135
apply (best intro!: DERIV_intros intro: DERIV_chain2) 
paulson@15077
  1136
  --{*replaces the old @{text DERIV_tac}*}
paulson@15229
  1137
apply (auto simp add: diff_minus left_distrib right_distrib mult_ac add_ac)
paulson@15077
  1138
done
paulson@15077
  1139
paulson@15077
  1140
lemma sin_cos_add [simp]:
paulson@15077
  1141
     "(sin (x + y) - (sin x * cos y + cos x * sin y)) ^ 2 +  
paulson@15077
  1142
      (cos (x + y) - (cos x * cos y - sin x * sin y)) ^ 2 = 0"
paulson@15077
  1143
apply (cut_tac y = 0 and x = x and y7 = y 
paulson@15077
  1144
       in lemma_DERIV_sin_cos_add [THEN DERIV_isconst_all])
paulson@15077
  1145
apply (auto simp add: numeral_2_eq_2)
paulson@15077
  1146
done
paulson@15077
  1147
paulson@15077
  1148
lemma sin_add: "sin (x + y) = sin x * cos y + cos x * sin y"
paulson@15077
  1149
apply (cut_tac x = x and y = y in sin_cos_add)
huffman@22969
  1150
apply (simp del: sin_cos_add)
paulson@15077
  1151
done
paulson@15077
  1152
paulson@15077
  1153
lemma cos_add: "cos (x + y) = cos x * cos y - sin x * sin y"
paulson@15077
  1154
apply (cut_tac x = x and y = y in sin_cos_add)
huffman@22969
  1155
apply (simp del: sin_cos_add)
paulson@15077
  1156
done
paulson@15077
  1157
paulson@15085
  1158
lemma lemma_DERIV_sin_cos_minus:
paulson@15085
  1159
    "\<forall>x. DERIV (%x. (sin(-x) + (sin x)) ^ 2 + (cos(-x) - (cos x)) ^ 2) x :> 0"
paulson@15077
  1160
apply (safe, rule lemma_DERIV_subst)
paulson@15077
  1161
apply (best intro!: DERIV_intros intro: DERIV_chain2) 
paulson@15229
  1162
apply (auto simp add: diff_minus left_distrib right_distrib mult_ac add_ac)
paulson@15077
  1163
done
paulson@15077
  1164
huffman@29165
  1165
lemma sin_cos_minus: 
paulson@15085
  1166
    "(sin(-x) + (sin x)) ^ 2 + (cos(-x) - (cos x)) ^ 2 = 0"
paulson@15085
  1167
apply (cut_tac y = 0 and x = x 
paulson@15085
  1168
       in lemma_DERIV_sin_cos_minus [THEN DERIV_isconst_all])
huffman@22969
  1169
apply simp
paulson@15077
  1170
done
paulson@15077
  1171
paulson@15077
  1172
lemma sin_minus [simp]: "sin (-x) = -sin(x)"
huffman@29165
  1173
  using sin_cos_minus [where x=x] by simp
paulson@15077
  1174
paulson@15077
  1175
lemma cos_minus [simp]: "cos (-x) = cos(x)"
huffman@29165
  1176
  using sin_cos_minus [where x=x] by simp
paulson@15077
  1177
paulson@15077
  1178
lemma sin_diff: "sin (x - y) = sin x * cos y - cos x * sin y"
huffman@22969
  1179
by (simp add: diff_minus sin_add)
paulson@15077
  1180
paulson@15077
  1181
lemma sin_diff2: "sin (x - y) = cos y * sin x - sin y * cos x"
paulson@15077
  1182
by (simp add: sin_diff mult_commute)
paulson@15077
  1183
paulson@15077
  1184
lemma cos_diff: "cos (x - y) = cos x * cos y + sin x * sin y"
huffman@22969
  1185
by (simp add: diff_minus cos_add)
paulson@15077
  1186
paulson@15077
  1187
lemma cos_diff2: "cos (x - y) = cos y * cos x + sin y * sin x"
paulson@15077
  1188
by (simp add: cos_diff mult_commute)
paulson@15077
  1189
paulson@15077
  1190
lemma sin_double [simp]: "sin(2 * x) = 2* sin x * cos x"
huffman@29165
  1191
  using sin_add [where x=x and y=x] by simp
paulson@15077
  1192
paulson@15077
  1193
lemma cos_double: "cos(2* x) = ((cos x)\<twosuperior>) - ((sin x)\<twosuperior>)"
huffman@29165
  1194
  using cos_add [where x=x and y=x]
huffman@29165
  1195
  by (simp add: power2_eq_square)
paulson@15077
  1196
paulson@15077
  1197
huffman@29164
  1198
subsection {* The Constant Pi *}
paulson@15077
  1199
huffman@23043
  1200
definition
huffman@23043
  1201
  pi :: "real" where
huffman@23053
  1202
  "pi = 2 * (THE x. 0 \<le> (x::real) & x \<le> 2 & cos x = 0)"
huffman@23043
  1203
paulson@15077
  1204
text{*Show that there's a least positive @{term x} with @{term "cos(x) = 0"}; 
paulson@15077
  1205
   hence define pi.*}
paulson@15077
  1206
paulson@15077
  1207
lemma sin_paired:
huffman@23177
  1208
     "(%n. -1 ^ n /(real (fact (2 * n + 1))) * x ^ (2 * n + 1)) 
paulson@15077
  1209
      sums  sin x"
paulson@15077
  1210
proof -
paulson@15077
  1211
  have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
paulson@15077
  1212
            (if even k then 0
huffman@23177
  1213
             else -1 ^ ((k - Suc 0) div 2) / real (fact k)) *
paulson@15077
  1214
            x ^ k) 
huffman@23176
  1215
	sums sin x"
huffman@23176
  1216
    unfolding sin_def
paulson@15077
  1217
    by (rule sin_converges [THEN sums_summable, THEN sums_group], simp) 
huffman@23176
  1218
  thus ?thesis by (simp add: mult_ac)
paulson@15077
  1219
qed
paulson@15077
  1220
paulson@15077
  1221
lemma sin_gt_zero: "[|0 < x; x < 2 |] ==> 0 < sin x"
paulson@15077
  1222
apply (subgoal_tac 
paulson@15077
  1223
       "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
huffman@23177
  1224
              -1 ^ k / real (fact (2 * k + 1)) * x ^ (2 * k + 1)) 
huffman@23177
  1225
     sums (\<Sum>n. -1 ^ n / real (fact (2 * n + 1)) * x ^ (2 * n + 1))")
paulson@15077
  1226
 prefer 2
paulson@15077
  1227
 apply (rule sin_paired [THEN sums_summable, THEN sums_group], simp) 
paulson@15077
  1228
apply (rotate_tac 2)
paulson@15077
  1229
apply (drule sin_paired [THEN sums_unique, THEN ssubst])
paulson@15077
  1230
apply (auto simp del: fact_Suc realpow_Suc)
paulson@15077
  1231
apply (frule sums_unique)
paulson@15077
  1232
apply (auto simp del: fact_Suc realpow_Suc)
paulson@15077
  1233
apply (rule_tac n1 = 0 in series_pos_less [THEN [2] order_le_less_trans])
paulson@15077
  1234
apply (auto simp del: fact_Suc realpow_Suc)
paulson@15077
  1235
apply (erule sums_summable)
paulson@15077
  1236
apply (case_tac "m=0")
paulson@15077
  1237
apply (simp (no_asm_simp))
paulson@15234
  1238
apply (subgoal_tac "6 * (x * (x * x) / real (Suc (Suc (Suc (Suc (Suc (Suc 0))))))) < 6 * x") 
nipkow@15539
  1239
apply (simp only: mult_less_cancel_left, simp)  
nipkow@15539
  1240
apply (simp (no_asm_simp) add: numeral_2_eq_2 [symmetric] mult_assoc [symmetric])
paulson@15077
  1241
apply (subgoal_tac "x*x < 2*3", simp) 
paulson@15077
  1242
apply (rule mult_strict_mono)
paulson@15085
  1243
apply (auto simp add: real_0_less_add_iff real_of_nat_Suc simp del: fact_Suc)
paulson@15077
  1244
apply (subst fact_Suc)
paulson@15077
  1245
apply (subst fact_Suc)
paulson@15077
  1246
apply (subst fact_Suc)
paulson@15077
  1247
apply (subst fact_Suc)
paulson@15077
  1248
apply (subst real_of_nat_mult)
paulson@15077
  1249
apply (subst real_of_nat_mult)
paulson@15077
  1250
apply (subst real_of_nat_mult)
paulson@15077
  1251
apply (subst real_of_nat_mult)
nipkow@15539
  1252
apply (simp (no_asm) add: divide_inverse del: fact_Suc)
paulson@15077
  1253
apply (auto simp add: mult_assoc [symmetric] simp del: fact_Suc)
paulson@15077
  1254
apply (rule_tac c="real (Suc (Suc (4*m)))" in mult_less_imp_less_right) 
paulson@15077
  1255
apply (auto simp add: mult_assoc simp del: fact_Suc)
paulson@15077
  1256
apply (rule_tac c="real (Suc (Suc (Suc (4*m))))" in mult_less_imp_less_right) 
paulson@15077
  1257
apply (auto simp add: mult_assoc mult_less_cancel_left simp del: fact_Suc)
paulson@15077
  1258
apply (subgoal_tac "x * (x * x ^ (4*m)) = (x ^ (4*m)) * (x * x)") 
paulson@15077
  1259
apply (erule ssubst)+
paulson@15077
  1260
apply (auto simp del: fact_Suc)
paulson@15077
  1261
apply (subgoal_tac "0 < x ^ (4 * m) ")
paulson@15077
  1262
 prefer 2 apply (simp only: zero_less_power) 
paulson@15077
  1263
apply (simp (no_asm_simp) add: mult_less_cancel_left)
paulson@15077
  1264
apply (rule mult_strict_mono)
paulson@15077
  1265
apply (simp_all (no_asm_simp))
paulson@15077
  1266
done
paulson@15077
  1267
paulson@15077
  1268
lemma sin_gt_zero1: "[|0 < x; x < 2 |] ==> 0 < sin x"
paulson@15077
  1269
by (auto intro: sin_gt_zero)
paulson@15077
  1270
paulson@15077
  1271
lemma cos_double_less_one: "[| 0 < x; x < 2 |] ==> cos (2 * x) < 1"
paulson@15077
  1272
apply (cut_tac x = x in sin_gt_zero1)
paulson@15077
  1273
apply (auto simp add: cos_squared_eq cos_double)
paulson@15077
  1274
done
paulson@15077
  1275
paulson@15077
  1276
lemma cos_paired:
huffman@23177
  1277
     "(%n. -1 ^ n /(real (fact (2 * n))) * x ^ (2 * n)) sums cos x"
paulson@15077
  1278
proof -
paulson@15077
  1279
  have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
huffman@23177
  1280
            (if even k then -1 ^ (k div 2) / real (fact k) else 0) *
paulson@15077
  1281
            x ^ k) 
huffman@23176
  1282
        sums cos x"
huffman@23176
  1283
    unfolding cos_def
paulson@15077
  1284
    by (rule cos_converges [THEN sums_summable, THEN sums_group], simp) 
huffman@23176
  1285
  thus ?thesis by (simp add: mult_ac)
paulson@15077
  1286
qed
paulson@15077
  1287
paulson@15077
  1288
lemma fact_lemma: "real (n::nat) * 4 = real (4 * n)"
paulson@15077
  1289
by simp
paulson@15077
  1290
huffman@23053
  1291
lemma cos_two_less_zero [simp]: "cos (2) < 0"
paulson@15077
  1292
apply (cut_tac x = 2 in cos_paired)
paulson@15077
  1293
apply (drule sums_minus)
paulson@15077
  1294
apply (rule neg_less_iff_less [THEN iffD1]) 
nipkow@15539
  1295
apply (frule sums_unique, auto)
nipkow@15539
  1296
apply (rule_tac y =
huffman@23177
  1297
 "\<Sum>n=0..< Suc(Suc(Suc 0)). - (-1 ^ n / (real(fact (2*n))) * 2 ^ (2*n))"
paulson@15481
  1298
       in order_less_trans)
paulson@15077
  1299
apply (simp (no_asm) add: fact_num_eq_if realpow_num_eq_if del: fact_Suc realpow_Suc)
nipkow@15561
  1300
apply (simp (no_asm) add: mult_assoc del: setsum_op_ivl_Suc)
paulson@15077
  1301
apply (rule sumr_pos_lt_pair)
paulson@15077
  1302
apply (erule sums_summable, safe)
paulson@15085
  1303
apply (simp (no_asm) add: divide_inverse real_0_less_add_iff mult_assoc [symmetric] 
paulson@15085
  1304
            del: fact_Suc)
paulson@15077
  1305
apply (rule real_mult_inverse_cancel2)
paulson@15077
  1306
apply (rule real_of_nat_fact_gt_zero)+
paulson@15077
  1307
apply (simp (no_asm) add: mult_assoc [symmetric] del: fact_Suc)
paulson@15077
  1308
apply (subst fact_lemma) 
paulson@15481
  1309
apply (subst fact_Suc [of "Suc (Suc (Suc (Suc (Suc (Suc (Suc (4 * d)))))))"])
paulson@15481
  1310
apply (simp only: real_of_nat_mult)
huffman@23007
  1311
apply (rule mult_strict_mono, force)
huffman@27483
  1312
  apply (rule_tac [3] real_of_nat_ge_zero)
paulson@15481
  1313
 prefer 2 apply force
paulson@15077
  1314
apply (rule real_of_nat_less_iff [THEN iffD2])
paulson@15077
  1315
apply (rule fact_less_mono, auto)
paulson@15077
  1316
done
huffman@23053
  1317
huffman@23053
  1318
lemmas cos_two_neq_zero [simp] = cos_two_less_zero [THEN less_imp_neq]
huffman@23053
  1319
lemmas cos_two_le_zero [simp] = cos_two_less_zero [THEN order_less_imp_le]
paulson@15077
  1320
paulson@15077
  1321
lemma cos_is_zero: "EX! x. 0 \<le> x & x \<le> 2 & cos x = 0"
paulson@15077
  1322
apply (subgoal_tac "\<exists>x. 0 \<le> x & x \<le> 2 & cos x = 0")
paulson@15077
  1323
apply (rule_tac [2] IVT2)
paulson@15077
  1324
apply (auto intro: DERIV_isCont DERIV_cos)
paulson@15077
  1325
apply (cut_tac x = xa and y = y in linorder_less_linear)
paulson@15077
  1326
apply (rule ccontr)
paulson@15077
  1327
apply (subgoal_tac " (\<forall>x. cos differentiable x) & (\<forall>x. isCont cos x) ")
paulson@15077
  1328
apply (auto intro: DERIV_cos DERIV_isCont simp add: differentiable_def)
paulson@15077
  1329
apply (drule_tac f = cos in Rolle)
paulson@15077
  1330
apply (drule_tac [5] f = cos in Rolle)
paulson@15077
  1331
apply (auto dest!: DERIV_cos [THEN DERIV_unique] simp add: differentiable_def)
paulson@15077
  1332
apply (drule_tac y1 = xa in order_le_less_trans [THEN sin_gt_zero])
paulson@15077
  1333
apply (assumption, rule_tac y=y in order_less_le_trans, simp_all) 
paulson@15077
  1334
apply (drule_tac y1 = y in order_le_less_trans [THEN sin_gt_zero], assumption, simp_all) 
paulson@15077
  1335
done
paulson@15077
  1336
    
huffman@23053
  1337
lemma pi_half: "pi/2 = (THE x. 0 \<le> x & x \<le> 2 & cos x = 0)"
paulson@15077
  1338
by (simp add: pi_def)
paulson@15077
  1339
paulson@15077
  1340
lemma cos_pi_half [simp]: "cos (pi / 2) = 0"
huffman@23053
  1341
by (simp add: pi_half cos_is_zero [THEN theI'])
huffman@23053
  1342
huffman@23053
  1343
lemma pi_half_gt_zero [simp]: "0 < pi / 2"
huffman@23053
  1344
apply (rule order_le_neq_trans)
huffman@23053
  1345
apply (simp add: pi_half cos_is_zero [THEN theI'])
huffman@23053
  1346
apply (rule notI, drule arg_cong [where f=cos], simp)
paulson@15077
  1347
done
paulson@15077
  1348
huffman@23053
  1349
lemmas pi_half_neq_zero [simp] = pi_half_gt_zero [THEN less_imp_neq, symmetric]
huffman@23053
  1350
lemmas pi_half_ge_zero [simp] = pi_half_gt_zero [THEN order_less_imp_le]
paulson@15077
  1351
huffman@23053
  1352
lemma pi_half_less_two [simp]: "pi / 2 < 2"
huffman@23053
  1353
apply (rule order_le_neq_trans)
huffman@23053
  1354
apply (simp add: pi_half cos_is_zero [THEN theI'])
huffman@23053
  1355
apply (rule notI, drule arg_cong [where f=cos], simp)
paulson@15077
  1356
done
huffman@23053
  1357
huffman@23053
  1358
lemmas pi_half_neq_two [simp] = pi_half_less_two [THEN less_imp_neq]
huffman@23053
  1359
lemmas pi_half_le_two [simp] =  pi_half_less_two [THEN order_less_imp_le]
paulson@15077
  1360
paulson@15077
  1361
lemma pi_gt_zero [simp]: "0 < pi"
huffman@23053
  1362
by (insert pi_half_gt_zero, simp)
huffman@23053
  1363
huffman@23053
  1364
lemma pi_ge_zero [simp]: "0 \<le> pi"
huffman@23053
  1365
by (rule pi_gt_zero [THEN order_less_imp_le])
paulson@15077
  1366
paulson@15077
  1367
lemma pi_neq_zero [simp]: "pi \<noteq> 0"
huffman@22998
  1368
by (rule pi_gt_zero [THEN less_imp_neq, THEN not_sym])
paulson@15077
  1369
huffman@23053
  1370
lemma pi_not_less_zero [simp]: "\<not> pi < 0"
huffman@23053
  1371
by (simp add: linorder_not_less)
paulson@15077
  1372
huffman@29165
  1373
lemma minus_pi_half_less_zero: "-(pi/2) < 0"
huffman@29165
  1374
by simp
paulson@15077
  1375
paulson@15077
  1376
lemma sin_pi_half [simp]: "sin(pi/2) = 1"
paulson@15077
  1377
apply (cut_tac x = "pi/2" in sin_cos_squared_add2)
paulson@15077
  1378
apply (cut_tac sin_gt_zero [OF pi_half_gt_zero pi_half_less_two])
huffman@23053
  1379
apply (simp add: power2_eq_square)
paulson@15077
  1380
done
paulson@15077
  1381
paulson@15077
  1382
lemma cos_pi [simp]: "cos pi = -1"
nipkow@15539
  1383
by (cut_tac x = "pi/2" and y = "pi/2" in cos_add, simp)
paulson@15077
  1384
paulson@15077
  1385
lemma sin_pi [simp]: "sin pi = 0"
nipkow@15539
  1386
by (cut_tac x = "pi/2" and y = "pi/2" in sin_add, simp)
paulson@15077
  1387
paulson@15077
  1388
lemma sin_cos_eq: "sin x = cos (pi/2 - x)"
paulson@15229
  1389
by (simp add: diff_minus cos_add)
huffman@23053
  1390
declare sin_cos_eq [symmetric, simp]
paulson@15077
  1391
paulson@15077
  1392
lemma minus_sin_cos_eq: "-sin x = cos (x + pi/2)"
paulson@15229
  1393
by (simp add: cos_add)
paulson@15077
  1394
declare minus_sin_cos_eq [symmetric, simp]
paulson@15077
  1395
paulson@15077
  1396
lemma cos_sin_eq: "cos x = sin (pi/2 - x)"
paulson@15229
  1397
by (simp add: diff_minus sin_add)
huffman@23053
  1398
declare cos_sin_eq [symmetric, simp]
paulson@15077
  1399
paulson@15077
  1400
lemma sin_periodic_pi [simp]: "sin (x + pi) = - sin x"
paulson@15229
  1401
by (simp add: sin_add)
paulson@15077
  1402
paulson@15077
  1403
lemma sin_periodic_pi2 [simp]: "sin (pi + x) = - sin x"
paulson@15229
  1404
by (simp add: sin_add)
paulson@15077
  1405
paulson@15077
  1406
lemma cos_periodic_pi [simp]: "cos (x + pi) = - cos x"
paulson@15229
  1407
by (simp add: cos_add)
paulson@15077
  1408
paulson@15077
  1409
lemma sin_periodic [simp]: "sin (x + 2*pi) = sin x"
paulson@15077
  1410
by (simp add: sin_add cos_double)
paulson@15077
  1411
paulson@15077
  1412
lemma cos_periodic [simp]: "cos (x + 2*pi) = cos x"
paulson@15077
  1413
by (simp add: cos_add cos_double)
paulson@15077
  1414
paulson@15077
  1415
lemma cos_npi [simp]: "cos (real n * pi) = -1 ^ n"
paulson@15251
  1416
apply (induct "n")
paulson@15077
  1417
apply (auto simp add: real_of_nat_Suc left_distrib)
paulson@15077
  1418
done
paulson@15077
  1419
paulson@15383
  1420
lemma cos_npi2 [simp]: "cos (pi * real n) = -1 ^ n"
paulson@15383
  1421
proof -
paulson@15383
  1422
  have "cos (pi * real n) = cos (real n * pi)" by (simp only: mult_commute)
paulson@15383
  1423
  also have "... = -1 ^ n" by (rule cos_npi) 
paulson@15383
  1424
  finally show ?thesis .
paulson@15383
  1425
qed
paulson@15383
  1426
paulson@15077
  1427
lemma sin_npi [simp]: "sin (real (n::nat) * pi) = 0"
paulson@15251
  1428
apply (induct "n")
paulson@15077
  1429
apply (auto simp add: real_of_nat_Suc left_distrib)
paulson@15077
  1430
done
paulson@15077
  1431
paulson@15077
  1432
lemma sin_npi2 [simp]: "sin (pi * real (n::nat)) = 0"
paulson@15383
  1433
by (simp add: mult_commute [of pi]) 
paulson@15077
  1434
paulson@15077
  1435
lemma cos_two_pi [simp]: "cos (2 * pi) = 1"
paulson@15077
  1436
by (simp add: cos_double)
paulson@15077
  1437
paulson@15077
  1438
lemma sin_two_pi [simp]: "sin (2 * pi) = 0"
paulson@15229
  1439
by simp
paulson@15077
  1440
paulson@15077
  1441
lemma sin_gt_zero2: "[| 0 < x; x < pi/2 |] ==> 0 < sin x"
paulson@15077
  1442
apply (rule sin_gt_zero, assumption)
paulson@15077
  1443
apply (rule order_less_trans, assumption)
paulson@15077
  1444
apply (rule pi_half_less_two)
paulson@15077
  1445
done
paulson@15077
  1446
paulson@15077
  1447
lemma sin_less_zero: 
paulson@15077
  1448
  assumes lb: "- pi/2 < x" and "x < 0" shows "sin x < 0"
paulson@15077
  1449
proof -
paulson@15077
  1450
  have "0 < sin (- x)" using prems by (simp only: sin_gt_zero2) 
paulson@15077
  1451
  thus ?thesis by simp
paulson@15077
  1452
qed
paulson@15077
  1453
paulson@15077
  1454
lemma pi_less_4: "pi < 4"
paulson@15077
  1455
by (cut_tac pi_half_less_two, auto)
paulson@15077
  1456
paulson@15077
  1457
lemma cos_gt_zero: "[| 0 < x; x < pi/2 |] ==> 0 < cos x"
paulson@15077
  1458
apply (cut_tac pi_less_4)
paulson@15077
  1459
apply (cut_tac f = cos and a = 0 and b = x and y = 0 in IVT2_objl, safe, simp_all)
paulson@15077
  1460
apply (cut_tac cos_is_zero, safe)
paulson@15077
  1461
apply (rename_tac y z)
paulson@15077
  1462
apply (drule_tac x = y in spec)
paulson@15077
  1463
apply (drule_tac x = "pi/2" in spec, simp) 
paulson@15077
  1464
done
paulson@15077
  1465
paulson@15077
  1466
lemma cos_gt_zero_pi: "[| -(pi/2) < x; x < pi/2 |] ==> 0 < cos x"
paulson@15077
  1467
apply (rule_tac x = x and y = 0 in linorder_cases)
paulson@15077
  1468
apply (rule cos_minus [THEN subst])
paulson@15077
  1469
apply (rule cos_gt_zero)
paulson@15077
  1470
apply (auto intro: cos_gt_zero)
paulson@15077
  1471
done
paulson@15077
  1472
 
paulson@15077
  1473
lemma cos_ge_zero: "[| -(pi/2) \<le> x; x \<le> pi/2 |] ==> 0 \<le> cos x"
paulson@15077
  1474
apply (auto simp add: order_le_less cos_gt_zero_pi)
paulson@15077
  1475
apply (subgoal_tac "x = pi/2", auto) 
paulson@15077
  1476
done
paulson@15077
  1477
paulson@15077
  1478
lemma sin_gt_zero_pi: "[| 0 < x; x < pi  |] ==> 0 < sin x"
paulson@15077
  1479
apply (subst sin_cos_eq)
paulson@15077
  1480
apply (rotate_tac 1)
paulson@15077
  1481
apply (drule real_sum_of_halves [THEN ssubst])
paulson@15077
  1482
apply (auto intro!: cos_gt_zero_pi simp del: sin_cos_eq [symmetric])
paulson@15077
  1483
done
paulson@15077
  1484
paulson@15077
  1485
lemma sin_ge_zero: "[| 0 \<le> x; x \<le> pi |] ==> 0 \<le> sin x"
paulson@15077
  1486
by (auto simp add: order_le_less sin_gt_zero_pi)
paulson@15077
  1487
paulson@15077
  1488
lemma cos_total: "[| -1 \<le> y; y \<le> 1 |] ==> EX! x. 0 \<le> x & x \<le> pi & (cos x = y)"
paulson@15077
  1489
apply (subgoal_tac "\<exists>x. 0 \<le> x & x \<le> pi & cos x = y")
paulson@15077
  1490
apply (rule_tac [2] IVT2)
paulson@15077
  1491
apply (auto intro: order_less_imp_le DERIV_isCont DERIV_cos)
paulson@15077
  1492
apply (cut_tac x = xa and y = y in linorder_less_linear)
paulson@15077
  1493
apply (rule ccontr, auto)
paulson@15077
  1494
apply (drule_tac f = cos in Rolle)
paulson@15077
  1495
apply (drule_tac [5] f = cos in Rolle)
paulson@15077
  1496
apply (auto intro: order_less_imp_le DERIV_isCont DERIV_cos
paulson@15077
  1497
            dest!: DERIV_cos [THEN DERIV_unique] 
paulson@15077
  1498
            simp add: differentiable_def)
paulson@15077
  1499
apply (auto dest: sin_gt_zero_pi [OF order_le_less_trans order_less_le_trans])
paulson@15077
  1500
done
paulson@15077
  1501
paulson@15077
  1502
lemma sin_total:
paulson@15077
  1503
     "[| -1 \<le> y; y \<le> 1 |] ==> EX! x. -(pi/2) \<le> x & x \<le> pi/2 & (sin x = y)"
paulson@15077
  1504
apply (rule ccontr)
paulson@15077
  1505
apply (subgoal_tac "\<forall>x. (- (pi/2) \<le> x & x \<le> pi/2 & (sin x = y)) = (0 \<le> (x + pi/2) & (x + pi/2) \<le> pi & (cos (x + pi/2) = -y))")
wenzelm@18585
  1506
apply (erule contrapos_np)
paulson@15077
  1507
apply (simp del: minus_sin_cos_eq [symmetric])
paulson@15077
  1508
apply (cut_tac y="-y" in cos_total, simp) apply simp 
paulson@15077
  1509
apply (erule ex1E)
paulson@15229
  1510
apply (rule_tac a = "x - (pi/2)" in ex1I)
huffman@23286
  1511
apply (simp (no_asm) add: add_assoc)
paulson@15077
  1512
apply (rotate_tac 3)
paulson@15077
  1513
apply (drule_tac x = "xa + pi/2" in spec, safe, simp_all) 
paulson@15077
  1514
done
paulson@15077
  1515
paulson@15077
  1516
lemma reals_Archimedean4:
paulson@15077
  1517
     "[| 0 < y; 0 \<le> x |] ==> \<exists>n. real n * y \<le> x & x < real (Suc n) * y"
paulson@15077
  1518
apply (auto dest!: reals_Archimedean3)
paulson@15077
  1519
apply (drule_tac x = x in spec, clarify) 
paulson@15077
  1520
apply (subgoal_tac "x < real(LEAST m::nat. x < real m * y) * y")
paulson@15077
  1521
 prefer 2 apply (erule LeastI) 
paulson@15077
  1522
apply (case_tac "LEAST m::nat. x < real m * y", simp) 
paulson@15077
  1523
apply (subgoal_tac "~ x < real nat * y")
paulson@15077
  1524
 prefer 2 apply (rule not_less_Least, simp, force)  
paulson@15077
  1525
done
paulson@15077
  1526
paulson@15077
  1527
(* Pre Isabelle99-2 proof was simpler- numerals arithmetic 
paulson@15077
  1528
   now causes some unwanted re-arrangements of literals!   *)
paulson@15229
  1529
lemma cos_zero_lemma:
paulson@15229
  1530
     "[| 0 \<le> x; cos x = 0 |] ==>  
paulson@15077
  1531
      \<exists>n::nat. ~even n & x = real n * (pi/2)"
paulson@15077
  1532
apply (drule pi_gt_zero [THEN reals_Archimedean4], safe)
paulson@15086
  1533
apply (subgoal_tac "0 \<le> x - real n * pi & 
paulson@15086
  1534
                    (x - real n * pi) \<le> pi & (cos (x - real n * pi) = 0) ")
paulson@15086
  1535
apply (auto simp add: compare_rls) 
paulson@15077
  1536
  prefer 3 apply (simp add: cos_diff) 
paulson@15077
  1537
 prefer 2 apply (simp add: real_of_nat_Suc left_distrib) 
paulson@15077
  1538
apply (simp add: cos_diff)
paulson@15077
  1539
apply (subgoal_tac "EX! x. 0 \<le> x & x \<le> pi & cos x = 0")
paulson@15077
  1540
apply (rule_tac [2] cos_total, safe)
paulson@15077
  1541
apply (drule_tac x = "x - real n * pi" in spec)
paulson@15077
  1542
apply (drule_tac x = "pi/2" in spec)
paulson@15077
  1543
apply (simp add: cos_diff)
paulson@15229
  1544
apply (rule_tac x = "Suc (2 * n)" in exI)
paulson@15077
  1545
apply (simp add: real_of_nat_Suc left_distrib, auto)
paulson@15077
  1546
done
paulson@15077
  1547
paulson@15229
  1548
lemma sin_zero_lemma:
paulson@15229
  1549
     "[| 0 \<le> x; sin x = 0 |] ==>  
paulson@15077
  1550
      \<exists>n::nat. even n & x = real n * (pi/2)"
paulson@15077
  1551
apply (subgoal_tac "\<exists>n::nat. ~ even n & x + pi/2 = real n * (pi/2) ")
paulson@15077
  1552
 apply (clarify, rule_tac x = "n - 1" in exI)
paulson@15077
  1553
 apply (force simp add: odd_Suc_mult_two_ex real_of_nat_Suc left_distrib)
paulson@15085
  1554
apply (rule cos_zero_lemma)
paulson@15085
  1555
apply (simp_all add: add_increasing)  
paulson@15077
  1556
done
paulson@15077
  1557
paulson@15077
  1558
paulson@15229
  1559
lemma cos_zero_iff:
paulson@15229
  1560
     "(cos x = 0) =  
paulson@15077
  1561
      ((\<exists>n::nat. ~even n & (x = real n * (pi/2))) |    
paulson@15077
  1562
       (\<exists>n::nat. ~even n & (x = -(real n * (pi/2)))))"
paulson@15077
  1563
apply (rule iffI)
paulson@15077
  1564
apply (cut_tac linorder_linear [of 0 x], safe)
paulson@15077
  1565
apply (drule cos_zero_lemma, assumption+)
paulson@15077
  1566
apply (cut_tac x="-x" in cos_zero_lemma, simp, simp) 
paulson@15077
  1567
apply (force simp add: minus_equation_iff [of x]) 
paulson@15077
  1568
apply (auto simp only: odd_Suc_mult_two_ex real_of_nat_Suc left_distrib) 
nipkow@15539
  1569
apply (auto simp add: cos_add)
paulson@15077
  1570
done
paulson@15077
  1571
paulson@15077
  1572
(* ditto: but to a lesser extent *)
paulson@15229
  1573
lemma sin_zero_iff:
paulson@15229
  1574
     "(sin x = 0) =  
paulson@15077
  1575
      ((\<exists>n::nat. even n & (x = real n * (pi/2))) |    
paulson@15077
  1576
       (\<exists>n::nat. even n & (x = -(real n * (pi/2)))))"
paulson@15077
  1577
apply (rule iffI)
paulson@15077
  1578
apply (cut_tac linorder_linear [of 0 x], safe)
paulson@15077
  1579
apply (drule sin_zero_lemma, assumption+)
paulson@15077
  1580
apply (cut_tac x="-x" in sin_zero_lemma, simp, simp, safe)
paulson@15077
  1581
apply (force simp add: minus_equation_iff [of x]) 
nipkow@15539
  1582
apply (auto simp add: even_mult_two_ex)
paulson@15077
  1583
done
paulson@15077
  1584
paulson@15077
  1585
huffman@29164
  1586
subsection {* Tangent *}
paulson@15077
  1587
huffman@23043
  1588
definition
huffman@23043
  1589
  tan :: "real => real" where
huffman@23043
  1590
  "tan x = (sin x)/(cos x)"
huffman@23043
  1591
paulson@15077
  1592
lemma tan_zero [simp]: "tan 0 = 0"
paulson@15077
  1593
by (simp add: tan_def)
paulson@15077
  1594
paulson@15077
  1595
lemma tan_pi [simp]: "tan pi = 0"
paulson@15077
  1596
by (simp add: tan_def)
paulson@15077
  1597
paulson@15077
  1598
lemma tan_npi [simp]: "tan (real (n::nat) * pi) = 0"
paulson@15077
  1599
by (simp add: tan_def)
paulson@15077
  1600
paulson@15077
  1601
lemma tan_minus [simp]: "tan (-x) = - tan x"
paulson@15077
  1602
by (simp add: tan_def minus_mult_left)
paulson@15077
  1603
paulson@15077
  1604
lemma tan_periodic [simp]: "tan (x + 2*pi) = tan x"
paulson@15077
  1605
by (simp add: tan_def)
paulson@15077
  1606
paulson@15077
  1607
lemma lemma_tan_add1: 
paulson@15077
  1608
      "[| cos x \<noteq> 0; cos y \<noteq> 0 |]  
paulson@15077
  1609
        ==> 1 - tan(x)*tan(y) = cos (x + y)/(cos x * cos y)"
paulson@15229
  1610
apply (simp add: tan_def divide_inverse)
paulson@15229
  1611
apply (auto simp del: inverse_mult_distrib 
paulson@15229
  1612
            simp add: inverse_mult_distrib [symmetric] mult_ac)
paulson@15077
  1613
apply (rule_tac c1 = "cos x * cos y" in real_mult_right_cancel [THEN subst])
paulson@15229
  1614
apply (auto simp del: inverse_mult_distrib 
paulson@15229
  1615
            simp add: mult_assoc left_diff_distrib cos_add)
paulson@15234
  1616
done  
paulson@15077
  1617
paulson@15077
  1618
lemma add_tan_eq: 
paulson@15077
  1619
      "[| cos x \<noteq> 0; cos y \<noteq> 0 |]  
paulson@15077
  1620
       ==> tan x + tan y = sin(x + y)/(cos x * cos y)"
paulson@15229
  1621
apply (simp add: tan_def)
paulson@15077
  1622
apply (rule_tac c1 = "cos x * cos y" in real_mult_right_cancel [THEN subst])
paulson@15077
  1623
apply (auto simp add: mult_assoc left_distrib)
nipkow@15539
  1624
apply (simp add: sin_add)
paulson@15077
  1625
done
paulson@15077
  1626
paulson@15229
  1627
lemma tan_add:
paulson@15229
  1628
     "[| cos x \<noteq> 0; cos y \<noteq> 0; cos (x + y) \<noteq> 0 |]  
paulson@15077
  1629
      ==> tan(x + y) = (tan(x) + tan(y))/(1 - tan(x) * tan(y))"
paulson@15077
  1630
apply (simp (no_asm_simp) add: add_tan_eq lemma_tan_add1)
paulson@15077
  1631
apply (simp add: tan_def)
paulson@15077
  1632
done
paulson@15077
  1633
paulson@15229
  1634
lemma tan_double:
paulson@15229
  1635
     "[| cos x \<noteq> 0; cos (2 * x) \<noteq> 0 |]  
paulson@15077
  1636
      ==> tan (2 * x) = (2 * tan x)/(1 - (tan(x) ^ 2))"
paulson@15077
  1637
apply (insert tan_add [of x x]) 
paulson@15077
  1638
apply (simp add: mult_2 [symmetric])  
paulson@15077
  1639
apply (auto simp add: numeral_2_eq_2)
paulson@15077
  1640
done
paulson@15077
  1641
paulson@15077
  1642
lemma tan_gt_zero: "[| 0 < x; x < pi/2 |] ==> 0 < tan x"
paulson@15229
  1643
by (simp add: tan_def zero_less_divide_iff sin_gt_zero2 cos_gt_zero_pi) 
paulson@15077
  1644
paulson@15077
  1645
lemma tan_less_zero: 
paulson@15077
  1646
  assumes lb: "- pi/2 < x" and "x < 0" shows "tan x < 0"
paulson@15077
  1647
proof -
paulson@15077
  1648
  have "0 < tan (- x)" using prems by (simp only: tan_gt_zero) 
paulson@15077
  1649
  thus ?thesis by simp
paulson@15077
  1650
qed
paulson@15077
  1651
paulson@15077
  1652
lemma lemma_DERIV_tan:
paulson@15077
  1653
     "cos x \<noteq> 0 ==> DERIV (%x. sin(x)/cos(x)) x :> inverse((cos x)\<twosuperior>)"
paulson@15077
  1654
apply (rule lemma_DERIV_subst)
paulson@15077
  1655
apply (best intro!: DERIV_intros intro: DERIV_chain2) 
paulson@15079
  1656
apply (auto simp add: divide_inverse numeral_2_eq_2)
paulson@15077
  1657
done
paulson@15077
  1658
paulson@15077
  1659
lemma DERIV_tan [simp]: "cos x \<noteq> 0 ==> DERIV tan x :> inverse((cos x)\<twosuperior>)"
paulson@15077
  1660
by (auto dest: lemma_DERIV_tan simp add: tan_def [symmetric])
paulson@15077
  1661
huffman@23045
  1662
lemma isCont_tan [simp]: "cos x \<noteq> 0 ==> isCont tan x"
huffman@23045
  1663
by (rule DERIV_tan [THEN DERIV_isCont])
huffman@23045
  1664
paulson@15077
  1665
lemma LIM_cos_div_sin [simp]: "(%x. cos(x)/sin(x)) -- pi/2 --> 0"
paulson@15077
  1666
apply (subgoal_tac "(\<lambda>x. cos x * inverse (sin x)) -- pi * inverse 2 --> 0*1")
paulson@15229
  1667
apply (simp add: divide_inverse [symmetric])
huffman@22613
  1668
apply (rule LIM_mult)
paulson@15077
  1669
apply (rule_tac [2] inverse_1 [THEN subst])
paulson@15077
  1670
apply (rule_tac [2] LIM_inverse)
paulson@15077
  1671
apply (simp_all add: divide_inverse [symmetric]) 
paulson@15077
  1672
apply (simp_all only: isCont_def [symmetric] cos_pi_half [symmetric] sin_pi_half [symmetric]) 
paulson@15077
  1673
apply (blast intro!: DERIV_isCont DERIV_sin DERIV_cos)+
paulson@15077
  1674
done
paulson@15077
  1675
paulson@15077
  1676
lemma lemma_tan_total: "0 < y ==> \<exists>x. 0 < x & x < pi/2 & y < tan x"
paulson@15077
  1677
apply (cut_tac LIM_cos_div_sin)
paulson@15077
  1678
apply (simp only: LIM_def)
paulson@15077
  1679
apply (drule_tac x = "inverse y" in spec, safe, force)
paulson@15077
  1680
apply (drule_tac ?d1.0 = s in pi_half_gt_zero [THEN [2] real_lbound_gt_zero], safe)
paulson@15229
  1681
apply (rule_tac x = "(pi/2) - e" in exI)
paulson@15077
  1682
apply (simp (no_asm_simp))
paulson@15229
  1683
apply (drule_tac x = "(pi/2) - e" in spec)
paulson@15229
  1684
apply (auto simp add: tan_def)
paulson@15077
  1685
apply (rule inverse_less_iff_less [THEN iffD1])
paulson@15079
  1686
apply (auto simp add: divide_inverse)
paulson@15229
  1687
apply (rule real_mult_order) 
paulson@15229
  1688
apply (subgoal_tac [3] "0 < sin e & 0 < cos e")
paulson@15229
  1689
apply (auto intro: cos_gt_zero sin_gt_zero2 simp add: mult_commute) 
paulson@15077
  1690
done
paulson@15077
  1691
paulson@15077
  1692
lemma tan_total_pos: "0 \<le> y ==> \<exists>x. 0 \<le> x & x < pi/2 & tan x = y"
huffman@22998
  1693
apply (frule order_le_imp_less_or_eq, safe)
paulson@15077
  1694
 prefer 2 apply force
paulson@15077
  1695
apply (drule lemma_tan_total, safe)
paulson@15077
  1696
apply (cut_tac f = tan and a = 0 and b = x and y = y in IVT_objl)
paulson@15077
  1697
apply (auto intro!: DERIV_tan [THEN DERIV_isCont])
paulson@15077
  1698
apply (drule_tac y = xa in order_le_imp_less_or_eq)
paulson@15077
  1699
apply (auto dest: cos_gt_zero)
paulson@15077
  1700
done
paulson@15077
  1701
paulson@15077
  1702
lemma lemma_tan_total1: "\<exists>x. -(pi/2) < x & x < (pi/2) & tan x = y"
paulson@15077
  1703
apply (cut_tac linorder_linear [of 0 y], safe)
paulson@15077
  1704
apply (drule tan_total_pos)
paulson@15077
  1705
apply (cut_tac [2] y="-y" in tan_total_pos, safe)
paulson@15077
  1706
apply (rule_tac [3] x = "-x" in exI)
paulson@15077
  1707
apply (auto intro!: exI)
paulson@15077
  1708
done
paulson@15077
  1709
paulson@15077
  1710
lemma tan_total: "EX! x. -(pi/2) < x & x < (pi/2) & tan x = y"
paulson@15077
  1711
apply (cut_tac y = y in lemma_tan_total1, auto)
paulson@15077
  1712
apply (cut_tac x = xa and y = y in linorder_less_linear, auto)
paulson@15077
  1713
apply (subgoal_tac [2] "\<exists>z. y < z & z < xa & DERIV tan z :> 0")
paulson@15077
  1714
apply (subgoal_tac "\<exists>z. xa < z & z < y & DERIV tan z :> 0")
paulson@15077
  1715
apply (rule_tac [4] Rolle)
paulson@15077
  1716
apply (rule_tac [2] Rolle)
paulson@15077
  1717
apply (auto intro!: DERIV_tan DERIV_isCont exI 
paulson@15077
  1718
            simp add: differentiable_def)
paulson@15077
  1719
txt{*Now, simulate TRYALL*}
paulson@15077
  1720
apply (rule_tac [!] DERIV_tan asm_rl)
paulson@15077
  1721
apply (auto dest!: DERIV_unique [OF _ DERIV_tan]
huffman@22998
  1722
	    simp add: cos_gt_zero_pi [THEN less_imp_neq, THEN not_sym]) 
paulson@15077
  1723
done
paulson@15077
  1724
huffman@23043
  1725
huffman@23043
  1726
subsection {* Inverse Trigonometric Functions *}
huffman@23043
  1727
huffman@23043
  1728
definition
huffman@23043
  1729
  arcsin :: "real => real" where
huffman@23043
  1730
  "arcsin y = (THE x. -(pi/2) \<le> x & x \<le> pi/2 & sin x = y)"
huffman@23043
  1731
huffman@23043
  1732
definition
huffman@23043
  1733
  arccos :: "real => real" where
huffman@23043
  1734
  "arccos y = (THE x. 0 \<le> x & x \<le> pi & cos x = y)"
huffman@23043
  1735
huffman@23043
  1736
definition     
huffman@23043
  1737
  arctan :: "real => real" where
huffman@23043
  1738
  "arctan y = (THE x. -(pi/2) < x & x < pi/2 & tan x = y)"
huffman@23043
  1739
paulson@15229
  1740
lemma arcsin:
paulson@15229
  1741
     "[| -1 \<le> y; y \<le> 1 |]  
paulson@15077
  1742
      ==> -(pi/2) \<le> arcsin y &  
paulson@15077
  1743
           arcsin y \<le> pi/2 & sin(arcsin y) = y"
huffman@23011
  1744
unfolding arcsin_def by (rule theI' [OF sin_total])
huffman@23011
  1745
huffman@23011
  1746
lemma arcsin_pi:
huffman@23011
  1747
     "[| -1 \<le> y; y \<le> 1 |]  
huffman@23011
  1748
      ==> -(pi/2) \<le> arcsin y & arcsin y \<le> pi & sin(arcsin y) = y"
huffman@23011
  1749
apply (drule (1) arcsin)
huffman@23011
  1750
apply (force intro: order_trans)
paulson@15077
  1751
done
paulson@15077
  1752
paulson@15077
  1753
lemma sin_arcsin [simp]: "[| -1 \<le> y; y \<le> 1 |] ==> sin(arcsin y) = y"
paulson@15077
  1754
by (blast dest: arcsin)
paulson@15077
  1755
      
paulson@15077
  1756
lemma arcsin_bounded:
paulson@15077
  1757
     "[| -1 \<le> y; y \<le> 1 |] ==> -(pi/2) \<le> arcsin y & arcsin y \<le> pi/2"
paulson@15077
  1758
by (blast dest: arcsin)
paulson@15077
  1759
paulson@15077
  1760
lemma arcsin_lbound: "[| -1 \<le> y; y \<le> 1 |] ==> -(pi/2) \<le> arcsin y"
paulson@15077
  1761
by (blast dest: arcsin)
paulson@15077
  1762
paulson@15077
  1763
lemma arcsin_ubound: "[| -1 \<le> y; y \<le> 1 |] ==> arcsin y \<le> pi/2"
paulson@15077
  1764
by (blast dest: arcsin)
paulson@15077
  1765
paulson@15077
  1766
lemma arcsin_lt_bounded:
paulson@15077
  1767
     "[| -1 < y; y < 1 |] ==> -(pi/2) < arcsin y & arcsin y < pi/2"
paulson@15077
  1768
apply (frule order_less_imp_le)
paulson@15077
  1769
apply (frule_tac y = y in order_less_imp_le)
paulson@15077
  1770
apply (frule arcsin_bounded)
paulson@15077
  1771
apply (safe, simp)
paulson@15077
  1772
apply (drule_tac y = "arcsin y" in order_le_imp_less_or_eq)
paulson@15077
  1773
apply (drule_tac [2] y = "pi/2" in order_le_imp_less_or_eq, safe)
paulson@15077
  1774
apply (drule_tac [!] f = sin in arg_cong, auto)
paulson@15077
  1775
done
paulson@15077
  1776
paulson@15077
  1777
lemma arcsin_sin: "[|-(pi/2) \<le> x; x \<le> pi/2 |] ==> arcsin(sin x) = x"
paulson@15077
  1778
apply (unfold arcsin_def)
huffman@23011
  1779
apply (rule the1_equality)
paulson@15077
  1780
apply (rule sin_total, auto)
paulson@15077
  1781
done
paulson@15077
  1782
huffman@22975
  1783
lemma arccos:
paulson@15229
  1784
     "[| -1 \<le> y; y \<le> 1 |]  
huffman@22975
  1785
      ==> 0 \<le> arccos y & arccos y \<le> pi & cos(arccos y) = y"
huffman@23011
  1786
unfolding arccos_def by (rule theI' [OF cos_total])
paulson@15077
  1787
huffman@22975
  1788
lemma cos_arccos [simp]: "[| -1 \<le> y; y \<le> 1 |] ==> cos(arccos y) = y"
huffman@22975
  1789
by (blast dest: arccos)
paulson@15077
  1790
      
huffman@22975
  1791
lemma arccos_bounded: "[| -1 \<le> y; y \<le> 1 |] ==> 0 \<le> arccos y & arccos y \<le> pi"
huffman@22975
  1792
by (blast dest: arccos)
paulson@15077
  1793
huffman@22975
  1794
lemma arccos_lbound: "[| -1 \<le> y; y \<le> 1 |] ==> 0 \<le> arccos y"
huffman@22975
  1795
by (blast dest: arccos)
paulson@15077
  1796
huffman@22975
  1797
lemma arccos_ubound: "[| -1 \<le> y; y \<le> 1 |] ==> arccos y \<le> pi"
huffman@22975
  1798
by (blast dest: arccos)
paulson@15077
  1799
huffman@22975
  1800
lemma arccos_lt_bounded:
paulson@15229
  1801
     "[| -1 < y; y < 1 |]  
huffman@22975
  1802
      ==> 0 < arccos y & arccos y < pi"
paulson@15077
  1803
apply (frule order_less_imp_le)
paulson@15077
  1804
apply (frule_tac y = y in order_less_imp_le)
huffman@22975
  1805
apply (frule arccos_bounded, auto)
huffman@22975
  1806
apply (drule_tac y = "arccos y" in order_le_imp_less_or_eq)
paulson@15077
  1807
apply (drule_tac [2] y = pi in order_le_imp_less_or_eq, auto)
paulson@15077
  1808
apply (drule_tac [!] f = cos in arg_cong, auto)
paulson@15077
  1809
done
paulson@15077
  1810
huffman@22975
  1811
lemma arccos_cos: "[|0 \<le> x; x \<le> pi |] ==> arccos(cos x) = x"
huffman@22975
  1812
apply (simp add: arccos_def)
huffman@23011
  1813
apply (auto intro!: the1_equality cos_total)
paulson@15077
  1814
done
paulson@15077
  1815
huffman@22975
  1816
lemma arccos_cos2: "[|x \<le> 0; -pi \<le> x |] ==> arccos(cos x) = -x"
huffman@22975
  1817
apply (simp add: arccos_def)
huffman@23011
  1818
apply (auto intro!: the1_equality cos_total)
paulson@15077
  1819
done
paulson@15077
  1820
huffman@23045
  1821
lemma cos_arcsin: "\<lbrakk>-1 \<le> x; x \<le> 1\<rbrakk> \<Longrightarrow> cos (arcsin x) = sqrt (1 - x\<twosuperior>)"
huffman@23045
  1822
apply (subgoal_tac "x\<twosuperior> \<le> 1")
huffman@23052
  1823
apply (rule power2_eq_imp_eq)
huffman@23045
  1824
apply (simp add: cos_squared_eq)
huffman@23045
  1825
apply (rule cos_ge_zero)
huffman@23045
  1826
apply (erule (1) arcsin_lbound)
huffman@23045
  1827
apply (erule (1) arcsin_ubound)
huffman@23045
  1828
apply simp
huffman@23045
  1829
apply (subgoal_tac "\<bar>x\<bar>\<twosuperior> \<le> 1\<twosuperior>", simp)
huffman@23045
  1830
apply (rule power_mono, simp, simp)
huffman@23045
  1831
done
huffman@23045
  1832
huffman@23045
  1833
lemma sin_arccos: "\<lbrakk>-1 \<le> x; x \<le> 1\<rbrakk> \<Longrightarrow> sin (arccos x) = sqrt (1 - x\<twosuperior>)"
huffman@23045
  1834
apply (subgoal_tac "x\<twosuperior> \<le> 1")
huffman@23052
  1835
apply (rule power2_eq_imp_eq)
huffman@23045
  1836
apply (simp add: sin_squared_eq)
huffman@23045
  1837
apply (rule sin_ge_zero)
huffman@23045
  1838
apply (erule (1) arccos_lbound)
huffman@23045
  1839
apply (erule (1) arccos_ubound)
huffman@23045
  1840
apply simp
huffman@23045
  1841
apply (subgoal_tac "\<bar>x\<bar>\<twosuperior> \<le> 1\<twosuperior>", simp)
huffman@23045
  1842
apply (rule power_mono, simp, simp)
huffman@23045
  1843
done
huffman@23045
  1844
paulson@15077
  1845
lemma arctan [simp]:
paulson@15077
  1846
     "- (pi/2) < arctan y  & arctan y < pi/2 & tan (arctan y) = y"
huffman@23011
  1847
unfolding arctan_def by (rule theI' [OF tan_total])
paulson@15077
  1848
paulson@15077
  1849
lemma tan_arctan: "tan(arctan y) = y"
paulson@15077
  1850
by auto
paulson@15077
  1851
paulson@15077
  1852
lemma arctan_bounded: "- (pi/2) < arctan y  & arctan y < pi/2"
paulson@15077
  1853
by (auto simp only: arctan)
paulson@15077
  1854
paulson@15077
  1855
lemma arctan_lbound: "- (pi/2) < arctan y"
paulson@15077
  1856
by auto
paulson@15077
  1857
paulson@15077
  1858
lemma arctan_ubound: "arctan y < pi/2"
paulson@15077
  1859
by (auto simp only: arctan)
paulson@15077
  1860
paulson@15077
  1861
lemma arctan_tan: 
paulson@15077
  1862
      "[|-(pi/2) < x; x < pi/2 |] ==> arctan(tan x) = x"
paulson@15077
  1863
apply (unfold arctan_def)
huffman@23011
  1864
apply (rule the1_equality)
paulson@15077
  1865
apply (rule tan_total, auto)
paulson@15077
  1866
done
paulson@15077
  1867
paulson@15077
  1868
lemma arctan_zero_zero [simp]: "arctan 0 = 0"
paulson@15077
  1869
by (insert arctan_tan [of 0], simp)
paulson@15077
  1870
paulson@15077
  1871
lemma cos_arctan_not_zero [simp]: "cos(arctan x) \<noteq> 0"
paulson@15077
  1872
apply (auto simp add: cos_zero_iff)
paulson@15077
  1873
apply (case_tac "n")
paulson@15077
  1874
apply (case_tac [3] "n")
paulson@15077
  1875
apply (cut_tac [2] y = x in arctan_ubound)
paulson@15077
  1876
apply (cut_tac [4] y = x in arctan_lbound) 
paulson@15077
  1877
apply (auto simp add: real_of_nat_Suc left_distrib mult_less_0_iff)
paulson@15077
  1878
done
paulson@15077
  1879
paulson@15077
  1880
lemma tan_sec: "cos x \<noteq> 0 ==> 1 + tan(x) ^ 2 = inverse(cos x) ^ 2"
paulson@15077
  1881
apply (rule power_inverse [THEN subst])
paulson@15077
  1882
apply (rule_tac c1 = "(cos x)\<twosuperior>" in real_mult_right_cancel [THEN iffD1])
huffman@22960
  1883
apply (auto dest: field_power_not_zero
huffman@20516
  1884
        simp add: power_mult_distrib left_distrib power_divide tan_def 
paulson@15077
  1885
                  mult_assoc power_inverse [symmetric] 
paulson@15077
  1886
        simp del: realpow_Suc)
paulson@15077
  1887
done
paulson@15077
  1888
huffman@23045
  1889
lemma isCont_inverse_function2:
huffman@23045
  1890
  fixes f g :: "real \<Rightarrow> real" shows
huffman@23045
  1891
  "\<lbrakk>a < x; x < b;
huffman@23045
  1892
    \<forall>z. a \<le> z \<and> z \<le> b \<longrightarrow> g (f z) = z;
huffman@23045
  1893
    \<forall>z. a \<le> z \<and> z \<le> b \<longrightarrow> isCont f z\<rbrakk>
huffman@23045
  1894
   \<Longrightarrow> isCont g (f x)"
huffman@23045
  1895
apply (rule isCont_inverse_function
huffman@23045
  1896
       [where f=f and d="min (x - a) (b - x)"])
huffman@23045
  1897
apply (simp_all add: abs_le_iff)
huffman@23045
  1898
done
huffman@23045
  1899
huffman@23045
  1900
lemma isCont_arcsin: "\<lbrakk>-1 < x; x < 1\<rbrakk> \<Longrightarrow> isCont arcsin x"
huffman@23045
  1901
apply (subgoal_tac "isCont arcsin (sin (arcsin x))", simp)
huffman@23045
  1902
apply (rule isCont_inverse_function2 [where f=sin])
huffman@23045
  1903
apply (erule (1) arcsin_lt_bounded [THEN conjunct1])
huffman@23045
  1904
apply (erule (1) arcsin_lt_bounded [THEN conjunct2])
huffman@23045
  1905
apply (fast intro: arcsin_sin, simp)
huffman@23045
  1906
done
huffman@23045
  1907
huffman@23045
  1908
lemma isCont_arccos: "\<lbrakk>-1 < x; x < 1\<rbrakk> \<Longrightarrow> isCont arccos x"
huffman@23045
  1909
apply (subgoal_tac "isCont arccos (cos (arccos x))", simp)
huffman@23045
  1910
apply (rule isCont_inverse_function2 [where f=cos])
huffman@23045
  1911
apply (erule (1) arccos_lt_bounded [THEN conjunct1])
huffman@23045
  1912
apply (erule (1) arccos_lt_bounded [THEN conjunct2])
huffman@23045
  1913
apply (fast intro: arccos_cos, simp)
huffman@23045
  1914
done
huffman@23045
  1915
huffman@23045
  1916
lemma isCont_arctan: "isCont arctan x"
huffman@23045
  1917
apply (rule arctan_lbound [of x, THEN dense, THEN exE], clarify)
huffman@23045
  1918
apply (rule arctan_ubound [of x, THEN dense, THEN exE], clarify)
huffman@23045
  1919
apply (subgoal_tac "isCont arctan (tan (arctan x))", simp)
huffman@23045
  1920
apply (erule (1) isCont_inverse_function2 [where f=tan])
huffman@23045
  1921
apply (clarify, rule arctan_tan)
huffman@23045
  1922
apply (erule (1) order_less_le_trans)
huffman@23045
  1923
apply (erule (1) order_le_less_trans)
huffman@23045
  1924
apply (clarify, rule isCont_tan)
huffman@23045
  1925
apply (rule less_imp_neq [symmetric])
huffman@23045
  1926
apply (rule cos_gt_zero_pi)
huffman@23045
  1927
apply (erule (1) order_less_le_trans)
huffman@23045
  1928
apply (erule (1) order_le_less_trans)
huffman@23045
  1929
done
huffman@23045
  1930
huffman@23045
  1931
lemma DERIV_arcsin:
huffman@23045
  1932
  "\<lbrakk>-1 < x; x < 1\<rbrakk> \<Longrightarrow> DERIV arcsin x :> inverse (sqrt (1 - x\<twosuperior>))"
huffman@23045
  1933
apply (rule DERIV_inverse_function [where f=sin and a="-1" and b="1"])
huffman@23045
  1934
apply (rule lemma_DERIV_subst [OF DERIV_sin])
huffman@23045
  1935
apply (simp add: cos_arcsin)
huffman@23045
  1936
apply (subgoal_tac "\<bar>x\<bar>\<twosuperior> < 1\<twosuperior>", simp)
huffman@23045
  1937
apply (rule power_strict_mono, simp, simp, simp)
huffman@23045
  1938
apply assumption
huffman@23045
  1939
apply assumption
huffman@23045
  1940
apply simp
huffman@23045
  1941
apply (erule (1) isCont_arcsin)
huffman@23045
  1942
done
huffman@23045
  1943
huffman@23045
  1944
lemma DERIV_arccos:
huffman@23045
  1945
  "\<lbrakk>-1 < x; x < 1\<rbrakk> \<Longrightarrow> DERIV arccos x :> inverse (- sqrt (1 - x\<twosuperior>))"
huffman@23045
  1946
apply (rule DERIV_inverse_function [where f=cos and a="-1" and b="1"])
huffman@23045
  1947
apply (rule lemma_DERIV_subst [OF DERIV_cos])
huffman@23045
  1948
apply (simp add: sin_arccos)
huffman@23045
  1949
apply (subgoal_tac "\<bar>x\<bar>\<twosuperior> < 1\<twosuperior>", simp)
huffman@23045
  1950
apply (rule power_strict_mono, simp, simp, simp)
huffman@23045
  1951
apply assumption
huffman@23045
  1952
apply assumption
huffman@23045
  1953
apply simp
huffman@23045
  1954
apply (erule (1) isCont_arccos)
huffman@23045
  1955
done
huffman@23045
  1956
huffman@23045
  1957
lemma DERIV_arctan: "DERIV arctan x :> inverse (1 + x\<twosuperior>)"
huffman@23045
  1958
apply (rule DERIV_inverse_function [where f=tan and a="x - 1" and b="x + 1"])
huffman@23045
  1959
apply (rule lemma_DERIV_subst [OF DERIV_tan])
huffman@23045
  1960
apply (rule cos_arctan_not_zero)
huffman@23045
  1961
apply (simp add: power_inverse tan_sec [symmetric])
huffman@23045
  1962
apply (subgoal_tac "0 < 1 + x\<twosuperior>", simp)
huffman@23045
  1963
apply (simp add: add_pos_nonneg)
huffman@23045
  1964
apply (simp, simp, simp, rule isCont_arctan)
huffman@23045
  1965
done
huffman@23045
  1966
huffman@23045
  1967
huffman@23043
  1968
subsection {* More Theorems about Sin and Cos *}
huffman@23043
  1969
huffman@23052
  1970
lemma cos_45: "cos (pi / 4) = sqrt 2 / 2"
huffman@23052
  1971
proof -
huffman@23052
  1972
  let ?c = "cos (pi / 4)" and ?s = "sin (pi / 4)"
huffman@23052
  1973
  have nonneg: "0 \<le> ?c"
huffman@23052
  1974
    by (rule cos_ge_zero, rule order_trans [where y=0], simp_all)
huffman@23052
  1975
  have "0 = cos (pi / 4 + pi / 4)"
huffman@23052
  1976
    by simp
huffman@23052
  1977
  also have "cos (pi / 4 + pi / 4) = ?c\<twosuperior> - ?s\<twosuperior>"
huffman@23052
  1978
    by (simp only: cos_add power2_eq_square)
huffman@23052
  1979
  also have "\<dots> = 2 * ?c\<twosuperior> - 1"
huffman@23052
  1980
    by (simp add: sin_squared_eq)
huffman@23052
  1981
  finally have "?c\<twosuperior> = (sqrt 2 / 2)\<twosuperior>"
huffman@23052
  1982
    by (simp add: power_divide)
huffman@23052
  1983
  thus ?thesis
huffman@23052
  1984
    using nonneg by (rule power2_eq_imp_eq) simp
huffman@23052
  1985
qed
huffman@23052
  1986
huffman@23052
  1987
lemma cos_30: "cos (pi / 6) = sqrt 3 / 2"
huffman@23052
  1988
proof -
huffman@23052
  1989
  let ?c = "cos (pi / 6)" and ?s = "sin (pi / 6)"
huffman@23052
  1990
  have pos_c: "0 < ?c"
huffman@23052
  1991
    by (rule cos_gt_zero, simp, simp)
huffman@23052
  1992
  have "0 = cos (pi / 6 + pi / 6 + pi / 6)"
huffman@23066
  1993
    by simp
huffman@23052
  1994
  also have "\<dots> = (?c * ?c - ?s * ?s) * ?c - (?s * ?c + ?c * ?s) * ?s"
huffman@23052
  1995
    by (simp only: cos_add sin_add)
huffman@23052
  1996
  also have "\<dots> = ?c * (?c\<twosuperior> - 3 * ?s\<twosuperior>)"
nipkow@23477
  1997
    by (simp add: ring_simps power2_eq_square)
huffman@23052
  1998
  finally have "?c\<twosuperior> = (sqrt 3 / 2)\<twosuperior>"
huffman@23052
  1999
    using pos_c by (simp add: sin_squared_eq power_divide)
huffman@23052
  2000
  thus ?thesis
huffman@23052
  2001
    using pos_c [THEN order_less_imp_le]
huffman@23052
  2002
    by (rule power2_eq_imp_eq) simp
huffman@23052
  2003
qed
huffman@23052
  2004
huffman@23052
  2005
lemma sin_45: "sin (pi / 4) = sqrt 2 / 2"
huffman@23052
  2006
proof -
huffman@23052
  2007
  have "sin (pi / 4) = cos (pi / 2 - pi / 4)" by (rule sin_cos_eq)
huffman@23052
  2008
  also have "pi / 2 - pi / 4 = pi / 4" by simp
huffman@23052
  2009
  also have "cos (pi / 4) = sqrt 2 / 2" by (rule cos_45)
huffman@23052
  2010
  finally show ?thesis .
huffman@23052
  2011
qed
huffman@23052
  2012
huffman@23052
  2013
lemma sin_60: "sin (pi / 3) = sqrt 3 / 2"
huffman@23052
  2014
proof -
huffman@23052
  2015
  have "sin (pi / 3) = cos (pi / 2 - pi / 3)" by (rule sin_cos_eq)
huffman@23052
  2016
  also have "pi / 2 - pi / 3 = pi / 6" by simp
huffman@23052
  2017
  also have "cos (pi / 6) = sqrt 3 / 2" by (rule cos_30)
huffman@23052
  2018
  finally show ?thesis .
huffman@23052
  2019
qed
huffman@23052
  2020
huffman@23052
  2021
lemma cos_60: "cos (pi / 3) = 1 / 2"
huffman@23052
  2022
apply (rule power2_eq_imp_eq)
huffman@23052
  2023
apply (simp add: cos_squared_eq sin_60 power_divide)
huffman@23052
  2024
apply (rule cos_ge_zero, rule order_trans [where y=0], simp_all)
huffman@23052
  2025
done
huffman@23052
  2026
huffman@23052
  2027
lemma sin_30: "sin (pi / 6) = 1 / 2"
huffman@23052
  2028
proof -
huffman@23052
  2029
  have "sin (pi / 6) = cos (pi / 2 - pi / 6)" by (rule sin_cos_eq)
huffman@23066
  2030
  also have "pi / 2 - pi / 6 = pi / 3" by simp
huffman@23052
  2031
  also have "cos (pi / 3) = 1 / 2" by (rule cos_60)
huffman@23052
  2032
  finally show ?thesis .
huffman@23052
  2033
qed
huffman@23052
  2034
huffman@23052
  2035
lemma tan_30: "tan (pi / 6) = 1 / sqrt 3"
huffman@23052
  2036
unfolding tan_def by (simp add: sin_30 cos_30)
huffman@23052
  2037
huffman@23052
  2038
lemma tan_45: "tan (pi / 4) = 1"
huffman@23052
  2039
unfolding tan_def by (simp add: sin_45 cos_45)
huffman@23052
  2040
huffman@23052
  2041
lemma tan_60: "tan (pi / 3) = sqrt 3"
huffman@23052
  2042
unfolding tan_def by (simp add: sin_60 cos_60)
huffman@23052
  2043
paulson@15085
  2044
text{*NEEDED??*}
paulson@15229
  2045
lemma [simp]:
paulson@15229
  2046
     "sin (x + 1 / 2 * real (Suc m) * pi) =  
paulson@15229
  2047
      cos (x + 1 / 2 * real  (m) * pi)"
paulson@15229
  2048
by (simp only: cos_add sin_add real_of_nat_Suc left_distrib right_distrib, auto)
paulson@15077
  2049
paulson@15085
  2050
text{*NEEDED??*}
paulson@15229
  2051
lemma [simp]:
paulson@15229
  2052
     "sin (x + real (Suc m) * pi / 2) =  
paulson@15229
  2053
      cos (x + real (m) * pi / 2)"
paulson@15229
  2054
by (simp only: cos_add sin_add real_of_nat_Suc add_divide_distrib left_distrib, auto)
paulson@15077
  2055
paulson@15077
  2056
lemma DERIV_sin_add [simp]: "DERIV (%x. sin (x + k)) xa :> cos (xa + k)"
paulson@15077
  2057
apply (rule lemma_DERIV_subst)
paulson@15077
  2058
apply (rule_tac f = sin and g = "%x. x + k" in DERIV_chain2)
paulson@15077
  2059
apply (best intro!: DERIV_intros intro: DERIV_chain2)+
paulson@15077
  2060
apply (simp (no_asm))
paulson@15077
  2061
done
paulson@15077
  2062
paulson@15383
  2063
lemma sin_cos_npi [simp]: "sin (real (Suc (2 * n)) * pi / 2) = (-1) ^ n"
paulson@15383
  2064
proof -
paulson@15383
  2065
  have "sin ((real n + 1/2) * pi) = cos (real n * pi)"
paulson@15383
  2066
    by (auto simp add: right_distrib sin_add left_distrib mult_ac)
paulson@15383
  2067
  thus ?thesis
paulson@15383
  2068
    by (simp add: real_of_nat_Suc left_distrib add_divide_distrib 
paulson@15383
  2069
                  mult_commute [of pi])
paulson@15383
  2070
qed
paulson@15077
  2071
paulson@15077
  2072
lemma cos_2npi [simp]: "cos (2 * real (n::nat) * pi) = 1"
paulson@15077
  2073
by (simp add: cos_double mult_assoc power_add [symmetric] numeral_2_eq_2)
paulson@15077
  2074
paulson@15077
  2075
lemma cos_3over2_pi [simp]: "cos (3 / 2 * pi) = 0"
huffman@23066
  2076
apply (subgoal_tac "cos (pi + pi/2) = 0", simp)
huffman@23066
  2077
apply (subst cos_add, simp)
paulson@15077
  2078
done
paulson@15077
  2079
paulson@15077
  2080
lemma sin_2npi [simp]: "sin (2 * real (n::nat) * pi) = 0"
paulson@15077
  2081
by (auto simp add: mult_assoc)
paulson@15077
  2082
paulson@15077
  2083
lemma sin_3over2_pi [simp]: "sin (3 / 2 * pi) = - 1"
huffman@23066
  2084
apply (subgoal_tac "sin (pi + pi/2) = - 1", simp)
huffman@23066
  2085
apply (subst sin_add, simp)
paulson@15077
  2086
done
paulson@15077
  2087
paulson@15077
  2088
(*NEEDED??*)
paulson@15229
  2089
lemma [simp]:
paulson@15229
  2090
     "cos(x + 1 / 2 * real(Suc m) * pi) = -sin (x + 1 / 2 * real m * pi)"
paulson@15077
  2091
apply (simp only: cos_add sin_add real_of_nat_Suc right_distrib left_distrib minus_mult_right, auto)
paulson@15077
  2092
done
paulson@15077
  2093
paulson@15077
  2094
(*NEEDED??*)
paulson@15077
  2095
lemma [simp]: "cos (x + real(Suc m) * pi / 2) = -sin (x + real m * pi / 2)"
paulson@15229
  2096
by (simp only: cos_add sin_add real_of_nat_Suc left_distrib add_divide_distrib, auto)
paulson@15077
  2097
paulson@15077
  2098
lemma cos_pi_eq_zero [simp]: "cos (pi * real (Suc (2 * m)) / 2) = 0"
paulson@15229
  2099
by (simp only: cos_add sin_add real_of_nat_Suc left_distrib right_distrib add_divide_distrib, auto)
paulson@15077
  2100
paulson@15077
  2101
lemma DERIV_cos_add [simp]: "DERIV (%x. cos (x + k)) xa :> - sin (xa + k)"
paulson@15077
  2102
apply (rule lemma_DERIV_subst)
paulson@15077
  2103
apply (rule_tac f = cos and g = "%x. x + k" in DERIV_chain2)
paulson@15077
  2104
apply (best intro!: DERIV_intros intro: DERIV_chain2)+
paulson@15077
  2105
apply (simp (no_asm))
paulson@15077
  2106
done
paulson@15077
  2107
paulson@15081
  2108
lemma sin_zero_abs_cos_one: "sin x = 0 ==> \<bar>cos x\<bar> = 1"
nipkow@15539
  2109
by (auto simp add: sin_zero_iff even_mult_two_ex)
paulson@15077
  2110
huffman@23115
  2111
lemma exp_eq_one_iff [simp]: "(exp (x::real) = 1) = (x = 0)"
paulson@15077
  2112
apply auto
paulson@15077
  2113
apply (drule_tac f = ln in arg_cong, auto)
paulson@15077
  2114
done
paulson@15077
  2115
paulson@15077
  2116
lemma cos_one_sin_zero: "cos x = 1 ==> sin x = 0"
paulson@15077
  2117
by (cut_tac x = x in sin_cos_squared_add3, auto)
paulson@15077
  2118
paulson@15077
  2119
huffman@22978
  2120
subsection {* Existence of Polar Coordinates *}
paulson@15077
  2121
huffman@22978
  2122
lemma cos_x_y_le_one: "\<bar>x / sqrt (x\<twosuperior> + y\<twosuperior>)\<bar> \<le> 1"
huffman@22978
  2123
apply (rule power2_le_imp_le [OF _ zero_le_one])
huffman@22978
  2124
apply (simp add: abs_divide power_divide divide_le_eq not_sum_power2_lt_zero)
paulson@15077
  2125
done
paulson@15077
  2126
huffman@22978
  2127
lemma cos_arccos_abs: "\<bar>y\<bar> \<le> 1 \<Longrightarrow> cos (arccos y) = y"
huffman@22978
  2128
by (simp add: abs_le_iff)
paulson@15077
  2129
huffman@23045
  2130
lemma sin_arccos_abs: "\<bar>y\<bar> \<le> 1 \<Longrightarrow> sin (arccos y) = sqrt (1 - y\<twosuperior>)"
huffman@23045
  2131
by (simp add: sin_arccos abs_le_iff)
paulson@15077
  2132
huffman@22978
  2133
lemmas cos_arccos_lemma1 = cos_arccos_abs [OF cos_x_y_le_one]
paulson@15228
  2134
huffman@23045
  2135
lemmas sin_arccos_lemma1 = sin_arccos_abs [OF cos_x_y_le_one]
paulson@15077
  2136
paulson@15229
  2137
lemma polar_ex1:
huffman@22978
  2138
     "0 < y ==> \<exists>r a. x = r * cos a & y = r * sin a"
paulson@15229
  2139
apply (rule_tac x = "sqrt (x\<twosuperior> + y\<twosuperior>)" in exI)
huffman@22978
  2140
apply (rule_tac x = "arccos (x / sqrt (x\<twosuperior> + y\<twosuperior>))" in exI)
huffman@22978
  2141
apply (simp add: cos_arccos_lemma1)
huffman@23045
  2142
apply (simp add: sin_arccos_lemma1)
huffman@23045
  2143
apply (simp add: power_divide)
huffman@23045
  2144
apply (simp add: real_sqrt_mult [symmetric])
huffman@23045
  2145
apply (simp add: right_diff_distrib)
paulson@15077
  2146
done
paulson@15077
  2147
paulson@15229
  2148
lemma polar_ex2:
huffman@22978
  2149
     "y < 0 ==> \<exists>r a. x = r * cos a & y = r * sin a"
huffman@22978
  2150
apply (insert polar_ex1 [where x=x and y="-y"], simp, clarify)
paulson@15077
  2151
apply (rule_tac x = r in exI)
huffman@22978
  2152
apply (rule_tac x = "-a" in exI, simp)
paulson@15077
  2153
done
paulson@15077
  2154
paulson@15077
  2155
lemma polar_Ex: "\<exists>r a. x = r * cos a & y = r * sin a"
huffman@22978
  2156
apply (rule_tac x=0 and y=y in linorder_cases)
huffman@22978
  2157
apply (erule polar_ex1)
huffman@22978
  2158
apply (rule_tac x=x in exI, rule_tac x=0 in exI, simp)
huffman@22978
  2159
apply (erule polar_ex2)
paulson@15077
  2160
done
paulson@15077
  2161
paulson@12196
  2162
end