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