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