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