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