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