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