src/HOL/Hyperreal/Transcendental.thy
changeset 15229 1eb23f805c06
parent 15228 4d332d10fa3d
child 15234 ec91a90c604e
equal deleted inserted replaced
15228:4d332d10fa3d 15229:1eb23f805c06
    50     arctan :: "real => real"
    50     arctan :: "real => real"
    51     "arctan y == (@x. -(pi/2) < x & x < pi/2 & tan x = y)"
    51     "arctan y == (@x. -(pi/2) < x & x < pi/2 & tan x = y)"
    52 
    52 
    53 
    53 
    54 lemma real_root_zero [simp]: "root (Suc n) 0 = 0"
    54 lemma real_root_zero [simp]: "root (Suc n) 0 = 0"
    55 apply (unfold root_def)
    55 apply (simp add: root_def)
    56 apply (safe intro!: some_equality power_0_Suc elim!: realpow_zero_zero)
    56 apply (safe intro!: some_equality power_0_Suc elim!: realpow_zero_zero)
    57 done
    57 done
    58 
    58 
    59 lemma real_root_pow_pos: 
    59 lemma real_root_pow_pos: 
    60      "0 < x ==> (root(Suc n) x) ^ (Suc n) = x"
    60      "0 < x ==> (root(Suc n) x) ^ (Suc n) = x"
    61 apply (unfold root_def)
    61 apply (simp add: root_def)
    62 apply (drule_tac n = n in realpow_pos_nth2)
    62 apply (drule_tac n = n in realpow_pos_nth2)
    63 apply (auto intro: someI2)
    63 apply (auto intro: someI2)
    64 done
    64 done
    65 
    65 
    66 lemma real_root_pow_pos2: "0 \<le> x ==> (root(Suc n) x) ^ (Suc n) = x"
    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)
    67 by (auto dest!: real_le_imp_less_or_eq dest: real_root_pow_pos)
    68 
    68 
    69 lemma real_root_pos: 
    69 lemma real_root_pos: 
    70      "0 < x ==> root(Suc n) (x ^ (Suc n)) = x"
    70      "0 < x ==> root(Suc n) (x ^ (Suc n)) = x"
    71 apply (unfold root_def)
    71 apply (simp add: root_def)
    72 apply (rule some_equality)
    72 apply (rule some_equality)
    73 apply (frule_tac [2] n = n in zero_less_power)
    73 apply (frule_tac [2] n = n in zero_less_power)
    74 apply (auto simp add: zero_less_mult_iff)
    74 apply (auto simp add: zero_less_mult_iff)
    75 apply (rule_tac x = u and y = x in linorder_cases)
    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])
    76 apply (drule_tac n1 = n and x = u in zero_less_Suc [THEN [3] realpow_less])
    81 lemma real_root_pos2: "0 \<le> x ==> root(Suc n) (x ^ (Suc n)) = x"
    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)
    82 by (auto dest!: real_le_imp_less_or_eq real_root_pos)
    83 
    83 
    84 lemma real_root_pos_pos: 
    84 lemma real_root_pos_pos: 
    85      "0 < x ==> 0 \<le> root(Suc n) x"
    85      "0 < x ==> 0 \<le> root(Suc n) x"
    86 apply (unfold root_def)
    86 apply (simp add: root_def)
    87 apply (drule_tac n = n in realpow_pos_nth2)
    87 apply (drule_tac n = n in realpow_pos_nth2)
    88 apply (safe, rule someI2)
    88 apply (safe, rule someI2)
    89 apply (auto intro!: order_less_imp_le dest: zero_less_power simp add: zero_less_mult_iff)
    89 apply (auto intro!: order_less_imp_le dest: zero_less_power 
       
    90             simp add: zero_less_mult_iff)
    90 done
    91 done
    91 
    92 
    92 lemma real_root_pos_pos_le: "0 \<le> x ==> 0 \<le> root(Suc n) x"
    93 lemma real_root_pos_pos_le: "0 \<le> x ==> 0 \<le> root(Suc n) x"
    93 by (auto dest!: real_le_imp_less_or_eq dest: real_root_pos_pos)
    94 by (auto dest!: real_le_imp_less_or_eq dest: real_root_pos_pos)
    94 
    95 
    95 lemma real_root_one [simp]: "root (Suc n) 1 = 1"
    96 lemma real_root_one [simp]: "root (Suc n) 1 = 1"
    96 apply (unfold root_def)
    97 apply (simp add: root_def)
    97 apply (rule some_equality, auto)
    98 apply (rule some_equality, auto)
    98 apply (rule ccontr)
    99 apply (rule ccontr)
    99 apply (rule_tac x = u and y = 1 in linorder_cases)
   100 apply (rule_tac x = u and y = 1 in linorder_cases)
   100 apply (drule_tac n = n in realpow_Suc_less_one)
   101 apply (drule_tac n = n in realpow_Suc_less_one)
   101 apply (drule_tac [4] n = n in power_gt1_lemma)
   102 apply (drule_tac [4] n = n in power_gt1_lemma)
   103 done
   104 done
   104 
   105 
   105 
   106 
   106 subsection{*Square Root*}
   107 subsection{*Square Root*}
   107 
   108 
   108 (*lcp: needed now because 2 is a binary numeral!*)
   109 text{*needed because 2 is a binary numeral!*}
   109 lemma root_2_eq [simp]: "root 2 = root (Suc (Suc 0))"
   110 lemma root_2_eq [simp]: "root 2 = root (Suc (Suc 0))"
   110 apply (simp (no_asm) del: nat_numeral_0_eq_0 nat_numeral_1_eq_1 add: nat_numeral_0_eq_0 [symmetric])
   111 by (simp del: nat_numeral_0_eq_0 nat_numeral_1_eq_1 
   111 done
   112          add: nat_numeral_0_eq_0 [symmetric])
   112 
   113 
   113 lemma real_sqrt_zero [simp]: "sqrt 0 = 0"
   114 lemma real_sqrt_zero [simp]: "sqrt 0 = 0"
   114 by (unfold sqrt_def, auto)
   115 by (simp add: sqrt_def)
   115 
   116 
   116 lemma real_sqrt_one [simp]: "sqrt 1 = 1"
   117 lemma real_sqrt_one [simp]: "sqrt 1 = 1"
   117 by (unfold sqrt_def, auto)
   118 by (simp add: sqrt_def)
   118 
   119 
   119 lemma real_sqrt_pow2_iff [simp]: "((sqrt x)\<twosuperior> = x) = (0 \<le> x)"
   120 lemma real_sqrt_pow2_iff [simp]: "((sqrt x)\<twosuperior> = x) = (0 \<le> x)"
   120 apply (unfold sqrt_def)
   121 apply (simp add: sqrt_def)
   121 apply (rule iffI) 
   122 apply (rule iffI) 
   122  apply (cut_tac r = "root 2 x" in realpow_two_le)
   123  apply (cut_tac r = "root 2 x" in realpow_two_le)
   123  apply (simp add: numeral_2_eq_2)
   124  apply (simp add: numeral_2_eq_2)
   124 apply (subst numeral_2_eq_2)
   125 apply (subst numeral_2_eq_2)
   125 apply (erule real_root_pow_pos2)
   126 apply (erule real_root_pow_pos2)
   134 lemma real_sqrt_abs_abs [simp]: "sqrt\<bar>x\<bar> ^ 2 = \<bar>x\<bar>"
   135 lemma real_sqrt_abs_abs [simp]: "sqrt\<bar>x\<bar> ^ 2 = \<bar>x\<bar>"
   135 by (rule real_sqrt_pow2_iff [THEN iffD2], arith)
   136 by (rule real_sqrt_pow2_iff [THEN iffD2], arith)
   136 
   137 
   137 lemma real_pow_sqrt_eq_sqrt_pow: 
   138 lemma real_pow_sqrt_eq_sqrt_pow: 
   138       "0 \<le> x ==> (sqrt x)\<twosuperior> = sqrt(x\<twosuperior>)"
   139       "0 \<le> x ==> (sqrt x)\<twosuperior> = sqrt(x\<twosuperior>)"
   139 apply (unfold sqrt_def)
   140 apply (simp add: sqrt_def)
   140 apply (subst numeral_2_eq_2)
   141 apply (subst numeral_2_eq_2)
   141 apply (auto intro: real_root_pow_pos2 [THEN ssubst] real_root_pos2 [THEN ssubst] simp del: realpow_Suc)
   142 apply (auto intro: real_root_pow_pos2 [THEN ssubst] real_root_pos2 [THEN ssubst] simp del: realpow_Suc)
   142 done
   143 done
   143 
   144 
   144 lemma real_pow_sqrt_eq_sqrt_abs_pow2:
   145 lemma real_pow_sqrt_eq_sqrt_abs_pow2:
   160 
   161 
   161 lemma real_mult_self_eq_zero_iff [simp]: "(r * r = 0) = (r = (0::real))"
   162 lemma real_mult_self_eq_zero_iff [simp]: "(r * r = 0) = (r = (0::real))"
   162 by auto
   163 by auto
   163 
   164 
   164 lemma real_sqrt_gt_zero: "0 < x ==> 0 < sqrt(x)"
   165 lemma real_sqrt_gt_zero: "0 < x ==> 0 < sqrt(x)"
   165 apply (unfold sqrt_def root_def)
   166 apply (simp add: sqrt_def root_def)
   166 apply (subst numeral_2_eq_2)
       
   167 apply (drule realpow_pos_nth2 [where n=1], safe)
   167 apply (drule realpow_pos_nth2 [where n=1], safe)
   168 apply (rule someI2, auto)
   168 apply (rule someI2, auto)
   169 done
   169 done
   170 
   170 
   171 lemma real_sqrt_ge_zero: "0 \<le> x ==> 0 \<le> sqrt(x)"
   171 lemma real_sqrt_ge_zero: "0 \<le> x ==> 0 \<le> sqrt(x)"
   176 
   176 
   177 
   177 
   178 (*we need to prove something like this:
   178 (*we need to prove something like this:
   179 lemma "[|r ^ n = a; 0<n; 0 < a \<longrightarrow> 0 < r|] ==> root n a = r"
   179 lemma "[|r ^ n = a; 0<n; 0 < a \<longrightarrow> 0 < r|] ==> root n a = r"
   180 apply (case_tac n, simp) 
   180 apply (case_tac n, simp) 
   181 apply (unfold root_def) 
   181 apply (simp add: root_def) 
   182 apply (rule someI2 [of _ r], safe)
   182 apply (rule someI2 [of _ r], safe)
   183 apply (auto simp del: realpow_Suc dest: power_inject_base)
   183 apply (auto simp del: realpow_Suc dest: power_inject_base)
   184 *)
   184 *)
   185 
   185 
   186 lemma sqrt_eqI: "[|r\<twosuperior> = a; 0 \<le> r|] ==> sqrt a = r"
   186 lemma sqrt_eqI: "[|r\<twosuperior> = a; 0 \<le> r|] ==> sqrt a = r"
   195 apply (rule sqrt_eqI)
   195 apply (rule sqrt_eqI)
   196 apply (simp add: power_mult_distrib)  
   196 apply (simp add: power_mult_distrib)  
   197 apply (simp add: zero_le_mult_iff real_sqrt_ge_zero) 
   197 apply (simp add: zero_le_mult_iff real_sqrt_ge_zero) 
   198 done
   198 done
   199 
   199 
   200 lemma real_sqrt_mult_distrib2: "[|0\<le>x; 0\<le>y |] ==> sqrt(x*y) =  sqrt(x) * sqrt(y)"
   200 lemma real_sqrt_mult_distrib2:
       
   201      "[|0\<le>x; 0\<le>y |] ==> sqrt(x*y) =  sqrt(x) * sqrt(y)"
   201 by (auto intro: real_sqrt_mult_distrib simp add: order_le_less)
   202 by (auto intro: real_sqrt_mult_distrib simp add: order_le_less)
   202 
   203 
   203 lemma real_sqrt_sum_squares_ge_zero [simp]: "0 \<le> sqrt (x\<twosuperior> + y\<twosuperior>)"
   204 lemma real_sqrt_sum_squares_ge_zero [simp]: "0 \<le> sqrt (x\<twosuperior> + y\<twosuperior>)"
   204 by (auto intro!: real_sqrt_ge_zero)
   205 by (auto intro!: real_sqrt_ge_zero)
   205 
   206 
   206 lemma real_sqrt_sum_squares_mult_ge_zero [simp]: "0 \<le> sqrt ((x\<twosuperior> + y\<twosuperior>)*(xa\<twosuperior> + ya\<twosuperior>))"
   207 lemma real_sqrt_sum_squares_mult_ge_zero [simp]:
       
   208      "0 \<le> sqrt ((x\<twosuperior> + y\<twosuperior>)*(xa\<twosuperior> + ya\<twosuperior>))"
   207 by (auto intro!: real_sqrt_ge_zero simp add: zero_le_mult_iff)
   209 by (auto intro!: real_sqrt_ge_zero simp add: zero_le_mult_iff)
   208 
   210 
   209 lemma real_sqrt_sum_squares_mult_squared_eq [simp]:
   211 lemma real_sqrt_sum_squares_mult_squared_eq [simp]:
   210      "sqrt ((x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)) ^ 2 = (x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)"
   212      "sqrt ((x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)) ^ 2 = (x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)"
   211 by (auto simp add: real_sqrt_pow2_iff zero_le_mult_iff simp del: realpow_Suc)
   213 by (auto simp add: real_sqrt_pow2_iff zero_le_mult_iff simp del: realpow_Suc)
   237 lemma real_sqrt_eq_zero_cancel: "[| 0 \<le> x; sqrt(x) = 0|] ==> x = 0"
   239 lemma real_sqrt_eq_zero_cancel: "[| 0 \<le> x; sqrt(x) = 0|] ==> x = 0"
   238 apply (drule real_le_imp_less_or_eq)
   240 apply (drule real_le_imp_less_or_eq)
   239 apply (auto dest: real_sqrt_not_eq_zero)
   241 apply (auto dest: real_sqrt_not_eq_zero)
   240 done
   242 done
   241 
   243 
   242 lemma real_sqrt_eq_zero_cancel_iff [simp]: "0 \<le> x ==> ((sqrt x = 0) = (x = 0))"
   244 lemma real_sqrt_eq_zero_cancel_iff [simp]: "0 \<le> x ==> ((sqrt x = 0) = (x=0))"
   243 by (auto simp add: real_sqrt_eq_zero_cancel)
   245 by (auto simp add: real_sqrt_eq_zero_cancel)
   244 
   246 
   245 lemma real_sqrt_sum_squares_ge1 [simp]: "x \<le> sqrt(x\<twosuperior> + y\<twosuperior>)"
   247 lemma real_sqrt_sum_squares_ge1 [simp]: "x \<le> sqrt(x\<twosuperior> + y\<twosuperior>)"
   246 apply (subgoal_tac "x \<le> 0 | 0 \<le> x", safe)
   248 apply (subgoal_tac "x \<le> 0 | 0 \<le> x", safe)
   247 apply (rule real_le_trans)
   249 apply (rule real_le_trans)
   272 apply (rule mult_right_mono)
   274 apply (rule mult_right_mono)
   273 apply (rule_tac b1 = "\<bar>x\<bar>" in mult_commute [THEN ssubst])
   275 apply (rule_tac b1 = "\<bar>x\<bar>" in mult_commute [THEN ssubst])
   274 apply (subst fact_Suc)
   276 apply (subst fact_Suc)
   275 apply (subst real_of_nat_mult)
   277 apply (subst real_of_nat_mult)
   276 apply (auto simp add: abs_mult inverse_mult_distrib)
   278 apply (auto simp add: abs_mult inverse_mult_distrib)
   277 apply (auto simp add: mult_assoc [symmetric] abs_eqI2 positive_imp_inverse_positive)
   279 apply (auto simp add: mult_assoc [symmetric] positive_imp_inverse_positive)
   278 apply (rule order_less_imp_le)
   280 apply (rule order_less_imp_le)
   279 apply (rule_tac z1 = "real (Suc na) " in real_mult_less_iff1 [THEN iffD1])
   281 apply (rule_tac z1 = "real (Suc na)" in real_mult_less_iff1 [THEN iffD1])
   280 apply (auto simp add: real_not_refl2 [THEN not_sym] mult_assoc abs_inverse)
   282 apply (auto simp add: real_not_refl2 [THEN not_sym] mult_assoc abs_inverse)
   281 apply (erule order_less_trans)
   283 apply (erule order_less_trans)
   282 apply (auto simp add: mult_less_cancel_left mult_ac)
   284 apply (auto simp add: mult_less_cancel_left mult_ac)
   283 done
   285 done
   284 
   286 
   286 lemma summable_sin: 
   288 lemma summable_sin: 
   287      "summable (%n.  
   289      "summable (%n.  
   288            (if even n then 0  
   290            (if even n then 0  
   289            else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) *  
   291            else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) *  
   290                 x ^ n)"
   292                 x ^ n)"
   291 apply (unfold real_divide_def)
   293 apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test)
   292 apply (rule_tac g = " (%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n) " in summable_comparison_test)
       
   293 apply (rule_tac [2] summable_exp)
   294 apply (rule_tac [2] summable_exp)
   294 apply (rule_tac x = 0 in exI)
   295 apply (rule_tac x = 0 in exI)
   295 apply (auto simp add: power_abs [symmetric] abs_mult zero_le_mult_iff)
   296 apply (auto simp add: divide_inverse power_abs [symmetric] zero_le_mult_iff)
   296 done
   297 done
   297 
   298 
   298 lemma summable_cos: 
   299 lemma summable_cos: 
   299       "summable (%n.  
   300       "summable (%n.  
   300            (if even n then  
   301            (if even n then  
   301            (- 1) ^ (n div 2)/(real (fact n)) else 0) * x ^ n)"
   302            (- 1) ^ (n div 2)/(real (fact n)) else 0) * x ^ n)"
   302 apply (unfold real_divide_def)
   303 apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test)
   303 apply (rule_tac g = " (%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n) " in summable_comparison_test)
       
   304 apply (rule_tac [2] summable_exp)
   304 apply (rule_tac [2] summable_exp)
   305 apply (rule_tac x = 0 in exI)
   305 apply (rule_tac x = 0 in exI)
   306 apply (auto simp add: power_abs [symmetric] abs_mult zero_le_mult_iff)
   306 apply (auto simp add: divide_inverse power_abs [symmetric] zero_le_mult_iff)
   307 done
   307 done
   308 
   308 
   309 lemma lemma_STAR_sin [simp]: "(if even n then 0  
   309 lemma lemma_STAR_sin [simp]:
       
   310      "(if even n then 0  
   310        else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) * 0 ^ n = 0"
   311        else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) * 0 ^ n = 0"
   311 apply (induct_tac "n", auto)
   312 by (induct_tac "n", auto)
   312 done
   313 
   313 
   314 lemma lemma_STAR_cos [simp]:
   314 lemma lemma_STAR_cos [simp]: "0 < n -->  
   315      "0 < n -->  
   315       (- 1) ^ (n div 2)/(real (fact n)) * 0 ^ n = 0"
   316       (- 1) ^ (n div 2)/(real (fact n)) * 0 ^ n = 0"
   316 apply (induct_tac "n", auto)
   317 by (induct_tac "n", auto)
   317 done
   318 
   318 
   319 lemma lemma_STAR_cos1 [simp]:
   319 lemma lemma_STAR_cos1 [simp]: "0 < n -->  
   320      "0 < n -->  
   320       (-1) ^ (n div 2)/(real (fact n)) * 0 ^ n = 0"
   321       (-1) ^ (n div 2)/(real (fact n)) * 0 ^ n = 0"
   321 apply (induct_tac "n", auto)
   322 by (induct_tac "n", auto)
   322 done
   323 
   323 
   324 lemma lemma_STAR_cos2 [simp]:
   324 lemma lemma_STAR_cos2 [simp]: "sumr 1 n (%n. if even n  
   325      "sumr 1 n (%n. if even n  
   325                     then (- 1) ^ (n div 2)/(real (fact n)) *  
   326                     then (- 1) ^ (n div 2)/(real (fact n)) *  
   326                           0 ^ n  
   327                           0 ^ n  
   327                     else 0) = 0"
   328                     else 0) = 0"
   328 apply (induct_tac "n")
   329 apply (induct_tac "n")
   329 apply (case_tac [2] "n", auto)
   330 apply (case_tac [2] "n", auto)
   330 done
   331 done
   331 
   332 
   332 lemma exp_converges: "(%n. inverse (real (fact n)) * x ^ n) sums exp(x)"
   333 lemma exp_converges: "(%n. inverse (real (fact n)) * x ^ n) sums exp(x)"
   333 apply (unfold exp_def)
   334 apply (simp add: exp_def)
   334 apply (rule summable_exp [THEN summable_sums])
   335 apply (rule summable_exp [THEN summable_sums])
   335 done
   336 done
   336 
   337 
   337 lemma sin_converges: 
   338 lemma sin_converges: 
   338       "(%n. (if even n then 0  
   339       "(%n. (if even n then 0  
   339             else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) *  
   340             else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) *  
   340                  x ^ n) sums sin(x)"
   341                  x ^ n) sums sin(x)"
   341 apply (unfold sin_def)
   342 apply (simp add: sin_def)
   342 apply (rule summable_sin [THEN summable_sums])
   343 apply (rule summable_sin [THEN summable_sums])
   343 done
   344 done
   344 
   345 
   345 lemma cos_converges: 
   346 lemma cos_converges: 
   346       "(%n. (if even n then  
   347       "(%n. (if even n then  
   347            (- 1) ^ (n div 2)/(real (fact n))  
   348            (- 1) ^ (n div 2)/(real (fact n))  
   348            else 0) * x ^ n) sums cos(x)"
   349            else 0) * x ^ n) sums cos(x)"
   349 apply (unfold cos_def)
   350 apply (simp add: cos_def)
   350 apply (rule summable_cos [THEN summable_sums])
   351 apply (rule summable_cos [THEN summable_sums])
   351 done
   352 done
   352 
   353 
   353 lemma lemma_realpow_diff [rule_format (no_asm)]: "p \<le> n --> y ^ (Suc n - p) = ((y::real) ^ (n - p)) * y"
   354 lemma lemma_realpow_diff [rule_format (no_asm)]:
       
   355      "p \<le> n --> y ^ (Suc n - p) = ((y::real) ^ (n - p)) * y"
   354 apply (induct_tac "n", auto)
   356 apply (induct_tac "n", auto)
   355 apply (subgoal_tac "p = Suc n")
   357 apply (subgoal_tac "p = Suc n")
   356 apply (simp (no_asm_simp), auto)
   358 apply (simp (no_asm_simp), auto)
   357 apply (drule sym)
   359 apply (drule sym)
   358 apply (simp add: Suc_diff_le mult_commute realpow_Suc [symmetric] 
   360 apply (simp add: Suc_diff_le mult_commute realpow_Suc [symmetric] 
   370 apply (intro strip)
   372 apply (intro strip)
   371 apply (subst lemma_realpow_diff)
   373 apply (subst lemma_realpow_diff)
   372 apply (auto simp add: mult_ac)
   374 apply (auto simp add: mult_ac)
   373 done
   375 done
   374 
   376 
   375 lemma lemma_realpow_diff_sumr2: "x ^ (Suc n) - y ^ (Suc n) =  
   377 lemma lemma_realpow_diff_sumr2:
       
   378      "x ^ (Suc n) - y ^ (Suc n) =  
   376       (x - y) * sumr 0 (Suc n) (%p. (x ^ p) * (y ^(n - p)))"
   379       (x - y) * sumr 0 (Suc n) (%p. (x ^ p) * (y ^(n - p)))"
   377 apply (induct_tac "n", simp)
   380 apply (induct_tac "n", simp)
   378 apply (auto simp del: sumr_Suc)
   381 apply (auto simp del: sumr_Suc)
   379 apply (subst sumr_Suc)
   382 apply (subst sumr_Suc)
   380 apply (drule sym)
   383 apply (drule sym)
   381 apply (auto simp add: lemma_realpow_diff_sumr right_distrib real_diff_def mult_ac simp del: sumr_Suc)
   384 apply (auto simp add: lemma_realpow_diff_sumr right_distrib diff_minus mult_ac simp del: sumr_Suc)
   382 done
   385 done
   383 
   386 
   384 lemma lemma_realpow_rev_sumr: "sumr 0 (Suc n) (%p. (x ^ p) * (y ^ (n - p))) =  
   387 lemma lemma_realpow_rev_sumr:
       
   388      "sumr 0 (Suc n) (%p. (x ^ p) * (y ^ (n - p))) =  
   385       sumr 0 (Suc n) (%p. (x ^ (n - p)) * (y ^ p))"
   389       sumr 0 (Suc n) (%p. (x ^ (n - p)) * (y ^ p))"
   386 apply (case_tac "x = y")
   390 apply (case_tac "x = y")
   387 apply (auto simp add: mult_commute power_add [symmetric] simp del: sumr_Suc)
   391 apply (auto simp add: mult_commute power_add [symmetric] simp del: sumr_Suc)
   388 apply (rule_tac c1 = "x - y" in real_mult_left_cancel [THEN iffD1])
   392 apply (rule_tac c1 = "x - y" in real_mult_left_cancel [THEN iffD1])
   389 apply (rule_tac [2] minus_minus [THEN subst], simp)
   393 apply (rule_tac [2] minus_minus [THEN subst], simp)
   411  apply (drule_tac x = 0 in spec, force)
   415  apply (drule_tac x = 0 in spec, force)
   412 apply (auto simp add: abs_mult power_abs mult_ac)
   416 apply (auto simp add: abs_mult power_abs mult_ac)
   413 apply (rule_tac a2 = "z ^ n" 
   417 apply (rule_tac a2 = "z ^ n" 
   414        in abs_ge_zero [THEN real_le_imp_less_or_eq, THEN disjE])
   418        in abs_ge_zero [THEN real_le_imp_less_or_eq, THEN disjE])
   415 apply (auto intro!: mult_right_mono simp add: mult_assoc [symmetric] power_abs summable_def power_0_left)
   419 apply (auto intro!: mult_right_mono simp add: mult_assoc [symmetric] power_abs summable_def power_0_left)
   416 apply (rule_tac x = "K * inverse (1 - (\<bar>z\<bar> * inverse (\<bar>x\<bar>))) " in exI)
   420 apply (rule_tac x = "K * inverse (1 - (\<bar>z\<bar> * inverse (\<bar>x\<bar>)))" in exI)
   417 apply (auto intro!: sums_mult simp add: mult_assoc)
   421 apply (auto intro!: sums_mult simp add: mult_assoc)
   418 apply (subgoal_tac "\<bar>z ^ n\<bar> * inverse (\<bar>x\<bar> ^ n) = (\<bar>z\<bar> * inverse (\<bar>x\<bar>)) ^ n")
   422 apply (subgoal_tac "\<bar>z ^ n\<bar> * inverse (\<bar>x\<bar> ^ n) = (\<bar>z\<bar> * inverse (\<bar>x\<bar>)) ^ n")
   419 apply (auto simp add: power_abs [symmetric])
   423 apply (auto simp add: power_abs [symmetric])
   420 apply (subgoal_tac "x \<noteq> 0")
   424 apply (subgoal_tac "x \<noteq> 0")
   421 apply (subgoal_tac [3] "x \<noteq> 0")
   425 apply (subgoal_tac [3] "x \<noteq> 0")
   423 apply (auto intro!: geometric_sums simp add: power_abs inverse_eq_divide)
   427 apply (auto intro!: geometric_sums simp add: power_abs inverse_eq_divide)
   424 apply (rule_tac c="\<bar>x\<bar>" in mult_right_less_imp_less) 
   428 apply (rule_tac c="\<bar>x\<bar>" in mult_right_less_imp_less) 
   425 apply (auto simp add: abs_mult [symmetric] mult_assoc)
   429 apply (auto simp add: abs_mult [symmetric] mult_assoc)
   426 done
   430 done
   427 
   431 
   428 lemma powser_inside: "[| summable (%n. f(n) * (x ^ n)); \<bar>z\<bar> < \<bar>x\<bar> |]  
   432 lemma powser_inside:
       
   433      "[| summable (%n. f(n) * (x ^ n)); \<bar>z\<bar> < \<bar>x\<bar> |]  
   429       ==> summable (%n. f(n) * (z ^ n))"
   434       ==> summable (%n. f(n) * (z ^ n))"
   430 apply (drule_tac z = "\<bar>z\<bar>" in powser_insidea)
   435 apply (drule_tac z = "\<bar>z\<bar>" in powser_insidea)
   431 apply (auto intro: summable_rabs_cancel simp add: power_abs [symmetric])
   436 apply (auto intro: summable_rabs_cancel simp add: power_abs [symmetric])
   432 done
   437 done
   433 
   438 
   445       (real n * c(n) * x ^ (n - Suc 0))"
   450       (real n * c(n) * x ^ (n - Suc 0))"
   446 apply (induct_tac "n")
   451 apply (induct_tac "n")
   447 apply (auto simp add: mult_assoc add_assoc [symmetric] diffs_def)
   452 apply (auto simp add: mult_assoc add_assoc [symmetric] diffs_def)
   448 done
   453 done
   449 
   454 
   450 lemma lemma_diffs2: "sumr 0 n (%n. real n * c(n) * (x ^ (n - Suc 0))) =  
   455 lemma lemma_diffs2:
       
   456      "sumr 0 n (%n. real n * c(n) * (x ^ (n - Suc 0))) =  
   451       sumr 0 n (%n. (diffs c)(n) * (x ^ n)) -  
   457       sumr 0 n (%n. (diffs c)(n) * (x ^ n)) -  
   452       (real n * c(n) * x ^ (n - Suc 0))"
   458       (real n * c(n) * x ^ (n - Suc 0))"
   453 by (auto simp add: lemma_diffs)
   459 by (auto simp add: lemma_diffs)
   454 
   460 
   455 
   461 
   456 lemma diffs_equiv: "summable (%n. (diffs c)(n) * (x ^ n)) ==>  
   462 lemma diffs_equiv:
       
   463      "summable (%n. (diffs c)(n) * (x ^ n)) ==>  
   457       (%n. real n * c(n) * (x ^ (n - Suc 0))) sums  
   464       (%n. real n * c(n) * (x ^ (n - Suc 0))) sums  
   458          (suminf(%n. (diffs c)(n) * (x ^ n)))"
   465          (suminf(%n. (diffs c)(n) * (x ^ n)))"
   459 apply (subgoal_tac " (%n. real n * c (n) * (x ^ (n - Suc 0))) ----> 0")
   466 apply (subgoal_tac " (%n. real n * c (n) * (x ^ (n - Suc 0))) ----> 0")
   460 apply (rule_tac [2] LIMSEQ_imp_Suc)
   467 apply (rule_tac [2] LIMSEQ_imp_Suc)
   461 apply (drule summable_sums) 
   468 apply (drule summable_sums) 
   471 lemma lemma_termdiff1:
   478 lemma lemma_termdiff1:
   472      "sumr 0 m (%p. (((z + h) ^ (m - p)) * (z ^ p)) - (z ^ m)) =  
   479      "sumr 0 m (%p. (((z + h) ^ (m - p)) * (z ^ p)) - (z ^ m)) =  
   473         sumr 0 m (%p. (z ^ p) *  
   480         sumr 0 m (%p. (z ^ p) *  
   474         (((z + h) ^ (m - p)) - (z ^ (m - p))))"
   481         (((z + h) ^ (m - p)) - (z ^ (m - p))))"
   475 apply (rule sumr_subst)
   482 apply (rule sumr_subst)
   476 apply (auto simp add: right_distrib real_diff_def power_add [symmetric] mult_ac)
   483 apply (auto simp add: right_distrib diff_minus power_add [symmetric] mult_ac)
   477 done
   484 done
   478 
   485 
   479 lemma less_add_one: "m < n ==> (\<exists>d. n = m + d + Suc 0)"
   486 lemma less_add_one: "m < n ==> (\<exists>d. n = m + d + Suc 0)"
   480 by (simp add: less_iff_Suc_add)
   487 by (simp add: less_iff_Suc_add)
   481 
   488 
   482 lemma sumdiff: "a + b - (c + d) = a - c + b - (d::real)"
   489 lemma sumdiff: "a + b - (c + d) = a - c + b - (d::real)"
   483 by arith
   490 by arith
   484 
   491 
   485 
   492 
   486 lemma lemma_termdiff2: " h \<noteq> 0 ==>  
   493 lemma lemma_termdiff2:
       
   494      " h \<noteq> 0 ==>  
   487         (((z + h) ^ n) - (z ^ n)) * inverse h -  
   495         (((z + h) ^ n) - (z ^ n)) * inverse h -  
   488             real n * (z ^ (n - Suc 0)) =  
   496             real n * (z ^ (n - Suc 0)) =  
   489          h * sumr 0 (n - Suc 0) (%p. (z ^ p) *  
   497          h * sumr 0 (n - Suc 0) (%p. (z ^ p) *  
   490                sumr 0 ((n - Suc 0) - p)  
   498                sumr 0 ((n - Suc 0) - p)  
   491                  (%q. ((z + h) ^ q) * (z ^ (((n - 2) - p) - q))))"
   499                  (%q. ((z + h) ^ q) * (z ^ (((n - 2) - p) - q))))"
   497                       right_diff_distrib [symmetric] mult_assoc
   505                       right_diff_distrib [symmetric] mult_assoc
   498             simp del: realpow_Suc sumr_Suc)
   506             simp del: realpow_Suc sumr_Suc)
   499 apply (auto simp add: lemma_realpow_rev_sumr simp del: sumr_Suc)
   507 apply (auto simp add: lemma_realpow_rev_sumr simp del: sumr_Suc)
   500 apply (auto simp add: real_of_nat_Suc sumr_diff_mult_const left_distrib 
   508 apply (auto simp add: real_of_nat_Suc sumr_diff_mult_const left_distrib 
   501                 sumdiff lemma_termdiff1 sumr_mult)
   509                 sumdiff lemma_termdiff1 sumr_mult)
   502 apply (auto intro!: sumr_subst simp add: real_diff_def real_add_assoc)
   510 apply (auto intro!: sumr_subst simp add: diff_minus real_add_assoc)
   503 apply (simp add: diff_minus [symmetric] less_iff_Suc_add) 
   511 apply (simp add: diff_minus [symmetric] less_iff_Suc_add) 
   504 apply (auto simp add: sumr_mult lemma_realpow_diff_sumr2 mult_ac simp
   512 apply (auto simp add: sumr_mult lemma_realpow_diff_sumr2 mult_ac simp
   505                  del: sumr_Suc realpow_Suc)
   513                  del: sumr_Suc realpow_Suc)
   506 done
   514 done
   507 
   515 
   508 lemma lemma_termdiff3: "[| h \<noteq> 0; \<bar>z\<bar> \<le> K; \<bar>z + h\<bar> \<le> K |]  
   516 lemma lemma_termdiff3:
       
   517      "[| h \<noteq> 0; \<bar>z\<bar> \<le> K; \<bar>z + h\<bar> \<le> K |]  
   509       ==> abs (((z + h) ^ n - z ^ n) * inverse h - real n * z ^ (n - Suc 0))  
   518       ==> abs (((z + h) ^ n - z ^ n) * inverse h - real n * z ^ (n - Suc 0))  
   510           \<le> real n * real (n - Suc 0) * K ^ (n - 2) * \<bar>h\<bar>"
   519           \<le> real n * real (n - Suc 0) * K ^ (n - 2) * \<bar>h\<bar>"
   511 apply (subst lemma_termdiff2, assumption)
   520 apply (subst lemma_termdiff2, assumption)
   512 apply (simp add: abs_mult mult_commute) 
   521 apply (simp add: abs_mult mult_commute) 
   513 apply (simp add: mult_commute [of _ "K ^ (n - 2)"]) 
   522 apply (simp add: mult_commute [of _ "K ^ (n - 2)"]) 
   522 apply (subgoal_tac "K ^ p * K ^ d * real (Suc (Suc (p + d))) =
   531 apply (subgoal_tac "K ^ p * K ^ d * real (Suc (Suc (p + d))) =
   523                     K ^ p * (real (Suc (Suc (p + d))) * K ^ d)") 
   532                     K ^ p * (real (Suc (Suc (p + d))) * K ^ d)") 
   524 apply (simp (no_asm_simp) add: power_add del: sumr_Suc)
   533 apply (simp (no_asm_simp) add: power_add del: sumr_Suc)
   525 apply (auto intro!: mult_mono simp del: sumr_Suc)
   534 apply (auto intro!: mult_mono simp del: sumr_Suc)
   526 apply (auto intro!: power_mono simp add: power_abs simp del: sumr_Suc)
   535 apply (auto intro!: power_mono simp add: power_abs simp del: sumr_Suc)
   527 apply (rule_tac j = "real (Suc d) * (K ^ d) " in real_le_trans)
   536 apply (rule_tac j = "real (Suc d) * (K ^ d)" in real_le_trans)
   528 apply (subgoal_tac [2] "0 \<le> K")
   537 apply (subgoal_tac [2] "0 \<le> K")
   529 apply (drule_tac [2] n = d in zero_le_power)
   538 apply (drule_tac [2] n = d in zero_le_power)
   530 apply (auto simp del: sumr_Suc)
   539 apply (auto simp del: sumr_Suc)
   531 apply (rule sumr_rabs [THEN real_le_trans])
   540 apply (rule sumr_rabs [THEN real_le_trans])
   532 apply (rule sumr_bound2, auto dest!: less_add_one intro!: mult_mono simp add: abs_mult power_add)
   541 apply (rule sumr_bound2, auto dest!: less_add_one intro!: mult_mono simp add: abs_mult power_add)
   535 
   544 
   536 lemma lemma_termdiff4: 
   545 lemma lemma_termdiff4: 
   537   "[| 0 < k;  
   546   "[| 0 < k;  
   538       (\<forall>h. 0 < \<bar>h\<bar> & \<bar>h\<bar> < k --> \<bar>f h\<bar> \<le> K * \<bar>h\<bar>) |]  
   547       (\<forall>h. 0 < \<bar>h\<bar> & \<bar>h\<bar> < k --> \<bar>f h\<bar> \<le> K * \<bar>h\<bar>) |]  
   539    ==> f -- 0 --> 0"
   548    ==> f -- 0 --> 0"
   540 apply (unfold LIM_def, auto)
   549 apply (simp add: LIM_def, auto)
   541 apply (subgoal_tac "0 \<le> K")
   550 apply (subgoal_tac "0 \<le> K")
   542 apply (drule_tac [2] x = "k/2" in spec)
   551  prefer 2
   543 apply (frule_tac [2] real_less_half_sum)
   552  apply (drule_tac x = "k/2" in spec)
   544 apply (drule_tac [2] real_gt_half_sum)
   553 apply (simp add: ); 
   545 apply (auto simp add: abs_eqI2)
   554  apply (subgoal_tac "0 \<le> K*k", simp add: zero_le_mult_iff) 
   546 apply (rule_tac [2] c = "k/2" in mult_right_le_imp_le)
   555  apply (force intro: order_trans [of _ "\<bar>f (k / 2)\<bar> * 2"]) 
   547 apply (auto intro: abs_ge_zero [THEN real_le_trans])
       
   548 apply (drule real_le_imp_less_or_eq, auto)
   556 apply (drule real_le_imp_less_or_eq, auto)
   549 apply (subgoal_tac "0 < (r * inverse K) * inverse 2")
   557 apply (subgoal_tac "0 < (r * inverse K) / 2")
   550 apply (rule_tac [2] real_mult_order)+
   558 apply (drule_tac ?d1.0 = "(r * inverse K) / 2" and ?d2.0 = k in real_lbound_gt_zero)
   551 apply (drule_tac ?d1.0 = "r * inverse K * inverse 2" and ?d2.0 = k in real_lbound_gt_zero)
   559 apply (auto simp add: positive_imp_inverse_positive zero_less_mult_iff zero_less_divide_iff)
   552 apply (auto simp add: positive_imp_inverse_positive zero_less_mult_iff)
       
   553 apply (rule_tac [2] y="\<bar>f (k / 2)\<bar> * 2" in order_trans, auto)
       
   554 apply (rule_tac x = e in exI, auto)
   560 apply (rule_tac x = e in exI, auto)
   555 apply (rule_tac y = "K * \<bar>x\<bar>" in order_le_less_trans)
   561 apply (rule_tac y = "K * \<bar>x\<bar>" in order_le_less_trans)
   556 apply (rule_tac [2] y = "K * e" in order_less_trans)
   562 apply (force ); 
   557 apply (rule_tac [3] c = "inverse K" in mult_right_less_imp_less, force)
   563 apply (rule_tac y = "K * e" in order_less_trans)
   558 apply (simp add: mult_less_cancel_left)
   564 apply (simp add: mult_less_cancel_left)
       
   565 apply (rule_tac c = "inverse K" in mult_right_less_imp_less)
   559 apply (auto simp add: mult_ac)
   566 apply (auto simp add: mult_ac)
   560 done
   567 done
   561 
   568 
   562 lemma lemma_termdiff5: "[| 0 < k;  
   569 lemma lemma_termdiff5:
       
   570      "[| 0 < k;  
   563             summable f;  
   571             summable f;  
   564             \<forall>h. 0 < \<bar>h\<bar> & \<bar>h\<bar> < k -->  
   572             \<forall>h. 0 < \<bar>h\<bar> & \<bar>h\<bar> < k -->  
   565                     (\<forall>n. abs(g(h) (n::nat)) \<le> (f(n) * \<bar>h\<bar>)) |]  
   573                     (\<forall>n. abs(g(h) (n::nat)) \<le> (f(n) * \<bar>h\<bar>)) |]  
   566          ==> (%h. suminf(g h)) -- 0 --> 0"
   574          ==> (%h. suminf(g h)) -- 0 --> 0"
   567 apply (drule summable_sums)
   575 apply (drule summable_sums)
   600        in lemma_termdiff5)
   608        in lemma_termdiff5)
   601 apply (auto simp add: add_commute)
   609 apply (auto simp add: add_commute)
   602 apply (subgoal_tac "summable (%n. \<bar>diffs (diffs c) n\<bar> * (r ^ n))")
   610 apply (subgoal_tac "summable (%n. \<bar>diffs (diffs c) n\<bar> * (r ^ n))")
   603 apply (rule_tac [2] x = K in powser_insidea, auto)
   611 apply (rule_tac [2] x = K in powser_insidea, auto)
   604 apply (subgoal_tac [2] "\<bar>r\<bar> = r", auto)
   612 apply (subgoal_tac [2] "\<bar>r\<bar> = r", auto)
   605 apply (rule_tac [2] y1 = "\<bar>x\<bar>" in order_trans [THEN abs_eqI1], auto)
   613 apply (rule_tac [2] y1 = "\<bar>x\<bar>" in order_trans [THEN abs_eq], auto)
   606 apply (simp add: diffs_def mult_assoc [symmetric])
   614 apply (simp add: diffs_def mult_assoc [symmetric])
   607 apply (subgoal_tac
   615 apply (subgoal_tac
   608         "\<forall>n. real (Suc n) * real (Suc (Suc n)) * \<bar>c (Suc (Suc n))\<bar> * (r ^ n) 
   616         "\<forall>n. real (Suc n) * real (Suc (Suc n)) * \<bar>c (Suc (Suc n))\<bar> * (r ^ n) 
   609               = diffs (diffs (%n. \<bar>c n\<bar>)) n * (r ^ n) ") 
   617               = diffs (diffs (%n. \<bar>c n\<bar>)) n * (r ^ n) ") 
   610 apply auto
   618 apply auto
   638 apply (case_tac "nat", auto)
   646 apply (case_tac "nat", auto)
   639 apply (drule abs_ge_zero [THEN order_le_less_trans], auto) 
   647 apply (drule abs_ge_zero [THEN order_le_less_trans], auto) 
   640 apply (drule abs_ge_zero [THEN order_le_less_trans])
   648 apply (drule abs_ge_zero [THEN order_le_less_trans])
   641 apply (simp add: mult_assoc)
   649 apply (simp add: mult_assoc)
   642 apply (rule mult_left_mono)
   650 apply (rule mult_left_mono)
   643 apply (rule add_commute [THEN subst])
   651  prefer 2 apply arith 
       
   652 apply (subst add_commute)
   644 apply (simp (no_asm) add: mult_assoc [symmetric])
   653 apply (simp (no_asm) add: mult_assoc [symmetric])
   645 apply (rule lemma_termdiff3)
   654 apply (rule lemma_termdiff3)
   646 apply (auto intro: abs_triangle_ineq [THEN order_trans], arith)
   655 apply (auto intro: abs_triangle_ineq [THEN order_trans], arith)
   647 done
   656 done
   648 
   657 
   652         summable(%n. (diffs c)(n) * (K ^ n));  
   661         summable(%n. (diffs c)(n) * (K ^ n));  
   653         summable(%n. (diffs(diffs c))(n) * (K ^ n));  
   662         summable(%n. (diffs(diffs c))(n) * (K ^ n));  
   654         \<bar>x\<bar> < \<bar>K\<bar> |]  
   663         \<bar>x\<bar> < \<bar>K\<bar> |]  
   655      ==> DERIV (%x. suminf (%n. c(n) * (x ^ n)))  x :>  
   664      ==> DERIV (%x. suminf (%n. c(n) * (x ^ n)))  x :>  
   656              suminf (%n. (diffs c)(n) * (x ^ n))"
   665              suminf (%n. (diffs c)(n) * (x ^ n))"
   657 apply (unfold deriv_def)
   666 apply (simp add: deriv_def)
   658 apply (rule_tac g = "%h. suminf (%n. ((c (n) * ( (x + h) ^ n)) - (c (n) * (x ^ n))) * inverse h) " in LIM_trans)
   667 apply (rule_tac g = "%h. suminf (%n. ((c (n) * ( (x + h) ^ n)) - (c (n) * (x ^ n))) * inverse h)" in LIM_trans)
   659 apply (simp add: LIM_def, safe)
   668 apply (simp add: LIM_def, safe)
   660 apply (rule_tac x = "\<bar>K\<bar> - \<bar>x\<bar>" in exI)
   669 apply (rule_tac x = "\<bar>K\<bar> - \<bar>x\<bar>" in exI)
   661 apply (auto simp add: less_diff_eq)
   670 apply (auto simp add: less_diff_eq)
   662 apply (drule abs_triangle_ineq [THEN order_le_less_trans])
   671 apply (drule abs_triangle_ineq [THEN order_le_less_trans])
   663 apply (rule_tac y = 0 in order_le_less_trans, auto)
   672 apply (rule_tac y = 0 in order_le_less_trans, auto)
   664 apply (subgoal_tac " (%n. (c n) * (x ^ n)) sums (suminf (%n. (c n) * (x ^ n))) & (%n. (c n) * ((x + xa) ^ n)) sums (suminf (%n. (c n) * ( (x + xa) ^ n))) ")
   673 apply (subgoal_tac " (%n. (c n) * (x ^ n)) sums (suminf (%n. (c n) * (x ^ n))) & (%n. (c n) * ((x + xa) ^ n)) sums (suminf (%n. (c n) * ( (x + xa) ^ n))) ")
   665 apply (auto intro!: summable_sums)
   674 apply (auto intro!: summable_sums)
   666 apply (rule_tac [2] powser_inside, rule_tac [4] powser_inside)
   675 apply (rule_tac [2] powser_inside, rule_tac [4] powser_inside)
   667 apply (auto simp add: add_commute)
   676 apply (auto simp add: add_commute)
   668 apply (drule_tac x="(\<lambda>n. c n * (xa + x) ^ n)" in sums_diff, assumption) 
   677 apply (drule_tac x="(\<lambda>n. c n * (xa + x) ^ n)" in sums_diff, assumption) 
   669 apply (drule_tac x = " (%n. c n * (xa + x) ^ n - c n * x ^ n) " and c = "inverse xa" in sums_mult)
   678 apply (drule_tac x = "(%n. c n * (xa + x) ^ n - c n * x ^ n) " and c = "inverse xa" in sums_mult)
   670 apply (rule sums_unique)
   679 apply (rule sums_unique)
   671 apply (simp add: diff_def divide_inverse add_ac mult_ac)
   680 apply (simp add: diff_def divide_inverse add_ac mult_ac)
   672 apply (rule LIM_zero_cancel)
   681 apply (rule LIM_zero_cancel)
   673 apply (rule_tac g = "%h. suminf (%n. c (n) * ((( ((x + h) ^ n) - (x ^ n)) * inverse h) - (real n * (x ^ (n - Suc 0))))) " in LIM_trans)
   682 apply (rule_tac g = "%h. suminf (%n. c (n) * ((( ((x + h) ^ n) - (x ^ n)) * inverse h) - (real n * (x ^ (n - Suc 0)))))" in LIM_trans)
   674  prefer 2 apply (blast intro: termdiffs_aux) 
   683  prefer 2 apply (blast intro: termdiffs_aux) 
   675 apply (simp add: LIM_def, safe)
   684 apply (simp add: LIM_def, safe)
   676 apply (rule_tac x = "\<bar>K\<bar> - \<bar>x\<bar>" in exI)
   685 apply (rule_tac x = "\<bar>K\<bar> - \<bar>x\<bar>" in exI)
   677 apply (auto simp add: less_diff_eq)
   686 apply (auto simp add: less_diff_eq)
   678 apply (drule abs_triangle_ineq [THEN order_le_less_trans])
   687 apply (drule abs_triangle_ineq [THEN order_le_less_trans])
   684 apply (subgoal_tac " (%n. (c n) * (x ^ n)) sums (suminf (%n. (c n) * (x ^ n))) & (%n. (c n) * ((x + xa) ^ n)) sums (suminf (%n. (c n) * ( (x + xa) ^ n))) ")
   693 apply (subgoal_tac " (%n. (c n) * (x ^ n)) sums (suminf (%n. (c n) * (x ^ n))) & (%n. (c n) * ((x + xa) ^ n)) sums (suminf (%n. (c n) * ( (x + xa) ^ n))) ")
   685 apply safe
   694 apply safe
   686 apply (auto intro!: summable_sums)
   695 apply (auto intro!: summable_sums)
   687 apply (rule_tac [2] powser_inside, rule_tac [4] powser_inside)
   696 apply (rule_tac [2] powser_inside, rule_tac [4] powser_inside)
   688 apply (auto simp add: add_commute)
   697 apply (auto simp add: add_commute)
   689 apply (frule_tac x = " (%n. c n * (xa + x) ^ n) " and y = " (%n. c n * x ^ n) " in sums_diff, assumption)
   698 apply (frule_tac x = "(%n. c n * (xa + x) ^ n) " and y = "(%n. c n * x ^ n)" in sums_diff, assumption)
   690 apply (simp add: suminf_diff [OF sums_summable sums_summable] 
   699 apply (simp add: suminf_diff [OF sums_summable sums_summable] 
   691                right_diff_distrib [symmetric])
   700                right_diff_distrib [symmetric])
   692 apply (frule_tac x = " (%n. c n * ((xa + x) ^ n - x ^ n))" and c = "inverse xa" in sums_mult)
   701 apply (frule_tac x = "(%n. c n * ((xa + x) ^ n - x ^ n))" and c = "inverse xa" in sums_mult)
   693 apply (simp add: sums_summable [THEN suminf_mult2])
   702 apply (simp add: sums_summable [THEN suminf_mult2])
   694 apply (frule_tac x = " (%n. inverse xa * (c n * ((xa + x) ^ n - x ^ n))) " and y = " (%n. real n * c n * x ^ (n - Suc 0))" in sums_diff)
   703 apply (frule_tac x = "(%n. inverse xa * (c n * ((xa + x) ^ n - x ^ n))) " and y = "(%n. real n * c n * x ^ (n - Suc 0))" in sums_diff)
   695 apply assumption
   704 apply assumption
   696 apply (simp add: suminf_diff [OF sums_summable sums_summable] add_ac mult_ac)
   705 apply (simp add: suminf_diff [OF sums_summable sums_summable] add_ac mult_ac)
   697 apply (rule_tac f = suminf in arg_cong)
   706 apply (rule_tac f = suminf in arg_cong)
   698 apply (rule ext)
   707 apply (rule ext)
   699 apply (simp add: diff_def right_distrib add_ac mult_ac)
   708 apply (simp add: diff_def right_distrib add_ac mult_ac)
   702 
   711 
   703 subsection{*Formal Derivatives of Exp, Sin, and Cos Series*} 
   712 subsection{*Formal Derivatives of Exp, Sin, and Cos Series*} 
   704 
   713 
   705 lemma exp_fdiffs: 
   714 lemma exp_fdiffs: 
   706       "diffs (%n. inverse(real (fact n))) = (%n. inverse(real (fact n)))"
   715       "diffs (%n. inverse(real (fact n))) = (%n. inverse(real (fact n)))"
   707 apply (unfold diffs_def)
   716 by (simp add: diffs_def mult_assoc [symmetric] del: mult_Suc)
   708 apply (rule ext)
       
   709 apply (subst fact_Suc)
       
   710 apply (subst real_of_nat_mult)
       
   711 apply (subst inverse_mult_distrib)
       
   712 apply (auto simp add: mult_assoc [symmetric])
       
   713 done
       
   714 
   717 
   715 lemma sin_fdiffs: 
   718 lemma sin_fdiffs: 
   716       "diffs(%n. if even n then 0  
   719       "diffs(%n. if even n then 0  
   717            else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n)))  
   720            else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n)))  
   718        = (%n. if even n then  
   721        = (%n. if even n then  
   719                  (- 1) ^ (n div 2)/(real (fact n))  
   722                  (- 1) ^ (n div 2)/(real (fact n))  
   720               else 0)"
   723               else 0)"
   721 apply (unfold diffs_def real_divide_def)
   724 by (auto intro!: ext 
   722 apply (rule ext)
   725          simp add: diffs_def divide_inverse simp del: mult_Suc)
   723 apply (subst fact_Suc)
       
   724 apply (subst real_of_nat_mult)
       
   725 apply (subst even_nat_Suc)
       
   726 apply (subst inverse_mult_distrib, auto)
       
   727 done
       
   728 
   726 
   729 lemma sin_fdiffs2: 
   727 lemma sin_fdiffs2: 
   730        "diffs(%n. if even n then 0  
   728        "diffs(%n. if even n then 0  
   731            else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) n  
   729            else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) n  
   732        = (if even n then  
   730        = (if even n then  
   733                  (- 1) ^ (n div 2)/(real (fact n))  
   731                  (- 1) ^ (n div 2)/(real (fact n))  
   734               else 0)"
   732               else 0)"
   735 apply (unfold diffs_def real_divide_def)
   733 by (auto intro!: ext 
   736 apply (subst fact_Suc)
   734          simp add: diffs_def divide_inverse simp del: mult_Suc)
   737 apply (subst real_of_nat_mult)
       
   738 apply (subst even_nat_Suc)
       
   739 apply (subst inverse_mult_distrib, auto)
       
   740 done
       
   741 
   735 
   742 lemma cos_fdiffs: 
   736 lemma cos_fdiffs: 
   743       "diffs(%n. if even n then  
   737       "diffs(%n. if even n then  
   744                  (- 1) ^ (n div 2)/(real (fact n)) else 0)  
   738                  (- 1) ^ (n div 2)/(real (fact n)) else 0)  
   745        = (%n. - (if even n then 0  
   739        = (%n. - (if even n then 0  
   746            else (- 1) ^ ((n - Suc 0)div 2)/(real (fact n))))"
   740            else (- 1) ^ ((n - Suc 0)div 2)/(real (fact n))))"
   747 apply (unfold diffs_def real_divide_def)
   741 by (auto intro!: ext 
   748 apply (rule ext)
   742          simp add: diffs_def divide_inverse odd_Suc_mult_two_ex
   749 apply (subst fact_Suc)
   743          simp del: mult_Suc)
   750 apply (subst real_of_nat_mult)
       
   751 apply (auto simp add: mult_assoc odd_Suc_mult_two_ex)
       
   752 done
       
   753 
   744 
   754 
   745 
   755 lemma cos_fdiffs2: 
   746 lemma cos_fdiffs2: 
   756       "diffs(%n. if even n then  
   747       "diffs(%n. if even n then  
   757                  (- 1) ^ (n div 2)/(real (fact n)) else 0) n 
   748                  (- 1) ^ (n div 2)/(real (fact n)) else 0) n 
   758        = - (if even n then 0  
   749        = - (if even n then 0  
   759            else (- 1) ^ ((n - Suc 0)div 2)/(real (fact n)))"
   750            else (- 1) ^ ((n - Suc 0)div 2)/(real (fact n)))"
   760 apply (unfold diffs_def real_divide_def)
   751 by (auto intro!: ext 
   761 apply (subst fact_Suc)
   752          simp add: diffs_def divide_inverse odd_Suc_mult_two_ex
   762 apply (subst real_of_nat_mult) 
   753          simp del: mult_Suc)
   763 apply (auto simp add: mult_assoc odd_Suc_mult_two_ex)
       
   764 done
       
   765 
   754 
   766 text{*Now at last we can get the derivatives of exp, sin and cos*}
   755 text{*Now at last we can get the derivatives of exp, sin and cos*}
   767 
   756 
   768 lemma lemma_sin_minus:
   757 lemma lemma_sin_minus:
   769      "- sin x =
   758      "- sin x =
   773 
   762 
   774 lemma lemma_exp_ext: "exp = (%x. suminf (%n. inverse (real (fact n)) * x ^ n))"
   763 lemma lemma_exp_ext: "exp = (%x. suminf (%n. inverse (real (fact n)) * x ^ n))"
   775 by (auto intro!: ext simp add: exp_def)
   764 by (auto intro!: ext simp add: exp_def)
   776 
   765 
   777 lemma DERIV_exp [simp]: "DERIV exp x :> exp(x)"
   766 lemma DERIV_exp [simp]: "DERIV exp x :> exp(x)"
   778 apply (unfold exp_def)
   767 apply (simp add: exp_def)
   779 apply (subst lemma_exp_ext)
   768 apply (subst lemma_exp_ext)
   780 apply (subgoal_tac "DERIV (%u. suminf (%n. inverse (real (fact n)) * u ^ n)) x :> suminf (%n. diffs (%n. inverse (real (fact n))) n * x ^ n) ")
   769 apply (subgoal_tac "DERIV (%u. suminf (%n. inverse (real (fact n)) * u ^ n)) x :> suminf (%n. diffs (%n. inverse (real (fact n))) n * x ^ n) ")
   781 apply (rule_tac [2] K = "1 + \<bar>x\<bar> " in termdiffs)
   770 apply (rule_tac [2] K = "1 + \<bar>x\<bar>" in termdiffs)
   782 apply (auto intro: exp_converges [THEN sums_summable] simp add: exp_fdiffs, arith)
   771 apply (auto intro: exp_converges [THEN sums_summable] simp add: exp_fdiffs, arith)
   783 done
   772 done
   784 
   773 
   785 lemma lemma_sin_ext:
   774 lemma lemma_sin_ext:
   786      "sin = (%x. suminf(%n. 
   775      "sin = (%x. suminf(%n. 
   794                    (if even n then (- 1) ^ (n div 2)/(real (fact n)) else 0) *
   783                    (if even n then (- 1) ^ (n div 2)/(real (fact n)) else 0) *
   795                    x ^ n))"
   784                    x ^ n))"
   796 by (auto intro!: ext simp add: cos_def)
   785 by (auto intro!: ext simp add: cos_def)
   797 
   786 
   798 lemma DERIV_sin [simp]: "DERIV sin x :> cos(x)"
   787 lemma DERIV_sin [simp]: "DERIV sin x :> cos(x)"
   799 apply (unfold cos_def)
   788 apply (simp add: cos_def)
   800 apply (subst lemma_sin_ext)
   789 apply (subst lemma_sin_ext)
   801 apply (auto simp add: sin_fdiffs2 [symmetric])
   790 apply (auto simp add: sin_fdiffs2 [symmetric])
   802 apply (rule_tac K = "1 + \<bar>x\<bar> " in termdiffs)
   791 apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs)
   803 apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs, arith)
   792 apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs, arith)
   804 done
   793 done
   805 
   794 
   806 lemma DERIV_cos [simp]: "DERIV cos x :> -sin(x)"
   795 lemma DERIV_cos [simp]: "DERIV cos x :> -sin(x)"
   807 apply (subst lemma_cos_ext)
   796 apply (subst lemma_cos_ext)
   808 apply (auto simp add: lemma_sin_minus cos_fdiffs2 [symmetric] minus_mult_left)
   797 apply (auto simp add: lemma_sin_minus cos_fdiffs2 [symmetric] minus_mult_left)
   809 apply (rule_tac K = "1 + \<bar>x\<bar> " in termdiffs)
   798 apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs)
   810 apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs diffs_minus, arith)
   799 apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs diffs_minus, arith)
   811 done
   800 done
   812 
   801 
   813 
   802 
   814 subsection{*Properties of the Exponential Function*}
   803 subsection{*Properties of the Exponential Function*}
   822   thus ?thesis by (simp add:  exp_def) 
   811   thus ?thesis by (simp add:  exp_def) 
   823 qed
   812 qed
   824 
   813 
   825 lemma exp_ge_add_one_self [simp]: "0 \<le> x ==> (1 + x) \<le> exp(x)"
   814 lemma exp_ge_add_one_self [simp]: "0 \<le> x ==> (1 + x) \<le> exp(x)"
   826 apply (drule real_le_imp_less_or_eq, auto)
   815 apply (drule real_le_imp_less_or_eq, auto)
   827 apply (unfold exp_def)
   816 apply (simp add: exp_def)
   828 apply (rule real_le_trans)
   817 apply (rule real_le_trans)
   829 apply (rule_tac [2] n = 2 and f = " (%n. inverse (real (fact n)) * x ^ n) " in series_pos_le)
   818 apply (rule_tac [2] n = 2 and f = "(%n. inverse (real (fact n)) * x ^ n)" in series_pos_le)
   830 apply (auto intro: summable_exp simp add: numeral_2_eq_2 zero_le_power zero_le_mult_iff)
   819 apply (auto intro: summable_exp simp add: numeral_2_eq_2 zero_le_power zero_le_mult_iff)
   831 done
   820 done
   832 
   821 
   833 lemma exp_gt_one [simp]: "0 < x ==> 1 < exp x"
   822 lemma exp_gt_one [simp]: "0 < x ==> 1 < exp x"
   834 apply (rule order_less_le_trans)
   823 apply (rule order_less_le_trans)
   900 
   889 
   901 lemma inv_exp_gt_zero [simp]: "0 < inverse(exp x)"
   890 lemma inv_exp_gt_zero [simp]: "0 < inverse(exp x)"
   902 by (auto intro: positive_imp_inverse_positive)
   891 by (auto intro: positive_imp_inverse_positive)
   903 
   892 
   904 lemma abs_exp_cancel [simp]: "\<bar>exp x\<bar> = exp x"
   893 lemma abs_exp_cancel [simp]: "\<bar>exp x\<bar> = exp x"
   905 by (auto simp add: abs_eqI2)
   894 by auto
   906 
   895 
   907 lemma exp_real_of_nat_mult: "exp(real n * x) = exp(x) ^ n"
   896 lemma exp_real_of_nat_mult: "exp(real n * x) = exp(x) ^ n"
   908 apply (induct_tac "n")
   897 apply (induct_tac "n")
   909 apply (auto simp add: real_of_nat_Suc right_distrib exp_add mult_commute)
   898 apply (auto simp add: real_of_nat_Suc right_distrib exp_add mult_commute)
   910 done
   899 done
   911 
   900 
   912 lemma exp_diff: "exp(x - y) = exp(x)/(exp y)"
   901 lemma exp_diff: "exp(x - y) = exp(x)/(exp y)"
   913 apply (unfold real_diff_def real_divide_def)
   902 apply (simp add: diff_minus divide_inverse)
   914 apply (simp (no_asm) add: exp_add exp_minus)
   903 apply (simp (no_asm) add: exp_add exp_minus)
   915 done
   904 done
   916 
   905 
   917 
   906 
   918 lemma exp_less_mono:
   907 lemma exp_less_mono:
   990 apply (auto simp add: positive_imp_inverse_positive ln_mult [symmetric])
   979 apply (auto simp add: positive_imp_inverse_positive ln_mult [symmetric])
   991 done
   980 done
   992 
   981 
   993 lemma ln_div: 
   982 lemma ln_div: 
   994     "[|0 < x; 0 < y|] ==> ln(x/y) = ln x - ln y"
   983     "[|0 < x; 0 < y|] ==> ln(x/y) = ln x - ln y"
   995 apply (unfold real_divide_def)
   984 apply (simp add: divide_inverse)
   996 apply (auto simp add: positive_imp_inverse_positive ln_mult ln_inverse)
   985 apply (auto simp add: positive_imp_inverse_positive ln_mult ln_inverse)
   997 done
   986 done
   998 
   987 
   999 lemma ln_less_cancel_iff[simp]: "[| 0 < x; 0 < y|] ==> (ln x < ln y) = (x < y)"
   988 lemma ln_less_cancel_iff[simp]: "[| 0 < x; 0 < y|] ==> (ln x < ln y) = (x < y)"
  1000 apply (simp only: exp_ln_iff [symmetric])
   989 apply (simp only: exp_ln_iff [symmetric])
  1084 
  1073 
  1085 lemma lemma_series_zero2: "(\<forall>m. n \<le> m --> f m = 0) --> f sums sumr 0 n f"
  1074 lemma lemma_series_zero2: "(\<forall>m. n \<le> m --> f m = 0) --> f sums sumr 0 n f"
  1086 by (auto intro: series_zero)
  1075 by (auto intro: series_zero)
  1087 
  1076 
  1088 lemma cos_zero [simp]: "cos 0 = 1"
  1077 lemma cos_zero [simp]: "cos 0 = 1"
  1089 apply (unfold cos_def)
  1078 apply (simp add: cos_def)
  1090 apply (rule sums_unique [symmetric])
  1079 apply (rule sums_unique [symmetric])
  1091 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)
  1080 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)
  1092 apply auto
  1081 apply auto
  1093 done
  1082 done
  1094 
  1083 
  1095 lemma DERIV_sin_sin_mult [simp]:
  1084 lemma DERIV_sin_sin_mult [simp]:
  1096      "DERIV (%x. sin(x)*sin(x)) x :> cos(x) * sin(x) + cos(x) * sin(x)"
  1085      "DERIV (%x. sin(x)*sin(x)) x :> cos(x) * sin(x) + cos(x) * sin(x)"
  1135 apply (rule lemma_DERIV_subst)
  1124 apply (rule lemma_DERIV_subst)
  1136 apply (rule DERIV_cos_realpow2a, auto)
  1125 apply (rule DERIV_cos_realpow2a, auto)
  1137 done
  1126 done
  1138 
  1127 
  1139 (* most useful *)
  1128 (* most useful *)
  1140 lemma DERIV_cos_cos_mult3 [simp]: "DERIV (%x. cos(x)*cos(x)) x :> -(2 * cos(x) * sin(x))"
  1129 lemma DERIV_cos_cos_mult3 [simp]:
       
  1130      "DERIV (%x. cos(x)*cos(x)) x :> -(2 * cos(x) * sin(x))"
  1141 apply (rule lemma_DERIV_subst)
  1131 apply (rule lemma_DERIV_subst)
  1142 apply (rule DERIV_cos_cos_mult2, auto)
  1132 apply (rule DERIV_cos_cos_mult2, auto)
  1143 done
  1133 done
  1144 
  1134 
  1145 lemma DERIV_sin_circle_all: 
  1135 lemma DERIV_sin_circle_all: 
  1146      "\<forall>x. DERIV (%x. (sin x)\<twosuperior> + (cos x)\<twosuperior>) x :>  
  1136      "\<forall>x. DERIV (%x. (sin x)\<twosuperior> + (cos x)\<twosuperior>) x :>  
  1147              (2*cos(x)*sin(x) - 2*cos(x)*sin(x))"
  1137              (2*cos(x)*sin(x) - 2*cos(x)*sin(x))"
  1148 apply (unfold real_diff_def, safe)
  1138 apply (simp only: diff_minus, safe)
  1149 apply (rule DERIV_add)
  1139 apply (rule DERIV_add) 
  1150 apply (auto simp add: numeral_2_eq_2)
  1140 apply (auto simp add: numeral_2_eq_2)
  1151 done
  1141 done
  1152 
  1142 
  1153 lemma DERIV_sin_circle_all_zero [simp]: "\<forall>x. DERIV (%x. (sin x)\<twosuperior> + (cos x)\<twosuperior>) x :> 0"
  1143 lemma DERIV_sin_circle_all_zero [simp]:
       
  1144      "\<forall>x. DERIV (%x. (sin x)\<twosuperior> + (cos x)\<twosuperior>) x :> 0"
  1154 by (cut_tac DERIV_sin_circle_all, auto)
  1145 by (cut_tac DERIV_sin_circle_all, auto)
  1155 
  1146 
  1156 lemma sin_cos_squared_add [simp]: "((sin x)\<twosuperior>) + ((cos x)\<twosuperior>) = 1"
  1147 lemma sin_cos_squared_add [simp]: "((sin x)\<twosuperior>) + ((cos x)\<twosuperior>) = 1"
  1157 apply (cut_tac x = x and y = 0 in DERIV_sin_circle_all_zero [THEN DERIV_isconst_all])
  1148 apply (cut_tac x = x and y = 0 in DERIV_sin_circle_all_zero [THEN DERIV_isconst_all])
  1158 apply (auto simp add: numeral_2_eq_2)
  1149 apply (auto simp add: numeral_2_eq_2)
  1167 apply (cut_tac x = x in sin_cos_squared_add2)
  1158 apply (cut_tac x = x in sin_cos_squared_add2)
  1168 apply (auto simp add: numeral_2_eq_2)
  1159 apply (auto simp add: numeral_2_eq_2)
  1169 done
  1160 done
  1170 
  1161 
  1171 lemma sin_squared_eq: "(sin x)\<twosuperior> = 1 - (cos x)\<twosuperior>"
  1162 lemma sin_squared_eq: "(sin x)\<twosuperior> = 1 - (cos x)\<twosuperior>"
  1172 apply (rule_tac a1 = "(cos x)\<twosuperior> " in add_right_cancel [THEN iffD1])
  1163 apply (rule_tac a1 = "(cos x)\<twosuperior>" in add_right_cancel [THEN iffD1])
  1173 apply (simp del: realpow_Suc)
  1164 apply (simp del: realpow_Suc)
  1174 done
  1165 done
  1175 
  1166 
  1176 lemma cos_squared_eq: "(cos x)\<twosuperior> = 1 - (sin x)\<twosuperior>"
  1167 lemma cos_squared_eq: "(cos x)\<twosuperior> = 1 - (sin x)\<twosuperior>"
  1177 apply (rule_tac a1 = "(sin x)\<twosuperior>" in add_right_cancel [THEN iffD1])
  1168 apply (rule_tac a1 = "(sin x)\<twosuperior>" in add_right_cancel [THEN iffD1])
  1218 done
  1209 done
  1219 
  1210 
  1220 lemma DERIV_fun_pow: "DERIV g x :> m ==>  
  1211 lemma DERIV_fun_pow: "DERIV g x :> m ==>  
  1221       DERIV (%x. (g x) ^ n) x :> real n * (g x) ^ (n - 1) * m"
  1212       DERIV (%x. (g x) ^ n) x :> real n * (g x) ^ (n - 1) * m"
  1222 apply (rule lemma_DERIV_subst)
  1213 apply (rule lemma_DERIV_subst)
  1223 apply (rule_tac f = " (%x. x ^ n) " in DERIV_chain2)
  1214 apply (rule_tac f = "(%x. x ^ n)" in DERIV_chain2)
  1224 apply (rule DERIV_pow, auto)
  1215 apply (rule DERIV_pow, auto)
  1225 done
  1216 done
  1226 
  1217 
  1227 lemma DERIV_fun_exp: "DERIV g x :> m ==> DERIV (%x. exp(g x)) x :> exp(g x) * m"
  1218 lemma DERIV_fun_exp:
       
  1219      "DERIV g x :> m ==> DERIV (%x. exp(g x)) x :> exp(g x) * m"
  1228 apply (rule lemma_DERIV_subst)
  1220 apply (rule lemma_DERIV_subst)
  1229 apply (rule_tac f = exp in DERIV_chain2)
  1221 apply (rule_tac f = exp in DERIV_chain2)
  1230 apply (rule DERIV_exp, auto)
  1222 apply (rule DERIV_exp, auto)
  1231 done
  1223 done
  1232 
  1224 
  1233 lemma DERIV_fun_sin: "DERIV g x :> m ==> DERIV (%x. sin(g x)) x :> cos(g x) * m"
  1225 lemma DERIV_fun_sin:
       
  1226      "DERIV g x :> m ==> DERIV (%x. sin(g x)) x :> cos(g x) * m"
  1234 apply (rule lemma_DERIV_subst)
  1227 apply (rule lemma_DERIV_subst)
  1235 apply (rule_tac f = sin in DERIV_chain2)
  1228 apply (rule_tac f = sin in DERIV_chain2)
  1236 apply (rule DERIV_sin, auto)
  1229 apply (rule DERIV_sin, auto)
  1237 done
  1230 done
  1238 
  1231 
  1239 lemma DERIV_fun_cos: "DERIV g x :> m ==> DERIV (%x. cos(g x)) x :> -sin(g x) * m"
  1232 lemma DERIV_fun_cos:
       
  1233      "DERIV g x :> m ==> DERIV (%x. cos(g x)) x :> -sin(g x) * m"
  1240 apply (rule lemma_DERIV_subst)
  1234 apply (rule lemma_DERIV_subst)
  1241 apply (rule_tac f = cos in DERIV_chain2)
  1235 apply (rule_tac f = cos in DERIV_chain2)
  1242 apply (rule DERIV_cos, auto)
  1236 apply (rule DERIV_cos, auto)
  1243 done
  1237 done
  1244 
  1238 
  1248                     DERIV_inverse_fun DERIV_quotient DERIV_fun_pow 
  1242                     DERIV_inverse_fun DERIV_quotient DERIV_fun_pow 
  1249                     DERIV_fun_exp DERIV_fun_sin DERIV_fun_cos 
  1243                     DERIV_fun_exp DERIV_fun_sin DERIV_fun_cos 
  1250                     DERIV_Id DERIV_const DERIV_cos
  1244                     DERIV_Id DERIV_const DERIV_cos
  1251 
  1245 
  1252 (* lemma *)
  1246 (* lemma *)
  1253 lemma lemma_DERIV_sin_cos_add: "\<forall>x.  
  1247 lemma lemma_DERIV_sin_cos_add:
       
  1248      "\<forall>x.  
  1254          DERIV (%x. (sin (x + y) - (sin x * cos y + cos x * sin y)) ^ 2 +  
  1249          DERIV (%x. (sin (x + y) - (sin x * cos y + cos x * sin y)) ^ 2 +  
  1255                (cos (x + y) - (cos x * cos y - sin x * sin y)) ^ 2) x :> 0"
  1250                (cos (x + y) - (cos x * cos y - sin x * sin y)) ^ 2) x :> 0"
  1256 apply (safe, rule lemma_DERIV_subst)
  1251 apply (safe, rule lemma_DERIV_subst)
  1257 apply (best intro!: DERIV_intros intro: DERIV_chain2) 
  1252 apply (best intro!: DERIV_intros intro: DERIV_chain2) 
  1258   --{*replaces the old @{text DERIV_tac}*}
  1253   --{*replaces the old @{text DERIV_tac}*}
  1259 apply (auto simp add: real_diff_def left_distrib right_distrib mult_ac add_ac)
  1254 apply (auto simp add: diff_minus left_distrib right_distrib mult_ac add_ac)
  1260 done
  1255 done
  1261 
  1256 
  1262 lemma sin_cos_add [simp]:
  1257 lemma sin_cos_add [simp]:
  1263      "(sin (x + y) - (sin x * cos y + cos x * sin y)) ^ 2 +  
  1258      "(sin (x + y) - (sin x * cos y + cos x * sin y)) ^ 2 +  
  1264       (cos (x + y) - (cos x * cos y - sin x * sin y)) ^ 2 = 0"
  1259       (cos (x + y) - (cos x * cos y - sin x * sin y)) ^ 2 = 0"
  1281 
  1276 
  1282 lemma lemma_DERIV_sin_cos_minus:
  1277 lemma lemma_DERIV_sin_cos_minus:
  1283     "\<forall>x. DERIV (%x. (sin(-x) + (sin x)) ^ 2 + (cos(-x) - (cos x)) ^ 2) x :> 0"
  1278     "\<forall>x. DERIV (%x. (sin(-x) + (sin x)) ^ 2 + (cos(-x) - (cos x)) ^ 2) x :> 0"
  1284 apply (safe, rule lemma_DERIV_subst)
  1279 apply (safe, rule lemma_DERIV_subst)
  1285 apply (best intro!: DERIV_intros intro: DERIV_chain2) 
  1280 apply (best intro!: DERIV_intros intro: DERIV_chain2) 
  1286 apply (auto simp add: real_diff_def left_distrib right_distrib mult_ac add_ac)
  1281 apply (auto simp add: diff_minus left_distrib right_distrib mult_ac add_ac)
  1287 done
  1282 done
  1288 
  1283 
  1289 lemma sin_cos_minus [simp]: 
  1284 lemma sin_cos_minus [simp]: 
  1290     "(sin(-x) + (sin x)) ^ 2 + (cos(-x) - (cos x)) ^ 2 = 0"
  1285     "(sin(-x) + (sin x)) ^ 2 + (cos(-x) - (cos x)) ^ 2 = 0"
  1291 apply (cut_tac y = 0 and x = x 
  1286 apply (cut_tac y = 0 and x = x 
  1304 apply (auto dest!: real_sum_squares_cancel_a 
  1299 apply (auto dest!: real_sum_squares_cancel_a 
  1305                    simp add: numeral_2_eq_2 simp del: sin_cos_minus)
  1300                    simp add: numeral_2_eq_2 simp del: sin_cos_minus)
  1306 done
  1301 done
  1307 
  1302 
  1308 lemma sin_diff: "sin (x - y) = sin x * cos y - cos x * sin y"
  1303 lemma sin_diff: "sin (x - y) = sin x * cos y - cos x * sin y"
  1309 apply (unfold real_diff_def)
  1304 apply (simp add: diff_minus)
  1310 apply (simp (no_asm) add: sin_add)
  1305 apply (simp (no_asm) add: sin_add)
  1311 done
  1306 done
  1312 
  1307 
  1313 lemma sin_diff2: "sin (x - y) = cos y * sin x - sin y * cos x"
  1308 lemma sin_diff2: "sin (x - y) = cos y * sin x - sin y * cos x"
  1314 by (simp add: sin_diff mult_commute)
  1309 by (simp add: sin_diff mult_commute)
  1315 
  1310 
  1316 lemma cos_diff: "cos (x - y) = cos x * cos y + sin x * sin y"
  1311 lemma cos_diff: "cos (x - y) = cos x * cos y + sin x * sin y"
  1317 apply (unfold real_diff_def)
  1312 apply (simp add: diff_minus)
  1318 apply (simp (no_asm) add: cos_add)
  1313 apply (simp (no_asm) add: cos_add)
  1319 done
  1314 done
  1320 
  1315 
  1321 lemma cos_diff2: "cos (x - y) = cos y * cos x + sin y * sin x"
  1316 lemma cos_diff2: "cos (x - y) = cos y * cos x + sin y * sin x"
  1322 by (simp add: cos_diff mult_commute)
  1317 by (simp add: cos_diff mult_commute)
  1429 lemma cos_two_less_zero: "cos (2) < 0"
  1424 lemma cos_two_less_zero: "cos (2) < 0"
  1430 apply (cut_tac x = 2 in cos_paired)
  1425 apply (cut_tac x = 2 in cos_paired)
  1431 apply (drule sums_minus)
  1426 apply (drule sums_minus)
  1432 apply (rule neg_less_iff_less [THEN iffD1]) 
  1427 apply (rule neg_less_iff_less [THEN iffD1]) 
  1433 apply (frule sums_unique, auto)
  1428 apply (frule sums_unique, auto)
  1434 apply (rule_tac y = "sumr 0 (Suc (Suc (Suc 0))) (%n. - ((- 1) ^ n / (real (fact (2 * n))) * 2 ^ (2 * n))) " in order_less_trans)
  1429 apply (rule_tac y = "sumr 0 (Suc (Suc (Suc 0))) (%n. - ((- 1) ^ n / (real (fact (2 * n))) * 2 ^ (2 * n)))" in order_less_trans)
  1435 apply (simp (no_asm) add: fact_num_eq_if realpow_num_eq_if del: fact_Suc realpow_Suc)
  1430 apply (simp (no_asm) add: fact_num_eq_if realpow_num_eq_if del: fact_Suc realpow_Suc)
  1436 apply (simp (no_asm) add: mult_assoc del: sumr_Suc)
  1431 apply (simp (no_asm) add: mult_assoc del: sumr_Suc)
  1437 apply (rule sumr_pos_lt_pair)
  1432 apply (rule sumr_pos_lt_pair)
  1438 apply (erule sums_summable, safe)
  1433 apply (erule sums_summable, safe)
  1439 apply (simp (no_asm) add: divide_inverse real_0_less_add_iff mult_assoc [symmetric] 
  1434 apply (simp (no_asm) add: divide_inverse real_0_less_add_iff mult_assoc [symmetric] 
  1500 declare pi_half_less_two [simp]
  1495 declare pi_half_less_two [simp]
  1501 declare pi_half_less_two [THEN real_not_refl2, simp]
  1496 declare pi_half_less_two [THEN real_not_refl2, simp]
  1502 declare pi_half_less_two [THEN order_less_imp_le, simp]
  1497 declare pi_half_less_two [THEN order_less_imp_le, simp]
  1503 
  1498 
  1504 lemma pi_gt_zero [simp]: "0 < pi"
  1499 lemma pi_gt_zero [simp]: "0 < pi"
  1505 apply (rule_tac c="inverse 2" in mult_less_imp_less_right) 
  1500 apply (insert pi_half_gt_zero) 
  1506 apply (cut_tac pi_half_gt_zero, simp_all)
  1501 apply (simp add: ); 
  1507 done
  1502 done
  1508 
  1503 
  1509 lemma pi_neq_zero [simp]: "pi \<noteq> 0"
  1504 lemma pi_neq_zero [simp]: "pi \<noteq> 0"
  1510 by (rule pi_gt_zero [THEN real_not_refl2, THEN not_sym])
  1505 by (rule pi_gt_zero [THEN real_not_refl2, THEN not_sym])
  1511 
  1506 
  1531 
  1526 
  1532 lemma sin_pi [simp]: "sin pi = 0"
  1527 lemma sin_pi [simp]: "sin pi = 0"
  1533 by (cut_tac x = "pi/2" and y = "pi/2" in sin_add, simp)
  1528 by (cut_tac x = "pi/2" and y = "pi/2" in sin_add, simp)
  1534 
  1529 
  1535 lemma sin_cos_eq: "sin x = cos (pi/2 - x)"
  1530 lemma sin_cos_eq: "sin x = cos (pi/2 - x)"
  1536 apply (unfold real_diff_def)
  1531 by (simp add: diff_minus cos_add)
  1537 apply (simp (no_asm) add: cos_add)
       
  1538 done
       
  1539 
  1532 
  1540 lemma minus_sin_cos_eq: "-sin x = cos (x + pi/2)"
  1533 lemma minus_sin_cos_eq: "-sin x = cos (x + pi/2)"
  1541 apply (simp (no_asm) add: cos_add)
  1534 by (simp add: cos_add)
  1542 done
       
  1543 declare minus_sin_cos_eq [symmetric, simp]
  1535 declare minus_sin_cos_eq [symmetric, simp]
  1544 
  1536 
  1545 lemma cos_sin_eq: "cos x = sin (pi/2 - x)"
  1537 lemma cos_sin_eq: "cos x = sin (pi/2 - x)"
  1546 apply (unfold real_diff_def)
  1538 by (simp add: diff_minus sin_add)
  1547 apply (simp (no_asm) add: sin_add)
       
  1548 done
       
  1549 declare sin_cos_eq [symmetric, simp] cos_sin_eq [symmetric, simp]
  1539 declare sin_cos_eq [symmetric, simp] cos_sin_eq [symmetric, simp]
  1550 
  1540 
  1551 lemma sin_periodic_pi [simp]: "sin (x + pi) = - sin x"
  1541 lemma sin_periodic_pi [simp]: "sin (x + pi) = - sin x"
  1552 apply (simp (no_asm) add: sin_add)
  1542 by (simp add: sin_add)
  1553 done
       
  1554 
  1543 
  1555 lemma sin_periodic_pi2 [simp]: "sin (pi + x) = - sin x"
  1544 lemma sin_periodic_pi2 [simp]: "sin (pi + x) = - sin x"
  1556 apply (simp (no_asm) add: sin_add)
  1545 by (simp add: sin_add)
  1557 done
       
  1558 
  1546 
  1559 lemma cos_periodic_pi [simp]: "cos (x + pi) = - cos x"
  1547 lemma cos_periodic_pi [simp]: "cos (x + pi) = - cos x"
  1560 apply (simp (no_asm) add: cos_add)
  1548 by (simp add: cos_add)
  1561 done
       
  1562 
  1549 
  1563 lemma sin_periodic [simp]: "sin (x + 2*pi) = sin x"
  1550 lemma sin_periodic [simp]: "sin (x + 2*pi) = sin x"
  1564 by (simp add: sin_add cos_double)
  1551 by (simp add: sin_add cos_double)
  1565 
  1552 
  1566 lemma cos_periodic [simp]: "cos (x + 2*pi) = cos x"
  1553 lemma cos_periodic [simp]: "cos (x + 2*pi) = cos x"
  1583 
  1570 
  1584 lemma cos_two_pi [simp]: "cos (2 * pi) = 1"
  1571 lemma cos_two_pi [simp]: "cos (2 * pi) = 1"
  1585 by (simp add: cos_double)
  1572 by (simp add: cos_double)
  1586 
  1573 
  1587 lemma sin_two_pi [simp]: "sin (2 * pi) = 0"
  1574 lemma sin_two_pi [simp]: "sin (2 * pi) = 0"
  1588 apply (simp (no_asm))
  1575 by simp
  1589 done
       
  1590 
  1576 
  1591 lemma sin_gt_zero2: "[| 0 < x; x < pi/2 |] ==> 0 < sin x"
  1577 lemma sin_gt_zero2: "[| 0 < x; x < pi/2 |] ==> 0 < sin x"
  1592 apply (rule sin_gt_zero, assumption)
  1578 apply (rule sin_gt_zero, assumption)
  1593 apply (rule order_less_trans, assumption)
  1579 apply (rule order_less_trans, assumption)
  1594 apply (rule pi_half_less_two)
  1580 apply (rule pi_half_less_two)
  1656 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))")
  1642 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))")
  1657 apply (erule swap)
  1643 apply (erule swap)
  1658 apply (simp del: minus_sin_cos_eq [symmetric])
  1644 apply (simp del: minus_sin_cos_eq [symmetric])
  1659 apply (cut_tac y="-y" in cos_total, simp) apply simp 
  1645 apply (cut_tac y="-y" in cos_total, simp) apply simp 
  1660 apply (erule ex1E)
  1646 apply (erule ex1E)
  1661 apply (rule_tac a = "x - (pi/2) " in ex1I)
  1647 apply (rule_tac a = "x - (pi/2)" in ex1I)
  1662 apply (simp (no_asm) add: real_add_assoc)
  1648 apply (simp (no_asm) add: real_add_assoc)
  1663 apply (rotate_tac 3)
  1649 apply (rotate_tac 3)
  1664 apply (drule_tac x = "xa + pi/2" in spec, safe, simp_all) 
  1650 apply (drule_tac x = "xa + pi/2" in spec, safe, simp_all) 
  1665 done
  1651 done
  1666 
  1652 
  1675  prefer 2 apply (rule not_less_Least, simp, force)  
  1661  prefer 2 apply (rule not_less_Least, simp, force)  
  1676 done
  1662 done
  1677 
  1663 
  1678 (* Pre Isabelle99-2 proof was simpler- numerals arithmetic 
  1664 (* Pre Isabelle99-2 proof was simpler- numerals arithmetic 
  1679    now causes some unwanted re-arrangements of literals!   *)
  1665    now causes some unwanted re-arrangements of literals!   *)
  1680 lemma cos_zero_lemma: "[| 0 \<le> x; cos x = 0 |] ==>  
  1666 lemma cos_zero_lemma:
       
  1667      "[| 0 \<le> x; cos x = 0 |] ==>  
  1681       \<exists>n::nat. ~even n & x = real n * (pi/2)"
  1668       \<exists>n::nat. ~even n & x = real n * (pi/2)"
  1682 apply (drule pi_gt_zero [THEN reals_Archimedean4], safe)
  1669 apply (drule pi_gt_zero [THEN reals_Archimedean4], safe)
  1683 apply (subgoal_tac "0 \<le> x - real n * pi & 
  1670 apply (subgoal_tac "0 \<le> x - real n * pi & 
  1684                     (x - real n * pi) \<le> pi & (cos (x - real n * pi) = 0) ")
  1671                     (x - real n * pi) \<le> pi & (cos (x - real n * pi) = 0) ")
  1685 apply (auto simp add: compare_rls) 
  1672 apply (auto simp add: compare_rls) 
  1689 apply (subgoal_tac "EX! x. 0 \<le> x & x \<le> pi & cos x = 0")
  1676 apply (subgoal_tac "EX! x. 0 \<le> x & x \<le> pi & cos x = 0")
  1690 apply (rule_tac [2] cos_total, safe)
  1677 apply (rule_tac [2] cos_total, safe)
  1691 apply (drule_tac x = "x - real n * pi" in spec)
  1678 apply (drule_tac x = "x - real n * pi" in spec)
  1692 apply (drule_tac x = "pi/2" in spec)
  1679 apply (drule_tac x = "pi/2" in spec)
  1693 apply (simp add: cos_diff)
  1680 apply (simp add: cos_diff)
  1694 apply (rule_tac x = "Suc (2 * n) " in exI)
  1681 apply (rule_tac x = "Suc (2 * n)" in exI)
  1695 apply (simp add: real_of_nat_Suc left_distrib, auto)
  1682 apply (simp add: real_of_nat_Suc left_distrib, auto)
  1696 done
  1683 done
  1697 
  1684 
  1698 lemma sin_zero_lemma: "[| 0 \<le> x; sin x = 0 |] ==>  
  1685 lemma sin_zero_lemma:
       
  1686      "[| 0 \<le> x; sin x = 0 |] ==>  
  1699       \<exists>n::nat. even n & x = real n * (pi/2)"
  1687       \<exists>n::nat. even n & x = real n * (pi/2)"
  1700 apply (subgoal_tac "\<exists>n::nat. ~ even n & x + pi/2 = real n * (pi/2) ")
  1688 apply (subgoal_tac "\<exists>n::nat. ~ even n & x + pi/2 = real n * (pi/2) ")
  1701  apply (clarify, rule_tac x = "n - 1" in exI)
  1689  apply (clarify, rule_tac x = "n - 1" in exI)
  1702  apply (force simp add: odd_Suc_mult_two_ex real_of_nat_Suc left_distrib)
  1690  apply (force simp add: odd_Suc_mult_two_ex real_of_nat_Suc left_distrib)
  1703 apply (rule cos_zero_lemma)
  1691 apply (rule cos_zero_lemma)
  1704 apply (simp_all add: add_increasing)  
  1692 apply (simp_all add: add_increasing)  
  1705 done
  1693 done
  1706 
  1694 
  1707 
  1695 
  1708 lemma cos_zero_iff: "(cos x = 0) =  
  1696 lemma cos_zero_iff:
       
  1697      "(cos x = 0) =  
  1709       ((\<exists>n::nat. ~even n & (x = real n * (pi/2))) |    
  1698       ((\<exists>n::nat. ~even n & (x = real n * (pi/2))) |    
  1710        (\<exists>n::nat. ~even n & (x = -(real n * (pi/2)))))"
  1699        (\<exists>n::nat. ~even n & (x = -(real n * (pi/2)))))"
  1711 apply (rule iffI)
  1700 apply (rule iffI)
  1712 apply (cut_tac linorder_linear [of 0 x], safe)
  1701 apply (cut_tac linorder_linear [of 0 x], safe)
  1713 apply (drule cos_zero_lemma, assumption+)
  1702 apply (drule cos_zero_lemma, assumption+)
  1716 apply (auto simp only: odd_Suc_mult_two_ex real_of_nat_Suc left_distrib) 
  1705 apply (auto simp only: odd_Suc_mult_two_ex real_of_nat_Suc left_distrib) 
  1717 apply (auto simp add: cos_add)
  1706 apply (auto simp add: cos_add)
  1718 done
  1707 done
  1719 
  1708 
  1720 (* ditto: but to a lesser extent *)
  1709 (* ditto: but to a lesser extent *)
  1721 lemma sin_zero_iff: "(sin x = 0) =  
  1710 lemma sin_zero_iff:
       
  1711      "(sin x = 0) =  
  1722       ((\<exists>n::nat. even n & (x = real n * (pi/2))) |    
  1712       ((\<exists>n::nat. even n & (x = real n * (pi/2))) |    
  1723        (\<exists>n::nat. even n & (x = -(real n * (pi/2)))))"
  1713        (\<exists>n::nat. even n & (x = -(real n * (pi/2)))))"
  1724 apply (rule iffI)
  1714 apply (rule iffI)
  1725 apply (cut_tac linorder_linear [of 0 x], safe)
  1715 apply (cut_tac linorder_linear [of 0 x], safe)
  1726 apply (drule sin_zero_lemma, assumption+)
  1716 apply (drule sin_zero_lemma, assumption+)
  1748 by (simp add: tan_def)
  1738 by (simp add: tan_def)
  1749 
  1739 
  1750 lemma lemma_tan_add1: 
  1740 lemma lemma_tan_add1: 
  1751       "[| cos x \<noteq> 0; cos y \<noteq> 0 |]  
  1741       "[| cos x \<noteq> 0; cos y \<noteq> 0 |]  
  1752         ==> 1 - tan(x)*tan(y) = cos (x + y)/(cos x * cos y)"
  1742         ==> 1 - tan(x)*tan(y) = cos (x + y)/(cos x * cos y)"
  1753 apply (unfold tan_def real_divide_def)
  1743 apply (simp add: tan_def divide_inverse)
  1754 apply (auto simp del: inverse_mult_distrib simp add: inverse_mult_distrib [symmetric] mult_ac)
  1744 apply (auto simp del: inverse_mult_distrib 
       
  1745             simp add: inverse_mult_distrib [symmetric] mult_ac)
  1755 apply (rule_tac c1 = "cos x * cos y" in real_mult_right_cancel [THEN subst])
  1746 apply (rule_tac c1 = "cos x * cos y" in real_mult_right_cancel [THEN subst])
  1756 apply (auto simp del: inverse_mult_distrib simp add: mult_assoc left_diff_distrib cos_add)
  1747 apply (auto simp del: inverse_mult_distrib 
       
  1748             simp add: mult_assoc left_diff_distrib cos_add)
  1757 done
  1749 done
  1758 
  1750 
  1759 lemma add_tan_eq: 
  1751 lemma add_tan_eq: 
  1760       "[| cos x \<noteq> 0; cos y \<noteq> 0 |]  
  1752       "[| cos x \<noteq> 0; cos y \<noteq> 0 |]  
  1761        ==> tan x + tan y = sin(x + y)/(cos x * cos y)"
  1753        ==> tan x + tan y = sin(x + y)/(cos x * cos y)"
  1762 apply (unfold tan_def)
  1754 apply (simp add: tan_def)
  1763 apply (rule_tac c1 = "cos x * cos y" in real_mult_right_cancel [THEN subst])
  1755 apply (rule_tac c1 = "cos x * cos y" in real_mult_right_cancel [THEN subst])
  1764 apply (auto simp add: mult_assoc left_distrib)
  1756 apply (auto simp add: mult_assoc left_distrib)
  1765 apply (simp (no_asm) add: sin_add)
  1757 apply (simp (no_asm) add: sin_add)
  1766 done
  1758 done
  1767 
  1759 
  1768 lemma tan_add: "[| cos x \<noteq> 0; cos y \<noteq> 0; cos (x + y) \<noteq> 0 |]  
  1760 lemma tan_add:
       
  1761      "[| cos x \<noteq> 0; cos y \<noteq> 0; cos (x + y) \<noteq> 0 |]  
  1769       ==> tan(x + y) = (tan(x) + tan(y))/(1 - tan(x) * tan(y))"
  1762       ==> tan(x + y) = (tan(x) + tan(y))/(1 - tan(x) * tan(y))"
  1770 apply (simp (no_asm_simp) add: add_tan_eq lemma_tan_add1)
  1763 apply (simp (no_asm_simp) add: add_tan_eq lemma_tan_add1)
  1771 apply (simp add: tan_def)
  1764 apply (simp add: tan_def)
  1772 done
  1765 done
  1773 
  1766 
  1774 lemma tan_double: "[| cos x \<noteq> 0; cos (2 * x) \<noteq> 0 |]  
  1767 lemma tan_double:
       
  1768      "[| cos x \<noteq> 0; cos (2 * x) \<noteq> 0 |]  
  1775       ==> tan (2 * x) = (2 * tan x)/(1 - (tan(x) ^ 2))"
  1769       ==> tan (2 * x) = (2 * tan x)/(1 - (tan(x) ^ 2))"
  1776 apply (insert tan_add [of x x]) 
  1770 apply (insert tan_add [of x x]) 
  1777 apply (simp add: mult_2 [symmetric])  
  1771 apply (simp add: mult_2 [symmetric])  
  1778 apply (auto simp add: numeral_2_eq_2)
  1772 apply (auto simp add: numeral_2_eq_2)
  1779 done
  1773 done
  1780 
  1774 
  1781 lemma tan_gt_zero: "[| 0 < x; x < pi/2 |] ==> 0 < tan x"
  1775 lemma tan_gt_zero: "[| 0 < x; x < pi/2 |] ==> 0 < tan x"
  1782 apply (unfold tan_def real_divide_def)
  1776 by (simp add: tan_def zero_less_divide_iff sin_gt_zero2 cos_gt_zero_pi) 
  1783 apply (auto intro!: sin_gt_zero2 cos_gt_zero_pi intro!: real_mult_order positive_imp_inverse_positive)
       
  1784 done
       
  1785 
  1777 
  1786 lemma tan_less_zero: 
  1778 lemma tan_less_zero: 
  1787   assumes lb: "- pi/2 < x" and "x < 0" shows "tan x < 0"
  1779   assumes lb: "- pi/2 < x" and "x < 0" shows "tan x < 0"
  1788 proof -
  1780 proof -
  1789   have "0 < tan (- x)" using prems by (simp only: tan_gt_zero) 
  1781   have "0 < tan (- x)" using prems by (simp only: tan_gt_zero) 
  1799 
  1791 
  1800 lemma DERIV_tan [simp]: "cos x \<noteq> 0 ==> DERIV tan x :> inverse((cos x)\<twosuperior>)"
  1792 lemma DERIV_tan [simp]: "cos x \<noteq> 0 ==> DERIV tan x :> inverse((cos x)\<twosuperior>)"
  1801 by (auto dest: lemma_DERIV_tan simp add: tan_def [symmetric])
  1793 by (auto dest: lemma_DERIV_tan simp add: tan_def [symmetric])
  1802 
  1794 
  1803 lemma LIM_cos_div_sin [simp]: "(%x. cos(x)/sin(x)) -- pi/2 --> 0"
  1795 lemma LIM_cos_div_sin [simp]: "(%x. cos(x)/sin(x)) -- pi/2 --> 0"
  1804 apply (unfold real_divide_def)
       
  1805 apply (subgoal_tac "(\<lambda>x. cos x * inverse (sin x)) -- pi * inverse 2 --> 0*1")
  1796 apply (subgoal_tac "(\<lambda>x. cos x * inverse (sin x)) -- pi * inverse 2 --> 0*1")
  1806 apply simp 
  1797 apply (simp add: divide_inverse [symmetric])
  1807 apply (rule LIM_mult2)
  1798 apply (rule LIM_mult2)
  1808 apply (rule_tac [2] inverse_1 [THEN subst])
  1799 apply (rule_tac [2] inverse_1 [THEN subst])
  1809 apply (rule_tac [2] LIM_inverse)
  1800 apply (rule_tac [2] LIM_inverse)
  1810 apply (simp_all add: divide_inverse [symmetric]) 
  1801 apply (simp_all add: divide_inverse [symmetric]) 
  1811 apply (simp_all only: isCont_def [symmetric] cos_pi_half [symmetric] sin_pi_half [symmetric]) 
  1802 apply (simp_all only: isCont_def [symmetric] cos_pi_half [symmetric] sin_pi_half [symmetric]) 
  1815 lemma lemma_tan_total: "0 < y ==> \<exists>x. 0 < x & x < pi/2 & y < tan x"
  1806 lemma lemma_tan_total: "0 < y ==> \<exists>x. 0 < x & x < pi/2 & y < tan x"
  1816 apply (cut_tac LIM_cos_div_sin)
  1807 apply (cut_tac LIM_cos_div_sin)
  1817 apply (simp only: LIM_def)
  1808 apply (simp only: LIM_def)
  1818 apply (drule_tac x = "inverse y" in spec, safe, force)
  1809 apply (drule_tac x = "inverse y" in spec, safe, force)
  1819 apply (drule_tac ?d1.0 = s in pi_half_gt_zero [THEN [2] real_lbound_gt_zero], safe)
  1810 apply (drule_tac ?d1.0 = s in pi_half_gt_zero [THEN [2] real_lbound_gt_zero], safe)
  1820 apply (rule_tac x = " (pi/2) - e" in exI)
  1811 apply (rule_tac x = "(pi/2) - e" in exI)
  1821 apply (simp (no_asm_simp))
  1812 apply (simp (no_asm_simp))
  1822 apply (drule_tac x = " (pi/2) - e" in spec)
  1813 apply (drule_tac x = "(pi/2) - e" in spec)
  1823 apply (auto simp add: abs_eqI2 tan_def)
  1814 apply (auto simp add: tan_def)
  1824 apply (rule inverse_less_iff_less [THEN iffD1])
  1815 apply (rule inverse_less_iff_less [THEN iffD1])
  1825 apply (auto simp add: divide_inverse)
  1816 apply (auto simp add: divide_inverse)
  1826 apply (rule real_mult_order)
  1817 apply (rule real_mult_order) 
  1827 apply (subgoal_tac [3] "0 < sin e")
  1818 apply (subgoal_tac [3] "0 < sin e & 0 < cos e")
  1828 apply (subgoal_tac [3] "0 < cos e")
  1819 apply (auto intro: cos_gt_zero sin_gt_zero2 simp add: mult_commute) 
  1829 apply (auto intro: cos_gt_zero sin_gt_zero2 simp add: inverse_mult_distrib abs_mult)
       
  1830 apply (drule_tac a = "cos e" in positive_imp_inverse_positive)
       
  1831 apply (drule_tac x = "inverse (cos e) " in abs_eqI2)
       
  1832 apply (auto dest!: abs_eqI2 simp add: mult_ac)
       
  1833 done
  1820 done
  1834 
  1821 
  1835 lemma tan_total_pos: "0 \<le> y ==> \<exists>x. 0 \<le> x & x < pi/2 & tan x = y"
  1822 lemma tan_total_pos: "0 \<le> y ==> \<exists>x. 0 \<le> x & x < pi/2 & tan x = y"
  1836 apply (frule real_le_imp_less_or_eq, safe)
  1823 apply (frule real_le_imp_less_or_eq, safe)
  1837  prefer 2 apply force
  1824  prefer 2 apply force
  1863 apply (rule_tac [!] DERIV_tan asm_rl)
  1850 apply (rule_tac [!] DERIV_tan asm_rl)
  1864 apply (auto dest!: DERIV_unique [OF _ DERIV_tan]
  1851 apply (auto dest!: DERIV_unique [OF _ DERIV_tan]
  1865 	    simp add: cos_gt_zero_pi [THEN real_not_refl2, THEN not_sym]) 
  1852 	    simp add: cos_gt_zero_pi [THEN real_not_refl2, THEN not_sym]) 
  1866 done
  1853 done
  1867 
  1854 
  1868 lemma arcsin_pi: "[| -1 \<le> y; y \<le> 1 |]  
  1855 lemma arcsin_pi:
       
  1856      "[| -1 \<le> y; y \<le> 1 |]  
  1869       ==> -(pi/2) \<le> arcsin y & arcsin y \<le> pi & sin(arcsin y) = y"
  1857       ==> -(pi/2) \<le> arcsin y & arcsin y \<le> pi & sin(arcsin y) = y"
  1870 apply (drule sin_total, assumption)
  1858 apply (drule sin_total, assumption)
  1871 apply (erule ex1E)
  1859 apply (erule ex1E)
  1872 apply (unfold arcsin_def)
  1860 apply (simp add: arcsin_def)
  1873 apply (rule someI2, blast) 
  1861 apply (rule someI2, blast) 
  1874 apply (force intro: order_trans) 
  1862 apply (force intro: order_trans) 
  1875 done
  1863 done
  1876 
  1864 
  1877 lemma arcsin: "[| -1 \<le> y; y \<le> 1 |]  
  1865 lemma arcsin:
       
  1866      "[| -1 \<le> y; y \<le> 1 |]  
  1878       ==> -(pi/2) \<le> arcsin y &  
  1867       ==> -(pi/2) \<le> arcsin y &  
  1879            arcsin y \<le> pi/2 & sin(arcsin y) = y"
  1868            arcsin y \<le> pi/2 & sin(arcsin y) = y"
  1880 apply (unfold arcsin_def)
  1869 apply (unfold arcsin_def)
  1881 apply (drule sin_total, assumption)
  1870 apply (drule sin_total, assumption)
  1882 apply (fast intro: someI2)
  1871 apply (fast intro: someI2)
  1910 apply (unfold arcsin_def)
  1899 apply (unfold arcsin_def)
  1911 apply (rule some1_equality)
  1900 apply (rule some1_equality)
  1912 apply (rule sin_total, auto)
  1901 apply (rule sin_total, auto)
  1913 done
  1902 done
  1914 
  1903 
  1915 lemma arcos: "[| -1 \<le> y; y \<le> 1 |]  
  1904 lemma arcos:
       
  1905      "[| -1 \<le> y; y \<le> 1 |]  
  1916       ==> 0 \<le> arcos y & arcos y \<le> pi & cos(arcos y) = y"
  1906       ==> 0 \<le> arcos y & arcos y \<le> pi & cos(arcos y) = y"
  1917 apply (unfold arcos_def)
  1907 apply (simp add: arcos_def)
  1918 apply (drule cos_total, assumption)
  1908 apply (drule cos_total, assumption)
  1919 apply (fast intro: someI2)
  1909 apply (fast intro: someI2)
  1920 done
  1910 done
  1921 
  1911 
  1922 lemma cos_arcos [simp]: "[| -1 \<le> y; y \<le> 1 |] ==> cos(arcos y) = y"
  1912 lemma cos_arcos [simp]: "[| -1 \<le> y; y \<le> 1 |] ==> cos(arcos y) = y"
  1929 by (blast dest: arcos)
  1919 by (blast dest: arcos)
  1930 
  1920 
  1931 lemma arcos_ubound: "[| -1 \<le> y; y \<le> 1 |] ==> arcos y \<le> pi"
  1921 lemma arcos_ubound: "[| -1 \<le> y; y \<le> 1 |] ==> arcos y \<le> pi"
  1932 by (blast dest: arcos)
  1922 by (blast dest: arcos)
  1933 
  1923 
  1934 lemma arcos_lt_bounded: "[| -1 < y; y < 1 |]  
  1924 lemma arcos_lt_bounded:
       
  1925      "[| -1 < y; y < 1 |]  
  1935       ==> 0 < arcos y & arcos y < pi"
  1926       ==> 0 < arcos y & arcos y < pi"
  1936 apply (frule order_less_imp_le)
  1927 apply (frule order_less_imp_le)
  1937 apply (frule_tac y = y in order_less_imp_le)
  1928 apply (frule_tac y = y in order_less_imp_le)
  1938 apply (frule arcos_bounded, auto)
  1929 apply (frule arcos_bounded, auto)
  1939 apply (drule_tac y = "arcos y" in order_le_imp_less_or_eq)
  1930 apply (drule_tac y = "arcos y" in order_le_imp_less_or_eq)
  1940 apply (drule_tac [2] y = pi in order_le_imp_less_or_eq, auto)
  1931 apply (drule_tac [2] y = pi in order_le_imp_less_or_eq, auto)
  1941 apply (drule_tac [!] f = cos in arg_cong, auto)
  1932 apply (drule_tac [!] f = cos in arg_cong, auto)
  1942 done
  1933 done
  1943 
  1934 
  1944 lemma arcos_cos: "[|0 \<le> x; x \<le> pi |] ==> arcos(cos x) = x"
  1935 lemma arcos_cos: "[|0 \<le> x; x \<le> pi |] ==> arcos(cos x) = x"
  1945 apply (unfold arcos_def)
  1936 apply (simp add: arcos_def)
  1946 apply (auto intro!: some1_equality cos_total)
  1937 apply (auto intro!: some1_equality cos_total)
  1947 done
  1938 done
  1948 
  1939 
  1949 lemma arcos_cos2: "[|x \<le> 0; -pi \<le> x |] ==> arcos(cos x) = -x"
  1940 lemma arcos_cos2: "[|x \<le> 0; -pi \<le> x |] ==> arcos(cos x) = -x"
  1950 apply (unfold arcos_def)
  1941 apply (simp add: arcos_def)
  1951 apply (auto intro!: some1_equality cos_total)
  1942 apply (auto intro!: some1_equality cos_total)
  1952 done
  1943 done
  1953 
  1944 
  1954 lemma arctan [simp]:
  1945 lemma arctan [simp]:
  1955      "- (pi/2) < arctan y  & arctan y < pi/2 & tan (arctan y) = y"
  1946      "- (pi/2) < arctan y  & arctan y < pi/2 & tan (arctan y) = y"
  1956 apply (cut_tac y = y in tan_total)
  1947 apply (cut_tac y = y in tan_total)
  1957 apply (unfold arctan_def)
  1948 apply (simp add: arctan_def)
  1958 apply (fast intro: someI2)
  1949 apply (fast intro: someI2)
  1959 done
  1950 done
  1960 
  1951 
  1961 lemma tan_arctan: "tan(arctan y) = y"
  1952 lemma tan_arctan: "tan(arctan y) = y"
  1962 by auto
  1953 by auto
  1997                   mult_assoc power_inverse [symmetric] 
  1988                   mult_assoc power_inverse [symmetric] 
  1998         simp del: realpow_Suc)
  1989         simp del: realpow_Suc)
  1999 done
  1990 done
  2000 
  1991 
  2001 text{*NEEDED??*}
  1992 text{*NEEDED??*}
  2002 lemma [simp]: "sin (xa + 1 / 2 * real (Suc m) * pi) =  
  1993 lemma [simp]:
  2003       cos (xa + 1 / 2 * real  (m) * pi)"
  1994      "sin (x + 1 / 2 * real (Suc m) * pi) =  
  2004 apply (simp only: cos_add sin_add real_of_nat_Suc left_distrib right_distrib, auto)
  1995       cos (x + 1 / 2 * real  (m) * pi)"
  2005 done
  1996 by (simp only: cos_add sin_add real_of_nat_Suc left_distrib right_distrib, auto)
  2006 
  1997 
  2007 text{*NEEDED??*}
  1998 text{*NEEDED??*}
  2008 lemma [simp]: "sin (xa + real (Suc m) * pi / 2) =  
  1999 lemma [simp]:
  2009       cos (xa + real (m) * pi / 2)"
  2000      "sin (x + real (Suc m) * pi / 2) =  
  2010 apply (simp only: cos_add sin_add divide_inverse real_of_nat_Suc left_distrib right_distrib, auto)
  2001       cos (x + real (m) * pi / 2)"
  2011 done
  2002 by (simp only: cos_add sin_add real_of_nat_Suc add_divide_distrib left_distrib, auto)
  2012 
  2003 
  2013 lemma DERIV_sin_add [simp]: "DERIV (%x. sin (x + k)) xa :> cos (xa + k)"
  2004 lemma DERIV_sin_add [simp]: "DERIV (%x. sin (x + k)) xa :> cos (xa + k)"
  2014 apply (rule lemma_DERIV_subst)
  2005 apply (rule lemma_DERIV_subst)
  2015 apply (rule_tac f = sin and g = "%x. x + k" in DERIV_chain2)
  2006 apply (rule_tac f = sin and g = "%x. x + k" in DERIV_chain2)
  2016 apply (best intro!: DERIV_intros intro: DERIV_chain2)+
  2007 apply (best intro!: DERIV_intros intro: DERIV_chain2)+
  2021 lemma sin_cos_npi [simp]: "sin ((real m + 1/2) * pi) = cos (real m * pi)"
  2012 lemma sin_cos_npi [simp]: "sin ((real m + 1/2) * pi) = cos (real m * pi)"
  2022 by (auto simp add: right_distrib sin_add left_distrib mult_ac)
  2013 by (auto simp add: right_distrib sin_add left_distrib mult_ac)
  2023 
  2014 
  2024 lemma sin_cos_npi2 [simp]: "sin (real (Suc (2 * n)) * pi / 2) = (-1) ^ n"
  2015 lemma sin_cos_npi2 [simp]: "sin (real (Suc (2 * n)) * pi / 2) = (-1) ^ n"
  2025 apply (cut_tac m = n in sin_cos_npi)
  2016 apply (cut_tac m = n in sin_cos_npi)
  2026 apply (simp only: real_of_nat_Suc left_distrib divide_inverse, auto)
  2017 apply (simp only: real_of_nat_Suc left_distrib add_divide_distrib, auto)
  2027 done
  2018 done
  2028 
  2019 
  2029 lemma cos_2npi [simp]: "cos (2 * real (n::nat) * pi) = 1"
  2020 lemma cos_2npi [simp]: "cos (2 * real (n::nat) * pi) = 1"
  2030 by (simp add: cos_double mult_assoc power_add [symmetric] numeral_2_eq_2)
  2021 by (simp add: cos_double mult_assoc power_add [symmetric] numeral_2_eq_2)
  2031 
  2022 
  2043 apply (simp only: left_distrib) 
  2034 apply (simp only: left_distrib) 
  2044 apply (auto simp add: sin_add mult_ac)
  2035 apply (auto simp add: sin_add mult_ac)
  2045 done
  2036 done
  2046 
  2037 
  2047 (*NEEDED??*)
  2038 (*NEEDED??*)
  2048 lemma [simp]: "cos(x + 1 / 2 * real(Suc m) * pi) = -sin (x + 1 / 2 * real m * pi)"
  2039 lemma [simp]:
       
  2040      "cos(x + 1 / 2 * real(Suc m) * pi) = -sin (x + 1 / 2 * real m * pi)"
  2049 apply (simp only: cos_add sin_add real_of_nat_Suc right_distrib left_distrib minus_mult_right, auto)
  2041 apply (simp only: cos_add sin_add real_of_nat_Suc right_distrib left_distrib minus_mult_right, auto)
  2050 done
  2042 done
  2051 
  2043 
  2052 (*NEEDED??*)
  2044 (*NEEDED??*)
  2053 lemma [simp]: "cos (x + real(Suc m) * pi / 2) = -sin (x + real m * pi / 2)"
  2045 lemma [simp]: "cos (x + real(Suc m) * pi / 2) = -sin (x + real m * pi / 2)"
  2054 apply (simp only: cos_add sin_add divide_inverse real_of_nat_Suc left_distrib right_distrib, auto)
  2046 by (simp only: cos_add sin_add real_of_nat_Suc left_distrib add_divide_distrib, auto)
  2055 done
       
  2056 
  2047 
  2057 lemma cos_pi_eq_zero [simp]: "cos (pi * real (Suc (2 * m)) / 2) = 0"
  2048 lemma cos_pi_eq_zero [simp]: "cos (pi * real (Suc (2 * m)) / 2) = 0"
  2058 by (simp only: cos_add sin_add divide_inverse real_of_nat_Suc left_distrib right_distrib, auto)
  2049 by (simp only: cos_add sin_add real_of_nat_Suc left_distrib right_distrib add_divide_distrib, auto)
  2059 
  2050 
  2060 lemma DERIV_cos_add [simp]: "DERIV (%x. cos (x + k)) xa :> - sin (xa + k)"
  2051 lemma DERIV_cos_add [simp]: "DERIV (%x. cos (x + k)) xa :> - sin (xa + k)"
  2061 apply (rule lemma_DERIV_subst)
  2052 apply (rule lemma_DERIV_subst)
  2062 apply (rule_tac f = cos and g = "%x. x + k" in DERIV_chain2)
  2053 apply (rule_tac f = cos and g = "%x. x + k" in DERIV_chain2)
  2063 apply (best intro!: DERIV_intros intro: DERIV_chain2)+
  2054 apply (best intro!: DERIV_intros intro: DERIV_chain2)+
  2083 
  2074 
  2084 lemma cos_one_sin_zero: "cos x = 1 ==> sin x = 0"
  2075 lemma cos_one_sin_zero: "cos x = 1 ==> sin x = 0"
  2085 by (cut_tac x = x in sin_cos_squared_add3, auto)
  2076 by (cut_tac x = x in sin_cos_squared_add3, auto)
  2086 
  2077 
  2087 
  2078 
  2088 lemma real_root_less_mono: "[| 0 \<le> x; x < y |] ==> root(Suc n) x < root(Suc n) y"
  2079 lemma real_root_less_mono:
       
  2080      "[| 0 \<le> x; x < y |] ==> root(Suc n) x < root(Suc n) y"
  2089 apply (frule order_le_less_trans, assumption)
  2081 apply (frule order_le_less_trans, assumption)
  2090 apply (frule_tac n1 = n in real_root_pow_pos2 [THEN ssubst])
  2082 apply (frule_tac n1 = n in real_root_pow_pos2 [THEN ssubst])
  2091 apply (rotate_tac 1, assumption)
  2083 apply (rotate_tac 1, assumption)
  2092 apply (frule_tac n1 = n in real_root_pow_pos [THEN ssubst])
  2084 apply (frule_tac n1 = n in real_root_pow_pos [THEN ssubst])
  2093 apply (rotate_tac 3, assumption)
  2085 apply (rotate_tac 3, assumption)
  2096 apply (frule_tac n = n in real_root_pos_pos)
  2088 apply (frule_tac n = n in real_root_pos_pos)
  2097 apply (drule_tac x = "root (Suc n) x" and y = "root (Suc n) y" in realpow_increasing)
  2089 apply (drule_tac x = "root (Suc n) x" and y = "root (Suc n) y" in realpow_increasing)
  2098 apply (assumption, assumption)
  2090 apply (assumption, assumption)
  2099 apply (drule_tac x = "root (Suc n) x" in order_le_imp_less_or_eq)
  2091 apply (drule_tac x = "root (Suc n) x" in order_le_imp_less_or_eq)
  2100 apply auto
  2092 apply auto
  2101 apply (drule_tac f = "%x. x ^ (Suc n) " in arg_cong)
  2093 apply (drule_tac f = "%x. x ^ (Suc n)" in arg_cong)
  2102 apply (auto simp add: real_root_pow_pos2 simp del: realpow_Suc)
  2094 apply (auto simp add: real_root_pow_pos2 simp del: realpow_Suc)
  2103 done
  2095 done
  2104 
  2096 
  2105 lemma real_root_le_mono: "[| 0 \<le> x; x \<le> y |] ==> root(Suc n) x \<le> root(Suc n) y"
  2097 lemma real_root_le_mono:
       
  2098      "[| 0 \<le> x; x \<le> y |] ==> root(Suc n) x \<le> root(Suc n) y"
  2106 apply (drule_tac y = y in order_le_imp_less_or_eq)
  2099 apply (drule_tac y = y in order_le_imp_less_or_eq)
  2107 apply (auto dest: real_root_less_mono intro: order_less_imp_le)
  2100 apply (auto dest: real_root_less_mono intro: order_less_imp_le)
  2108 done
  2101 done
  2109 
  2102 
  2110 lemma real_root_less_iff [simp]: "[| 0 \<le> x; 0 \<le> y |] ==> (root(Suc n) x < root(Suc n) y) = (x < y)"
  2103 lemma real_root_less_iff [simp]:
       
  2104      "[| 0 \<le> x; 0 \<le> y |] ==> (root(Suc n) x < root(Suc n) y) = (x < y)"
  2111 apply (auto intro: real_root_less_mono)
  2105 apply (auto intro: real_root_less_mono)
  2112 apply (rule ccontr, drule linorder_not_less [THEN iffD1])
  2106 apply (rule ccontr, drule linorder_not_less [THEN iffD1])
  2113 apply (drule_tac x = y and n = n in real_root_le_mono, auto)
  2107 apply (drule_tac x = y and n = n in real_root_le_mono, auto)
  2114 done
  2108 done
  2115 
  2109 
  2116 lemma real_root_le_iff [simp]: "[| 0 \<le> x; 0 \<le> y |] ==> (root(Suc n) x \<le> root(Suc n) y) = (x \<le> y)"
  2110 lemma real_root_le_iff [simp]:
       
  2111      "[| 0 \<le> x; 0 \<le> y |] ==> (root(Suc n) x \<le> root(Suc n) y) = (x \<le> y)"
  2117 apply (auto intro: real_root_le_mono)
  2112 apply (auto intro: real_root_le_mono)
  2118 apply (simp (no_asm) add: linorder_not_less [symmetric])
  2113 apply (simp (no_asm) add: linorder_not_less [symmetric])
  2119 apply auto
  2114 apply auto
  2120 apply (drule_tac x = y and n = n in real_root_less_mono, auto)
  2115 apply (drule_tac x = y and n = n in real_root_less_mono, auto)
  2121 done
  2116 done
  2122 
  2117 
  2123 lemma real_root_eq_iff [simp]: "[| 0 \<le> x; 0 \<le> y |] ==> (root(Suc n) x = root(Suc n) y) = (x = y)"
  2118 lemma real_root_eq_iff [simp]:
       
  2119      "[| 0 \<le> x; 0 \<le> y |] ==> (root(Suc n) x = root(Suc n) y) = (x = y)"
  2124 apply (auto intro!: order_antisym)
  2120 apply (auto intro!: order_antisym)
  2125 apply (rule_tac n1 = n in real_root_le_iff [THEN iffD1])
  2121 apply (rule_tac n1 = n in real_root_le_iff [THEN iffD1])
  2126 apply (rule_tac [4] n1 = n in real_root_le_iff [THEN iffD1], auto)
  2122 apply (rule_tac [4] n1 = n in real_root_le_iff [THEN iffD1], auto)
  2127 done
  2123 done
  2128 
  2124 
  2129 lemma real_root_pos_unique: "[| 0 \<le> x; 0 \<le> y; y ^ (Suc n) = x |] ==> root (Suc n) x = y"
  2125 lemma real_root_pos_unique:
       
  2126      "[| 0 \<le> x; 0 \<le> y; y ^ (Suc n) = x |] ==> root (Suc n) x = y"
  2130 by (auto dest: real_root_pos2 simp del: realpow_Suc)
  2127 by (auto dest: real_root_pos2 simp del: realpow_Suc)
  2131 
  2128 
  2132 lemma real_root_mult: "[| 0 \<le> x; 0 \<le> y |] 
  2129 lemma real_root_mult:
       
  2130      "[| 0 \<le> x; 0 \<le> y |] 
  2133       ==> root(Suc n) (x * y) = root(Suc n) x * root(Suc n) y"
  2131       ==> root(Suc n) (x * y) = root(Suc n) x * root(Suc n) y"
  2134 apply (rule real_root_pos_unique)
  2132 apply (rule real_root_pos_unique)
  2135 apply (auto intro!: real_root_pos_pos_le simp add: power_mult_distrib zero_le_mult_iff real_root_pow_pos2 simp del: realpow_Suc)
  2133 apply (auto intro!: real_root_pos_pos_le simp add: power_mult_distrib zero_le_mult_iff real_root_pow_pos2 simp del: realpow_Suc)
  2136 done
  2134 done
  2137 
  2135 
  2138 lemma real_root_inverse: "0 \<le> x ==> (root(Suc n) (inverse x) = inverse(root(Suc n) x))"
  2136 lemma real_root_inverse:
       
  2137      "0 \<le> x ==> (root(Suc n) (inverse x) = inverse(root(Suc n) x))"
  2139 apply (rule real_root_pos_unique)
  2138 apply (rule real_root_pos_unique)
  2140 apply (auto intro: real_root_pos_pos_le simp add: power_inverse [symmetric] real_root_pow_pos2 simp del: realpow_Suc)
  2139 apply (auto intro: real_root_pos_pos_le simp add: power_inverse [symmetric] real_root_pow_pos2 simp del: realpow_Suc)
  2141 done
  2140 done
  2142 
  2141 
  2143 lemma real_root_divide: 
  2142 lemma real_root_divide: 
  2144      "[| 0 \<le> x; 0 \<le> y |]  
  2143      "[| 0 \<le> x; 0 \<le> y |]  
  2145       ==> (root(Suc n) (x / y) = root(Suc n) x / root(Suc n) y)"
  2144       ==> (root(Suc n) (x / y) = root(Suc n) x / root(Suc n) y)"
  2146 apply (unfold real_divide_def)
  2145 apply (simp add: divide_inverse)
  2147 apply (auto simp add: real_root_mult real_root_inverse)
  2146 apply (auto simp add: real_root_mult real_root_inverse)
  2148 done
  2147 done
  2149 
  2148 
  2150 lemma real_sqrt_less_mono: "[| 0 \<le> x; x < y |] ==> sqrt(x) < sqrt(y)"
  2149 lemma real_sqrt_less_mono: "[| 0 \<le> x; x < y |] ==> sqrt(x) < sqrt(y)"
  2151 apply (unfold sqrt_def)
  2150 by (simp add: sqrt_def)
  2152 apply (auto intro: real_root_less_mono)
       
  2153 done
       
  2154 
  2151 
  2155 lemma real_sqrt_le_mono: "[| 0 \<le> x; x \<le> y |] ==> sqrt(x) \<le> sqrt(y)"
  2152 lemma real_sqrt_le_mono: "[| 0 \<le> x; x \<le> y |] ==> sqrt(x) \<le> sqrt(y)"
  2156 apply (unfold sqrt_def)
  2153 by (simp add: sqrt_def)
  2157 apply (auto intro: real_root_le_mono)
  2154 
  2158 done
  2155 lemma real_sqrt_less_iff [simp]:
  2159 
  2156      "[| 0 \<le> x; 0 \<le> y |] ==> (sqrt(x) < sqrt(y)) = (x < y)"
  2160 lemma real_sqrt_less_iff [simp]: "[| 0 \<le> x; 0 \<le> y |] ==> (sqrt(x) < sqrt(y)) = (x < y)"
  2157 by (simp add: sqrt_def)
  2161 by (unfold sqrt_def, auto)
  2158 
  2162 
  2159 lemma real_sqrt_le_iff [simp]:
  2163 lemma real_sqrt_le_iff [simp]: "[| 0 \<le> x; 0 \<le> y |] ==> (sqrt(x) \<le> sqrt(y)) = (x \<le> y)"
  2160      "[| 0 \<le> x; 0 \<le> y |] ==> (sqrt(x) \<le> sqrt(y)) = (x \<le> y)"
  2164 by (unfold sqrt_def, auto)
  2161 by (simp add: sqrt_def)
  2165 
  2162 
  2166 lemma real_sqrt_eq_iff [simp]: "[| 0 \<le> x; 0 \<le> y |] ==> (sqrt(x) = sqrt(y)) = (x = y)"
  2163 lemma real_sqrt_eq_iff [simp]:
  2167 by (unfold sqrt_def, auto)
  2164      "[| 0 \<le> x; 0 \<le> y |] ==> (sqrt(x) = sqrt(y)) = (x = y)"
       
  2165 by (simp add: sqrt_def)
  2168 
  2166 
  2169 lemma real_sqrt_sos_less_one_iff [simp]: "(sqrt(x\<twosuperior> + y\<twosuperior>) < 1) = (x\<twosuperior> + y\<twosuperior> < 1)"
  2167 lemma real_sqrt_sos_less_one_iff [simp]: "(sqrt(x\<twosuperior> + y\<twosuperior>) < 1) = (x\<twosuperior> + y\<twosuperior> < 1)"
  2170 apply (rule real_sqrt_one [THEN subst], safe)
  2168 apply (rule real_sqrt_one [THEN subst], safe)
  2171 apply (rule_tac [2] real_sqrt_less_mono)
  2169 apply (rule_tac [2] real_sqrt_less_mono)
  2172 apply (drule real_sqrt_less_iff [THEN [2] rev_iffD1], auto)
  2170 apply (drule real_sqrt_less_iff [THEN [2] rev_iffD1], auto)
  2176 apply (rule real_sqrt_one [THEN subst], safe)
  2174 apply (rule real_sqrt_one [THEN subst], safe)
  2177 apply (drule real_sqrt_eq_iff [THEN [2] rev_iffD1], auto)
  2175 apply (drule real_sqrt_eq_iff [THEN [2] rev_iffD1], auto)
  2178 done
  2176 done
  2179 
  2177 
  2180 lemma real_divide_square_eq [simp]: "(((r::real) * a) / (r * r)) = a / r"
  2178 lemma real_divide_square_eq [simp]: "(((r::real) * a) / (r * r)) = a / r"
  2181 apply (unfold real_divide_def)
  2179 apply (simp add: divide_inverse)
  2182 apply (case_tac "r=0")
  2180 apply (case_tac "r=0")
  2183 apply (auto simp add: inverse_mult_distrib mult_ac)
  2181 apply (auto simp add: inverse_mult_distrib mult_ac)
  2184 done
  2182 done
  2185 
  2183 
  2186 
  2184 
  2237 lemma lemma_real_divide_sqrt_le_one: "x < 0 ==> x/(sqrt (x * x + y * y)) \<le> 1"
  2235 lemma lemma_real_divide_sqrt_le_one: "x < 0 ==> x/(sqrt (x * x + y * y)) \<le> 1"
  2238 by (insert lemma_real_divide_sqrt_ge_minus_one [of "-x" y], simp)
  2236 by (insert lemma_real_divide_sqrt_ge_minus_one [of "-x" y], simp)
  2239 
  2237 
  2240 lemma lemma_real_divide_sqrt_ge_minus_one2:
  2238 lemma lemma_real_divide_sqrt_ge_minus_one2:
  2241      "x < 0 ==> -1 \<le> x/(sqrt (x * x + y * y))"
  2239      "x < 0 ==> -1 \<le> x/(sqrt (x * x + y * y))"
  2242 apply (simp add: divide_const_simps); 
  2240 apply (simp add: divide_const_simps) 
  2243 apply (insert minus_le_real_sqrt_sumsq [of x y])
  2241 apply (insert minus_le_real_sqrt_sumsq [of x y], arith)
  2244 apply arith;
       
  2245 done
  2242 done
  2246 
  2243 
  2247 lemma lemma_real_divide_sqrt_le_one2: "0 < x ==> x/(sqrt (x * x + y * y)) \<le> 1"
  2244 lemma lemma_real_divide_sqrt_le_one2: "0 < x ==> x/(sqrt (x * x + y * y)) \<le> 1"
  2248 by (cut_tac x = "-x" and y = y in lemma_real_divide_sqrt_ge_minus_one2, auto)
  2245 by (cut_tac x = "-x" and y = y in lemma_real_divide_sqrt_ge_minus_one2, auto)
  2249 
  2246 
  2255 
  2252 
  2256 lemma not_neg_sqrt_sumsq: "~ sqrt (x * x + y * y) < 0"
  2253 lemma not_neg_sqrt_sumsq: "~ sqrt (x * x + y * y) < 0"
  2257 by (simp add: linorder_not_less)
  2254 by (simp add: linorder_not_less)
  2258 
  2255 
  2259 lemma cos_x_y_ge_minus_one: "-1 \<le> x / sqrt (x * x + y * y)"
  2256 lemma cos_x_y_ge_minus_one: "-1 \<le> x / sqrt (x * x + y * y)"
  2260 apply (simp add: minus_sqrt_le not_neg_sqrt_sumsq divide_const_simps); 
  2257 by (simp add: minus_sqrt_le not_neg_sqrt_sumsq divide_const_simps)
  2261 done
       
  2262 
  2258 
  2263 lemma cos_x_y_ge_minus_one1a [simp]: "-1 \<le> y / sqrt (x * x + y * y)"
  2259 lemma cos_x_y_ge_minus_one1a [simp]: "-1 \<le> y / sqrt (x * x + y * y)"
  2264 apply (subst add_commute, simp add: cos_x_y_ge_minus_one); 
  2260 by (subst add_commute, simp add: cos_x_y_ge_minus_one)
  2265 done
       
  2266 
  2261 
  2267 lemma cos_x_y_le_one [simp]: "x / sqrt (x * x + y * y) \<le> 1" 
  2262 lemma cos_x_y_le_one [simp]: "x / sqrt (x * x + y * y) \<le> 1" 
  2268 apply (cut_tac x = x and y = 0 in linorder_less_linear, safe)
  2263 apply (cut_tac x = x and y = 0 in linorder_less_linear, safe)
  2269 apply (rule lemma_real_divide_sqrt_le_one)
  2264 apply (rule lemma_real_divide_sqrt_le_one)
  2270 apply (rule_tac [3] lemma_real_divide_sqrt_le_one2, auto)
  2265 apply (rule_tac [3] lemma_real_divide_sqrt_le_one2, auto)
  2315 apply (rotate_tac [2] 2)
  2310 apply (rotate_tac [2] 2)
  2316 apply (drule_tac [2] mult_assoc [THEN subst])
  2311 apply (drule_tac [2] mult_assoc [THEN subst])
  2317 apply (rotate_tac [2] 2)
  2312 apply (rotate_tac [2] 2)
  2318 apply (frule_tac [2] left_inverse [THEN subst])
  2313 apply (frule_tac [2] left_inverse [THEN subst])
  2319 prefer 2 apply assumption
  2314 prefer 2 apply assumption
  2320 apply (erule_tac [2] V = " (1 - z) * (x + y) = x / (x + y) * (x + y) " in thin_rl)
  2315 apply (erule_tac [2] V = "(1 - z) * (x + y) = x / (x + y) * (x + y)" in thin_rl)
  2321 apply (erule_tac [2] V = "1 - z = x / (x + y) " in thin_rl)
  2316 apply (erule_tac [2] V = "1 - z = x / (x + y)" in thin_rl)
  2322 apply (auto simp add: mult_assoc)
  2317 apply (auto simp add: mult_assoc)
  2323 apply (auto simp add: right_distrib left_diff_distrib)
  2318 apply (auto simp add: right_distrib left_diff_distrib)
  2324 done
  2319 done
  2325 
  2320 
  2326 lemma lemma_cos_sin_eq:
  2321 lemma lemma_cos_sin_eq:
  2353 apply (rule_tac [2] lemma_cos_sin_eq)
  2348 apply (rule_tac [2] lemma_cos_sin_eq)
  2354 apply (auto simp add: realpow_two_disj numeral_2_eq_2 simp del: realpow_Suc)
  2349 apply (auto simp add: realpow_two_disj numeral_2_eq_2 simp del: realpow_Suc)
  2355 done
  2350 done
  2356 
  2351 
  2357 lemma lemma_cos_not_eq_zero: "x \<noteq> 0 ==> x / sqrt (x * x + y * y) \<noteq> 0"
  2352 lemma lemma_cos_not_eq_zero: "x \<noteq> 0 ==> x / sqrt (x * x + y * y) \<noteq> 0"
  2358 apply (unfold real_divide_def)
  2353 apply (simp add: divide_inverse)
  2359 apply (frule_tac y3 = y in real_sqrt_sum_squares_gt_zero3 [THEN real_not_refl2, THEN not_sym, THEN nonzero_imp_inverse_nonzero])
  2354 apply (frule_tac y3 = y in real_sqrt_sum_squares_gt_zero3 [THEN real_not_refl2, THEN not_sym, THEN nonzero_imp_inverse_nonzero])
  2360 apply (auto simp add: power2_eq_square)
  2355 apply (auto simp add: power2_eq_square)
  2361 done
  2356 done
  2362 
  2357 
  2363 lemma cos_x_y_disj: "[| x \<noteq> 0;  
  2358 lemma cos_x_y_disj:
       
  2359      "[| x \<noteq> 0;  
  2364          sin xa = y / sqrt (x * x + y * y)  
  2360          sin xa = y / sqrt (x * x + y * y)  
  2365       |] ==>  cos xa = x / sqrt (x * x + y * y) |  
  2361       |] ==>  cos xa = x / sqrt (x * x + y * y) |  
  2366               cos xa = - x / sqrt (x * x + y * y)"
  2362               cos xa = - x / sqrt (x * x + y * y)"
  2367 apply (drule_tac f = "%x. x\<twosuperior>" in arg_cong)
  2363 apply (drule_tac f = "%x. x\<twosuperior>" in arg_cong)
  2368 apply (frule_tac y = y in real_sum_square_gt_zero)
  2364 apply (frule_tac y = y in real_sum_square_gt_zero)
  2371 apply (rule_tac [2] lemma_sin_cos_eq)
  2367 apply (rule_tac [2] lemma_sin_cos_eq)
  2372 apply (auto simp add: realpow_two_disj numeral_2_eq_2 simp del: realpow_Suc)
  2368 apply (auto simp add: realpow_two_disj numeral_2_eq_2 simp del: realpow_Suc)
  2373 done
  2369 done
  2374 
  2370 
  2375 lemma real_sqrt_divide_less_zero: "0 < y ==> - y / sqrt (x * x + y * y) < 0"
  2371 lemma real_sqrt_divide_less_zero: "0 < y ==> - y / sqrt (x * x + y * y) < 0"
  2376 apply (case_tac "x = 0")
  2372 apply (case_tac "x = 0", auto)
  2377 apply (auto simp add: abs_eqI2)
       
  2378 apply (drule_tac y = y in real_sqrt_sum_squares_gt_zero3)
  2373 apply (drule_tac y = y in real_sqrt_sum_squares_gt_zero3)
  2379 apply (auto simp add: zero_less_mult_iff divide_inverse power2_eq_square)
  2374 apply (auto simp add: zero_less_mult_iff divide_inverse power2_eq_square)
  2380 done
  2375 done
  2381 
  2376 
  2382 lemma polar_ex1: "[| x \<noteq> 0; 0 < y |] ==> \<exists>r a. x = r * cos a & y = r * sin a"
  2377 lemma polar_ex1:
  2383 apply (rule_tac x = "sqrt (x\<twosuperior> + y\<twosuperior>) " in exI)
  2378      "[| x \<noteq> 0; 0 < y |] ==> \<exists>r a. x = r * cos a & y = r * sin a"
       
  2379 apply (rule_tac x = "sqrt (x\<twosuperior> + y\<twosuperior>)" in exI)
  2384 apply (rule_tac x = "arcos (x / sqrt (x * x + y * y))" in exI)
  2380 apply (rule_tac x = "arcos (x / sqrt (x * x + y * y))" in exI)
  2385 apply auto
  2381 apply auto
  2386 apply (drule_tac y2 = y in real_sqrt_sum_squares_gt_zero3 [THEN real_not_refl2, THEN not_sym])
  2382 apply (drule_tac y2 = y in real_sqrt_sum_squares_gt_zero3 [THEN real_not_refl2, THEN not_sym])
  2387 apply (auto simp add: power2_eq_square)
  2383 apply (auto simp add: power2_eq_square)
  2388 apply (unfold arcos_def)
  2384 apply (simp add: arcos_def)
  2389 apply (cut_tac x1 = x and y1 = y 
  2385 apply (cut_tac x1 = x and y1 = y 
  2390        in cos_total [OF cos_x_y_ge_minus_one cos_x_y_le_one])
  2386        in cos_total [OF cos_x_y_ge_minus_one cos_x_y_le_one])
  2391 apply (rule someI2_ex, blast)
  2387 apply (rule someI2_ex, blast)
  2392 apply (erule_tac V = "EX! xa. 0 \<le> xa & xa \<le> pi & cos xa = x / sqrt (x * x + y * y) " in thin_rl)
  2388 apply (erule_tac V = "EX! xa. 0 \<le> xa & xa \<le> pi & cos xa = x / sqrt (x * x + y * y)" in thin_rl)
  2393 apply (frule sin_x_y_disj, blast)
  2389 apply (frule sin_x_y_disj, blast)
  2394 apply (drule_tac y2 = y in real_sqrt_sum_squares_gt_zero3 [THEN real_not_refl2, THEN not_sym])
  2390 apply (drule_tac y2 = y in real_sqrt_sum_squares_gt_zero3 [THEN real_not_refl2, THEN not_sym])
  2395 apply (auto simp add: power2_eq_square)
  2391 apply (auto simp add: power2_eq_square)
  2396 apply (drule sin_ge_zero, assumption)
  2392 apply (drule sin_ge_zero, assumption)
  2397 apply (drule_tac x = x in real_sqrt_divide_less_zero, auto)
  2393 apply (drule_tac x = x in real_sqrt_divide_less_zero, auto)
  2398 done
  2394 done
  2399 
  2395 
  2400 lemma real_sum_squares_cancel2a: "x * x = -(y * y) ==> y = (0::real)"
  2396 lemma real_sum_squares_cancel2a: "x * x = -(y * y) ==> y = (0::real)"
  2401 by (auto intro: real_sum_squares_cancel iff: real_add_eq_0_iff)
  2397 by (auto intro: real_sum_squares_cancel iff: real_add_eq_0_iff)
  2402 
  2398 
  2403 lemma polar_ex2: "[| x \<noteq> 0; y < 0 |] ==> \<exists>r a. x = r * cos a & y = r * sin a"
  2399 lemma polar_ex2:
       
  2400      "[| x \<noteq> 0; y < 0 |] ==> \<exists>r a. x = r * cos a & y = r * sin a"
  2404 apply (cut_tac x = 0 and y = x in linorder_less_linear, auto)
  2401 apply (cut_tac x = 0 and y = x in linorder_less_linear, auto)
  2405 apply (rule_tac x = "sqrt (x\<twosuperior> + y\<twosuperior>)" in exI)
  2402 apply (rule_tac x = "sqrt (x\<twosuperior> + y\<twosuperior>)" in exI)
  2406 apply (rule_tac x = "arcsin (y / sqrt (x * x + y * y))" in exI) 
  2403 apply (rule_tac x = "arcsin (y / sqrt (x * x + y * y))" in exI) 
  2407 apply (auto dest: real_sum_squares_cancel2a 
  2404 apply (auto dest: real_sum_squares_cancel2a 
  2408             simp add: power2_eq_square real_0_le_add_iff real_add_eq_0_iff)
  2405             simp add: power2_eq_square real_0_le_add_iff real_add_eq_0_iff)
  2454   prefer 3 apply (simp add: numeral_2_eq_2 [symmetric] del: realpow_Suc)
  2451   prefer 3 apply (simp add: numeral_2_eq_2 [symmetric] del: realpow_Suc)
  2455 apply (simp_all add: numeral_2_eq_2)
  2452 apply (simp_all add: numeral_2_eq_2)
  2456 done
  2453 done
  2457 
  2454 
  2458 lemma lemma_real_divide_sqrt_less: "0 < u ==> u / sqrt 2 < u"
  2455 lemma lemma_real_divide_sqrt_less: "0 < u ==> u / sqrt 2 < u"
  2459 apply (rule_tac z1 = "inverse u" in real_mult_less_iff1 [THEN iffD1], auto)
  2456 by (rule_tac z1 = "inverse u" in real_mult_less_iff1 [THEN iffD1], auto)
  2460 done
       
  2461 
  2457 
  2462 lemma four_x_squared: 
  2458 lemma four_x_squared: 
  2463   fixes x::real
  2459   fixes x::real
  2464   shows "4 * x\<twosuperior> = (2 * x)\<twosuperior>"
  2460   shows "4 * x\<twosuperior> = (2 * x)\<twosuperior>"
  2465 by (simp add: power2_eq_square)
  2461 by (simp add: power2_eq_square)
  2477 apply (rule_tac t = "u\<twosuperior>" in real_sum_of_halves [THEN subst])
  2473 apply (rule_tac t = "u\<twosuperior>" in real_sum_of_halves [THEN subst])
  2478 apply (rule add_mono)
  2474 apply (rule add_mono)
  2479 apply (auto simp add: four_x_squared simp del: realpow_Suc intro: power_mono)
  2475 apply (auto simp add: four_x_squared simp del: realpow_Suc intro: power_mono)
  2480 done
  2476 done
  2481 
  2477 
  2482 declare real_sqrt_sum_squares_ge_zero [THEN abs_eqI1, simp]
  2478 declare real_sqrt_sum_squares_ge_zero [THEN abs_eq, simp]
  2483 
  2479 
  2484 
  2480 
  2485 subsection{*A Few Theorems Involving Ln, Derivatives, etc.*}
  2481 subsection{*A Few Theorems Involving Ln, Derivatives, etc.*}
  2486 
  2482 
  2487 lemma lemma_DERIV_ln:
  2483 lemma lemma_DERIV_ln:
  2491 lemma STAR_exp_ln: "0 < z ==> ( *f* (%x. exp (ln x))) z = z"
  2487 lemma STAR_exp_ln: "0 < z ==> ( *f* (%x. exp (ln x))) z = z"
  2492 apply (rule_tac z = z in eq_Abs_hypreal)
  2488 apply (rule_tac z = z in eq_Abs_hypreal)
  2493 apply (auto simp add: starfun hypreal_zero_def hypreal_less)
  2489 apply (auto simp add: starfun hypreal_zero_def hypreal_less)
  2494 done
  2490 done
  2495 
  2491 
  2496 lemma hypreal_add_Infinitesimal_gt_zero: "[|e : Infinitesimal; 0 < x |] ==> 0 < hypreal_of_real x + e"
  2492 lemma hypreal_add_Infinitesimal_gt_zero:
       
  2493      "[|e : Infinitesimal; 0 < x |] ==> 0 < hypreal_of_real x + e"
  2497 apply (rule_tac c1 = "-e" in add_less_cancel_right [THEN iffD1])
  2494 apply (rule_tac c1 = "-e" in add_less_cancel_right [THEN iffD1])
  2498 apply (auto intro: Infinitesimal_less_SReal)
  2495 apply (auto intro: Infinitesimal_less_SReal)
  2499 done
  2496 done
  2500 
  2497 
  2501 lemma NSDERIV_exp_ln_one: "0 < z ==> NSDERIV (%x. exp (ln x)) z :> 1"
  2498 lemma NSDERIV_exp_ln_one: "0 < z ==> NSDERIV (%x. exp (ln x)) z :> 1"
  2502 apply (unfold nsderiv_def NSLIM_def, auto)
  2499 apply (simp add: nsderiv_def NSLIM_def, auto)
  2503 apply (rule ccontr)
  2500 apply (rule ccontr)
  2504 apply (subgoal_tac "0 < hypreal_of_real z + h")
  2501 apply (subgoal_tac "0 < hypreal_of_real z + h")
  2505 apply (drule STAR_exp_ln)
  2502 apply (drule STAR_exp_ln)
  2506 apply (rule_tac [2] hypreal_add_Infinitesimal_gt_zero)
  2503 apply (rule_tac [2] hypreal_add_Infinitesimal_gt_zero)
  2507 apply (subgoal_tac "h/h = 1")
  2504 apply (subgoal_tac "h/h = 1")
  2509 done
  2506 done
  2510 
  2507 
  2511 lemma DERIV_exp_ln_one: "0 < z ==> DERIV (%x. exp (ln x)) z :> 1"
  2508 lemma DERIV_exp_ln_one: "0 < z ==> DERIV (%x. exp (ln x)) z :> 1"
  2512 by (auto intro: NSDERIV_exp_ln_one simp add: NSDERIV_DERIV_iff [symmetric])
  2509 by (auto intro: NSDERIV_exp_ln_one simp add: NSDERIV_DERIV_iff [symmetric])
  2513 
  2510 
  2514 lemma lemma_DERIV_ln2: "[| 0 < z; DERIV ln z :> l |] ==>  exp (ln z) * l = 1"
  2511 lemma lemma_DERIV_ln2:
       
  2512      "[| 0 < z; DERIV ln z :> l |] ==>  exp (ln z) * l = 1"
  2515 apply (rule DERIV_unique)
  2513 apply (rule DERIV_unique)
  2516 apply (rule lemma_DERIV_ln)
  2514 apply (rule lemma_DERIV_ln)
  2517 apply (rule_tac [2] DERIV_exp_ln_one, auto)
  2515 apply (rule_tac [2] DERIV_exp_ln_one, auto)
  2518 done
  2516 done
  2519 
  2517 
  2520 lemma lemma_DERIV_ln3: "[| 0 < z; DERIV ln z :> l |] ==>  l = 1/(exp (ln z))"
  2518 lemma lemma_DERIV_ln3:
  2521 apply (rule_tac c1 = "exp (ln z) " in real_mult_left_cancel [THEN iffD1])
  2519      "[| 0 < z; DERIV ln z :> l |] ==>  l = 1/(exp (ln z))"
       
  2520 apply (rule_tac c1 = "exp (ln z)" in real_mult_left_cancel [THEN iffD1])
  2522 apply (auto intro: lemma_DERIV_ln2)
  2521 apply (auto intro: lemma_DERIV_ln2)
  2523 done
  2522 done
  2524 
  2523 
  2525 lemma lemma_DERIV_ln4: "[| 0 < z; DERIV ln z :> l |] ==>  l = 1/z"
  2524 lemma lemma_DERIV_ln4: "[| 0 < z; DERIV ln z :> l |] ==>  l = 1/z"
  2526 apply (rule_tac t = z in exp_ln_iff [THEN iffD2, THEN subst])
  2525 apply (rule_tac t = z in exp_ln_iff [THEN iffD2, THEN subst])
  2527 apply (auto intro: lemma_DERIV_ln3)
  2526 apply (auto intro: lemma_DERIV_ln3)
  2528 done
  2527 done
  2529 
  2528 
  2530 (* need to rename second isCont_inverse *)
  2529 (* need to rename second isCont_inverse *)
  2531 
  2530 
  2532 lemma isCont_inv_fun: "[| 0 < d; \<forall>z. \<bar>z - x\<bar> \<le> d --> g(f(z)) = z;  
  2531 lemma isCont_inv_fun:
       
  2532      "[| 0 < d; \<forall>z. \<bar>z - x\<bar> \<le> d --> g(f(z)) = z;  
  2533          \<forall>z. \<bar>z - x\<bar> \<le> d --> isCont f z |]  
  2533          \<forall>z. \<bar>z - x\<bar> \<le> d --> isCont f z |]  
  2534       ==> isCont g (f x)"
  2534       ==> isCont g (f x)"
  2535 apply (simp (no_asm) add: isCont_iff LIM_def)
  2535 apply (simp (no_asm) add: isCont_iff LIM_def)
  2536 apply safe
  2536 apply safe
  2537 apply (drule_tac ?d1.0 = r in real_lbound_gt_zero)
  2537 apply (drule_tac ?d1.0 = r in real_lbound_gt_zero)
  2561 apply (drule_tac x = y in spec, auto)
  2561 apply (drule_tac x = y in spec, auto)
  2562 done
  2562 done
  2563 
  2563 
  2564 
  2564 
  2565 text{*Bartle/Sherbert: Introduction to Real Analysis, Theorem 4.2.9, p. 110*}
  2565 text{*Bartle/Sherbert: Introduction to Real Analysis, Theorem 4.2.9, p. 110*}
  2566 lemma LIM_fun_gt_zero: "[| f -- c --> l; 0 < l |]  
  2566 lemma LIM_fun_gt_zero:
       
  2567      "[| f -- c --> l; 0 < l |]  
  2567          ==> \<exists>r. 0 < r & (\<forall>x. x \<noteq> c & \<bar>c - x\<bar> < r --> 0 < f x)"
  2568          ==> \<exists>r. 0 < r & (\<forall>x. x \<noteq> c & \<bar>c - x\<bar> < r --> 0 < f x)"
  2568 apply (auto simp add: LIM_def)
  2569 apply (auto simp add: LIM_def)
  2569 apply (drule_tac x = "l/2" in spec, safe, force)
  2570 apply (drule_tac x = "l/2" in spec, safe, force)
  2570 apply (rule_tac x = s in exI)
  2571 apply (rule_tac x = s in exI)
  2571 apply (auto simp only: abs_interval_iff)
  2572 apply (auto simp only: abs_interval_iff)
  2572 done
  2573 done
  2573 
  2574 
  2574 lemma LIM_fun_less_zero: "[| f -- c --> l; l < 0 |]  
  2575 lemma LIM_fun_less_zero:
  2575          ==> \<exists>r. 0 < r & (\<forall>x. x \<noteq> c & \<bar>c - x\<bar> < r --> f x < 0)"
  2576      "[| f -- c --> l; l < 0 |]  
       
  2577       ==> \<exists>r. 0 < r & (\<forall>x. x \<noteq> c & \<bar>c - x\<bar> < r --> f x < 0)"
  2576 apply (auto simp add: LIM_def)
  2578 apply (auto simp add: LIM_def)
  2577 apply (drule_tac x = "-l/2" in spec, safe, force)
  2579 apply (drule_tac x = "-l/2" in spec, safe, force)
  2578 apply (rule_tac x = s in exI)
  2580 apply (rule_tac x = s in exI)
  2579 apply (auto simp only: abs_interval_iff)
  2581 apply (auto simp only: abs_interval_iff)
  2580 done
  2582 done