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