made repository layout more coherent with logical distribution structure; stripped some $Id$s
1 (* Title : Transcendental.thy
2 Author : Jacques D. Fleuriot
3 Copyright : 1998,1999 University of Cambridge
4 1999,2001 University of Edinburgh
5 Conversion to Isar and new proofs by Lawrence C Paulson, 2004
8 header{*Power Series, Transcendental Functions etc.*}
11 imports Fact Series Deriv NthRoot
14 subsection{*Properties of Power Series*}
16 lemma lemma_realpow_diff:
17 fixes y :: "'a::recpower"
18 shows "p \<le> n \<Longrightarrow> y ^ (Suc n - p) = (y ^ (n - p)) * y"
21 hence "Suc n - p = Suc (n - p)" by (rule Suc_diff_le)
22 thus ?thesis by (simp add: power_Suc power_commutes)
25 lemma lemma_realpow_diff_sumr:
26 fixes y :: "'a::{recpower,comm_semiring_0}" shows
27 "(\<Sum>p=0..<Suc n. (x ^ p) * y ^ (Suc n - p)) =
28 y * (\<Sum>p=0..<Suc n. (x ^ p) * y ^ (n - p))"
29 by (auto simp add: setsum_right_distrib lemma_realpow_diff mult_ac
30 simp del: setsum_op_ivl_Suc cong: strong_setsum_cong)
32 lemma lemma_realpow_diff_sumr2:
33 fixes y :: "'a::{recpower,comm_ring}" shows
34 "x ^ (Suc n) - y ^ (Suc n) =
35 (x - y) * (\<Sum>p=0..<Suc n. (x ^ p) * y ^ (n - p))"
36 apply (induct n, simp add: power_Suc)
37 apply (simp add: power_Suc del: setsum_op_ivl_Suc)
38 apply (subst setsum_op_ivl_Suc)
39 apply (subst lemma_realpow_diff_sumr)
40 apply (simp add: right_distrib del: setsum_op_ivl_Suc)
41 apply (subst mult_left_commute [where a="x - y"])
43 apply (simp add: power_Suc ring_simps)
46 lemma lemma_realpow_rev_sumr:
47 "(\<Sum>p=0..<Suc n. (x ^ p) * (y ^ (n - p))) =
48 (\<Sum>p=0..<Suc n. (x ^ (n - p)) * (y ^ p))"
49 apply (rule setsum_reindex_cong [where f="\<lambda>i. n - i"])
50 apply (rule inj_onI, simp)
52 apply (rule_tac x="n - x" in image_eqI, simp, simp)
55 text{*Power series has a `circle` of convergence, i.e. if it sums for @{term
56 x}, then it sums absolutely for @{term z} with @{term "\<bar>z\<bar> < \<bar>x\<bar>"}.*}
59 fixes x z :: "'a::{real_normed_field,banach,recpower}"
60 assumes 1: "summable (\<lambda>n. f n * x ^ n)"
61 assumes 2: "norm z < norm x"
62 shows "summable (\<lambda>n. norm (f n * z ^ n))"
64 from 2 have x_neq_0: "x \<noteq> 0" by clarsimp
65 from 1 have "(\<lambda>n. f n * x ^ n) ----> 0"
66 by (rule summable_LIMSEQ_zero)
67 hence "convergent (\<lambda>n. f n * x ^ n)"
69 hence "Cauchy (\<lambda>n. f n * x ^ n)"
70 by (simp add: Cauchy_convergent_iff)
71 hence "Bseq (\<lambda>n. f n * x ^ n)"
73 then obtain K where 3: "0 < K" and 4: "\<forall>n. norm (f n * x ^ n) \<le> K"
74 by (simp add: Bseq_def, safe)
75 have "\<exists>N. \<forall>n\<ge>N. norm (norm (f n * z ^ n)) \<le>
76 K * norm (z ^ n) * inverse (norm (x ^ n))"
77 proof (intro exI allI impI)
78 fix n::nat assume "0 \<le> n"
79 have "norm (norm (f n * z ^ n)) * norm (x ^ n) =
80 norm (f n * x ^ n) * norm (z ^ n)"
81 by (simp add: norm_mult abs_mult)
82 also have "\<dots> \<le> K * norm (z ^ n)"
83 by (simp only: mult_right_mono 4 norm_ge_zero)
84 also have "\<dots> = K * norm (z ^ n) * (inverse (norm (x ^ n)) * norm (x ^ n))"
85 by (simp add: x_neq_0)
86 also have "\<dots> = K * norm (z ^ n) * inverse (norm (x ^ n)) * norm (x ^ n)"
87 by (simp only: mult_assoc)
88 finally show "norm (norm (f n * z ^ n)) \<le>
89 K * norm (z ^ n) * inverse (norm (x ^ n))"
90 by (simp add: mult_le_cancel_right x_neq_0)
92 moreover have "summable (\<lambda>n. K * norm (z ^ n) * inverse (norm (x ^ n)))"
94 from 2 have "norm (norm (z * inverse x)) < 1"
96 by (simp add: nonzero_norm_divide divide_inverse [symmetric])
97 hence "summable (\<lambda>n. norm (z * inverse x) ^ n)"
98 by (rule summable_geometric)
99 hence "summable (\<lambda>n. K * norm (z * inverse x) ^ n)"
100 by (rule summable_mult)
101 thus "summable (\<lambda>n. K * norm (z ^ n) * inverse (norm (x ^ n)))"
103 by (simp add: norm_mult nonzero_norm_inverse power_mult_distrib
104 power_inverse norm_power mult_assoc)
106 ultimately show "summable (\<lambda>n. norm (f n * z ^ n))"
107 by (rule summable_comparison_test)
111 fixes f :: "nat \<Rightarrow> 'a::{real_normed_field,banach,recpower}" shows
112 "[| summable (%n. f(n) * (x ^ n)); norm z < norm x |]
113 ==> summable (%n. f(n) * (z ^ n))"
114 by (rule powser_insidea [THEN summable_norm_cancel])
117 subsection{*Term-by-Term Differentiability of Power Series*}
120 diffs :: "(nat => 'a::ring_1) => nat => 'a" where
121 "diffs c = (%n. of_nat (Suc n) * c(Suc n))"
123 text{*Lemma about distributing negation over it*}
124 lemma diffs_minus: "diffs (%n. - c n) = (%n. - diffs c n)"
125 by (simp add: diffs_def)
127 text{*Show that we can shift the terms down one*}
129 "(\<Sum>n=0..<n. (diffs c)(n) * (x ^ n)) =
130 (\<Sum>n=0..<n. of_nat n * c(n) * (x ^ (n - Suc 0))) +
131 (of_nat n * c(n) * x ^ (n - Suc 0))"
133 apply (auto simp add: mult_assoc add_assoc [symmetric] diffs_def)
137 "(\<Sum>n=0..<n. of_nat n * c(n) * (x ^ (n - Suc 0))) =
138 (\<Sum>n=0..<n. (diffs c)(n) * (x ^ n)) -
139 (of_nat n * c(n) * x ^ (n - Suc 0))"
140 by (auto simp add: lemma_diffs)
144 "summable (%n. (diffs c)(n) * (x ^ n)) ==>
145 (%n. of_nat n * c(n) * (x ^ (n - Suc 0))) sums
146 (\<Sum>n. (diffs c)(n) * (x ^ n))"
147 apply (subgoal_tac " (%n. of_nat n * c (n) * (x ^ (n - Suc 0))) ----> 0")
148 apply (rule_tac [2] LIMSEQ_imp_Suc)
149 apply (drule summable_sums)
150 apply (auto simp add: sums_def)
151 apply (drule_tac X="(\<lambda>n. \<Sum>n = 0..<n. diffs c n * x ^ n)" in LIMSEQ_diff)
152 apply (auto simp add: lemma_diffs2 [symmetric] diffs_def [symmetric])
153 apply (simp add: diffs_def summable_LIMSEQ_zero)
156 lemma lemma_termdiff1:
157 fixes z :: "'a :: {recpower,comm_ring}" shows
158 "(\<Sum>p=0..<m. (((z + h) ^ (m - p)) * (z ^ p)) - (z ^ m)) =
159 (\<Sum>p=0..<m. (z ^ p) * (((z + h) ^ (m - p)) - (z ^ (m - p))))"
160 by (auto simp add: right_distrib diff_minus power_add [symmetric] mult_ac
161 cong: strong_setsum_cong)
163 lemma less_add_one: "m < n ==> (\<exists>d. n = m + d + Suc 0)"
164 by (simp add: less_iff_Suc_add)
166 lemma sumdiff: "a + b - (c + d) = a - c + b - (d::real)"
169 lemma sumr_diff_mult_const2:
170 "setsum f {0..<n} - of_nat n * (r::'a::ring_1) = (\<Sum>i = 0..<n. f i - r)"
171 by (simp add: setsum_subtractf)
173 lemma lemma_termdiff2:
174 fixes h :: "'a :: {recpower,field}"
175 assumes h: "h \<noteq> 0" shows
176 "((z + h) ^ n - z ^ n) / h - of_nat n * z ^ (n - Suc 0) =
177 h * (\<Sum>p=0..< n - Suc 0. \<Sum>q=0..< n - Suc 0 - p.
178 (z + h) ^ q * z ^ (n - 2 - q))" (is "?lhs = ?rhs")
179 apply (subgoal_tac "h * ?lhs = h * ?rhs", simp add: h)
180 apply (simp add: right_diff_distrib diff_divide_distrib h)
181 apply (simp add: mult_assoc [symmetric])
182 apply (cases "n", simp)
183 apply (simp add: lemma_realpow_diff_sumr2 h
184 right_diff_distrib [symmetric] mult_assoc
185 del: realpow_Suc setsum_op_ivl_Suc of_nat_Suc)
186 apply (subst lemma_realpow_rev_sumr)
187 apply (subst sumr_diff_mult_const2)
189 apply (simp only: lemma_termdiff1 setsum_right_distrib)
190 apply (rule setsum_cong [OF refl])
191 apply (simp add: diff_minus [symmetric] less_iff_Suc_add)
193 apply (simp add: setsum_right_distrib lemma_realpow_diff_sumr2 mult_ac
194 del: setsum_op_ivl_Suc realpow_Suc)
195 apply (subst mult_assoc [symmetric], subst power_add [symmetric])
196 apply (simp add: mult_ac)
199 lemma real_setsum_nat_ivl_bounded2:
200 fixes K :: "'a::ordered_semidom"
201 assumes f: "\<And>p::nat. p < n \<Longrightarrow> f p \<le> K"
202 assumes K: "0 \<le> K"
203 shows "setsum f {0..<n-k} \<le> of_nat n * K"
204 apply (rule order_trans [OF setsum_mono])
206 apply (simp add: mult_right_mono K)
209 lemma lemma_termdiff3:
210 fixes h z :: "'a::{real_normed_field,recpower}"
211 assumes 1: "h \<noteq> 0"
212 assumes 2: "norm z \<le> K"
213 assumes 3: "norm (z + h) \<le> K"
214 shows "norm (((z + h) ^ n - z ^ n) / h - of_nat n * z ^ (n - Suc 0))
215 \<le> of_nat n * of_nat (n - Suc 0) * K ^ (n - 2) * norm h"
217 have "norm (((z + h) ^ n - z ^ n) / h - of_nat n * z ^ (n - Suc 0)) =
218 norm (\<Sum>p = 0..<n - Suc 0. \<Sum>q = 0..<n - Suc 0 - p.
219 (z + h) ^ q * z ^ (n - 2 - q)) * norm h"
220 apply (subst lemma_termdiff2 [OF 1])
221 apply (subst norm_mult)
222 apply (rule mult_commute)
224 also have "\<dots> \<le> of_nat n * (of_nat (n - Suc 0) * K ^ (n - 2)) * norm h"
225 proof (rule mult_right_mono [OF _ norm_ge_zero])
226 from norm_ge_zero 2 have K: "0 \<le> K" by (rule order_trans)
227 have le_Kn: "\<And>i j n. i + j = n \<Longrightarrow> norm ((z + h) ^ i * z ^ j) \<le> K ^ n"
229 apply (simp only: norm_mult norm_power power_add)
230 apply (intro mult_mono power_mono 2 3 norm_ge_zero zero_le_power K)
232 show "norm (\<Sum>p = 0..<n - Suc 0. \<Sum>q = 0..<n - Suc 0 - p.
233 (z + h) ^ q * z ^ (n - 2 - q))
234 \<le> of_nat n * (of_nat (n - Suc 0) * K ^ (n - 2))"
236 order_trans [OF norm_setsum]
237 real_setsum_nat_ivl_bounded2
241 apply (rule le_Kn, simp)
244 also have "\<dots> = of_nat n * of_nat (n - Suc 0) * K ^ (n - 2) * norm h"
245 by (simp only: mult_assoc)
246 finally show ?thesis .
249 lemma lemma_termdiff4:
250 fixes f :: "'a::{real_normed_field,recpower} \<Rightarrow>
251 'b::real_normed_vector"
252 assumes k: "0 < (k::real)"
253 assumes le: "\<And>h. \<lbrakk>h \<noteq> 0; norm h < k\<rbrakk> \<Longrightarrow> norm (f h) \<le> K * norm h"
255 proof (simp add: LIM_def, safe)
256 fix r::real assume r: "0 < r"
257 have zero_le_K: "0 \<le> K"
259 apply (cut_tac h="of_real (k/2)" in le, simp)
260 apply (simp del: of_real_divide)
261 apply (drule order_trans [OF norm_ge_zero])
262 apply (simp add: zero_le_mult_iff)
264 show "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> 0 \<and> norm x < s \<longrightarrow> norm (f x) < r)"
267 with k r le have "0 < k \<and> (\<forall>x. x \<noteq> 0 \<and> norm x < k \<longrightarrow> norm (f x) < r)"
269 thus "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> 0 \<and> norm x < s \<longrightarrow> norm (f x) < r)" ..
271 assume K_neq_zero: "K \<noteq> 0"
272 with zero_le_K have K: "0 < K" by simp
273 show "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> 0 \<and> norm x < s \<longrightarrow> norm (f x) < r)"
274 proof (rule exI, safe)
275 from k r K show "0 < min k (r * inverse K / 2)"
276 by (simp add: mult_pos_pos positive_imp_inverse_positive)
279 assume x1: "x \<noteq> 0" and x2: "norm x < min k (r * inverse K / 2)"
280 from x2 have x3: "norm x < k" and x4: "norm x < r * inverse K / 2"
282 from x1 x3 le have "norm (f x) \<le> K * norm x" by simp
283 also from x4 K have "K * norm x < K * (r * inverse K / 2)"
284 by (rule mult_strict_left_mono)
285 also have "\<dots> = r / 2"
286 using K_neq_zero by simp
287 also have "r / 2 < r"
289 finally show "norm (f x) < r" .
294 lemma lemma_termdiff5:
295 fixes g :: "'a::{recpower,real_normed_field} \<Rightarrow>
296 nat \<Rightarrow> 'b::banach"
297 assumes k: "0 < (k::real)"
298 assumes f: "summable f"
299 assumes le: "\<And>h n. \<lbrakk>h \<noteq> 0; norm h < k\<rbrakk> \<Longrightarrow> norm (g h n) \<le> f n * norm h"
300 shows "(\<lambda>h. suminf (g h)) -- 0 --> 0"
301 proof (rule lemma_termdiff4 [OF k])
302 fix h::'a assume "h \<noteq> 0" and "norm h < k"
303 hence A: "\<forall>n. norm (g h n) \<le> f n * norm h"
305 hence "\<exists>N. \<forall>n\<ge>N. norm (norm (g h n)) \<le> f n * norm h"
307 moreover from f have B: "summable (\<lambda>n. f n * norm h)"
308 by (rule summable_mult2)
309 ultimately have C: "summable (\<lambda>n. norm (g h n))"
310 by (rule summable_comparison_test)
311 hence "norm (suminf (g h)) \<le> (\<Sum>n. norm (g h n))"
312 by (rule summable_norm)
313 also from A C B have "(\<Sum>n. norm (g h n)) \<le> (\<Sum>n. f n * norm h)"
314 by (rule summable_le)
315 also from f have "(\<Sum>n. f n * norm h) = suminf f * norm h"
316 by (rule suminf_mult2 [symmetric])
317 finally show "norm (suminf (g h)) \<le> suminf f * norm h" .
321 text{* FIXME: Long proofs*}
324 fixes x :: "'a::{recpower,real_normed_field,banach}"
325 assumes 1: "summable (\<lambda>n. diffs (diffs c) n * K ^ n)"
326 assumes 2: "norm x < norm K"
327 shows "(\<lambda>h. \<Sum>n. c n * (((x + h) ^ n - x ^ n) / h
328 - of_nat n * x ^ (n - Suc 0))) -- 0 --> 0"
331 obtain r where r1: "norm x < r" and r2: "r < norm K" by fast
332 from norm_ge_zero r1 have r: "0 < r"
333 by (rule order_le_less_trans)
334 hence r_neq_0: "r \<noteq> 0" by simp
336 proof (rule lemma_termdiff5)
337 show "0 < r - norm x" using r1 by simp
339 from r r2 have "norm (of_real r::'a) < norm K"
341 with 1 have "summable (\<lambda>n. norm (diffs (diffs c) n * (of_real r ^ n)))"
342 by (rule powser_insidea)
343 hence "summable (\<lambda>n. diffs (diffs (\<lambda>n. norm (c n))) n * r ^ n)"
345 by (simp add: diffs_def norm_mult norm_power del: of_nat_Suc)
346 hence "summable (\<lambda>n. of_nat n * diffs (\<lambda>n. norm (c n)) n * r ^ (n - Suc 0))"
347 by (rule diffs_equiv [THEN sums_summable])
348 also have "(\<lambda>n. of_nat n * diffs (\<lambda>n. norm (c n)) n * r ^ (n - Suc 0))
349 = (\<lambda>n. diffs (%m. of_nat (m - Suc 0) * norm (c m) * inverse r) n * (r ^ n))"
351 apply (simp add: diffs_def)
352 apply (case_tac n, simp_all add: r_neq_0)
354 finally have "summable
355 (\<lambda>n. of_nat n * (of_nat (n - Suc 0) * norm (c n) * inverse r) * r ^ (n - Suc 0))"
356 by (rule diffs_equiv [THEN sums_summable])
358 "(\<lambda>n. of_nat n * (of_nat (n - Suc 0) * norm (c n) * inverse r) *
360 (\<lambda>n. norm (c n) * of_nat n * of_nat (n - Suc 0) * r ^ (n - 2))"
362 apply (case_tac "n", simp)
363 apply (case_tac "nat", simp)
364 apply (simp add: r_neq_0)
367 "summable (\<lambda>n. norm (c n) * of_nat n * of_nat (n - Suc 0) * r ^ (n - 2))" .
370 assume h: "h \<noteq> 0"
371 assume "norm h < r - norm x"
372 hence "norm x + norm h < r" by simp
373 with norm_triangle_ineq have xh: "norm (x + h) < r"
374 by (rule order_le_less_trans)
375 show "norm (c n * (((x + h) ^ n - x ^ n) / h - of_nat n * x ^ (n - Suc 0)))
376 \<le> norm (c n) * of_nat n * of_nat (n - Suc 0) * r ^ (n - 2) * norm h"
377 apply (simp only: norm_mult mult_assoc)
378 apply (rule mult_left_mono [OF _ norm_ge_zero])
379 apply (simp (no_asm) add: mult_assoc [symmetric])
380 apply (rule lemma_termdiff3)
382 apply (rule r1 [THEN order_less_imp_le])
383 apply (rule xh [THEN order_less_imp_le])
389 fixes K x :: "'a::{recpower,real_normed_field,banach}"
390 assumes 1: "summable (\<lambda>n. c n * K ^ n)"
391 assumes 2: "summable (\<lambda>n. (diffs c) n * K ^ n)"
392 assumes 3: "summable (\<lambda>n. (diffs (diffs c)) n * K ^ n)"
393 assumes 4: "norm x < norm K"
394 shows "DERIV (\<lambda>x. \<Sum>n. c n * x ^ n) x :> (\<Sum>n. (diffs c) n * x ^ n)"
395 proof (simp add: deriv_def, rule LIM_zero_cancel)
396 show "(\<lambda>h. (suminf (\<lambda>n. c n * (x + h) ^ n) - suminf (\<lambda>n. c n * x ^ n)) / h
397 - suminf (\<lambda>n. diffs c n * x ^ n)) -- 0 --> 0"
398 proof (rule LIM_equal2)
399 show "0 < norm K - norm x" by (simp add: less_diff_eq 4)
402 assume "h \<noteq> 0"
403 assume "norm (h - 0) < norm K - norm x"
404 hence "norm x + norm h < norm K" by simp
405 hence 5: "norm (x + h) < norm K"
406 by (rule norm_triangle_ineq [THEN order_le_less_trans])
407 have A: "summable (\<lambda>n. c n * x ^ n)"
408 by (rule powser_inside [OF 1 4])
409 have B: "summable (\<lambda>n. c n * (x + h) ^ n)"
410 by (rule powser_inside [OF 1 5])
411 have C: "summable (\<lambda>n. diffs c n * x ^ n)"
412 by (rule powser_inside [OF 2 4])
413 show "((\<Sum>n. c n * (x + h) ^ n) - (\<Sum>n. c n * x ^ n)) / h
414 - (\<Sum>n. diffs c n * x ^ n) =
415 (\<Sum>n. c n * (((x + h) ^ n - x ^ n) / h - of_nat n * x ^ (n - Suc 0)))"
416 apply (subst sums_unique [OF diffs_equiv [OF C]])
417 apply (subst suminf_diff [OF B A])
418 apply (subst suminf_divide [symmetric])
419 apply (rule summable_diff [OF B A])
420 apply (subst suminf_diff)
421 apply (rule summable_divide)
422 apply (rule summable_diff [OF B A])
423 apply (rule sums_summable [OF diffs_equiv [OF C]])
424 apply (rule_tac f="suminf" in arg_cong)
426 apply (simp add: ring_simps)
429 show "(\<lambda>h. \<Sum>n. c n * (((x + h) ^ n - x ^ n) / h -
430 of_nat n * x ^ (n - Suc 0))) -- 0 --> 0"
431 by (rule termdiffs_aux [OF 3 4])
436 subsection{*Exponential Function*}
439 exp :: "'a \<Rightarrow> 'a::{recpower,real_normed_field,banach}" where
440 "exp x = (\<Sum>n. x ^ n /\<^sub>R real (fact n))"
443 sin :: "real => real" where
444 "sin x = (\<Sum>n. (if even(n) then 0 else
445 (-1 ^ ((n - Suc 0) div 2))/(real (fact n))) * x ^ n)"
448 cos :: "real => real" where
449 "cos x = (\<Sum>n. (if even(n) then (-1 ^ (n div 2))/(real (fact n))
452 lemma summable_exp_generic:
453 fixes x :: "'a::{real_normed_algebra_1,recpower,banach}"
454 defines S_def: "S \<equiv> \<lambda>n. x ^ n /\<^sub>R real (fact n)"
457 have S_Suc: "\<And>n. S (Suc n) = (x * S n) /\<^sub>R real (Suc n)"
458 unfolding S_def by (simp add: power_Suc del: mult_Suc)
459 obtain r :: real where r0: "0 < r" and r1: "r < 1"
460 using dense [OF zero_less_one] by fast
461 obtain N :: nat where N: "norm x < real N * r"
462 using reals_Archimedean3 [OF r0] by fast
464 proof (rule ratio_test [rule_format])
466 assume n: "N \<le> n"
467 have "norm x \<le> real N * r"
468 using N by (rule order_less_imp_le)
469 also have "real N * r \<le> real (Suc n) * r"
470 using r0 n by (simp add: mult_right_mono)
471 finally have "norm x * norm (S n) \<le> real (Suc n) * r * norm (S n)"
472 using norm_ge_zero by (rule mult_right_mono)
473 hence "norm (x * S n) \<le> real (Suc n) * r * norm (S n)"
474 by (rule order_trans [OF norm_mult_ineq])
475 hence "norm (x * S n) / real (Suc n) \<le> r * norm (S n)"
476 by (simp add: pos_divide_le_eq mult_ac)
477 thus "norm (S (Suc n)) \<le> r * norm (S n)"
478 by (simp add: S_Suc norm_scaleR inverse_eq_divide)
482 lemma summable_norm_exp:
483 fixes x :: "'a::{real_normed_algebra_1,recpower,banach}"
484 shows "summable (\<lambda>n. norm (x ^ n /\<^sub>R real (fact n)))"
485 proof (rule summable_norm_comparison_test [OF exI, rule_format])
486 show "summable (\<lambda>n. norm x ^ n /\<^sub>R real (fact n))"
487 by (rule summable_exp_generic)
489 fix n show "norm (x ^ n /\<^sub>R real (fact n)) \<le> norm x ^ n /\<^sub>R real (fact n)"
490 by (simp add: norm_scaleR norm_power_ineq)
493 lemma summable_exp: "summable (%n. inverse (real (fact n)) * x ^ n)"
494 by (insert summable_exp_generic [where x=x], simp)
499 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) *
501 apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test)
502 apply (rule_tac [2] summable_exp)
503 apply (rule_tac x = 0 in exI)
504 apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
510 -1 ^ (n div 2)/(real (fact n)) else 0) * x ^ n)"
511 apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test)
512 apply (rule_tac [2] summable_exp)
513 apply (rule_tac x = 0 in exI)
514 apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
517 lemma lemma_STAR_sin:
519 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * 0 ^ n = 0"
520 by (induct "n", auto)
522 lemma lemma_STAR_cos:
524 -1 ^ (n div 2)/(real (fact n)) * 0 ^ n = 0"
525 by (induct "n", auto)
527 lemma lemma_STAR_cos1:
529 (-1) ^ (n div 2)/(real (fact n)) * 0 ^ n = 0"
530 by (induct "n", auto)
532 lemma lemma_STAR_cos2:
533 "(\<Sum>n=1..<n. if even n then -1 ^ (n div 2)/(real (fact n)) * 0 ^ n
536 apply (case_tac [2] "n", auto)
539 lemma exp_converges: "(\<lambda>n. x ^ n /\<^sub>R real (fact n)) sums exp x"
540 unfolding exp_def by (rule summable_exp_generic [THEN summable_sums])
543 "(%n. (if even n then 0
544 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) *
546 unfolding sin_def by (rule summable_sin [THEN summable_sums])
549 "(%n. (if even n then
550 -1 ^ (n div 2)/(real (fact n))
551 else 0) * x ^ n) sums cos(x)"
552 unfolding cos_def by (rule summable_cos [THEN summable_sums])
555 subsection{*Formal Derivatives of Exp, Sin, and Cos Series*}
558 "diffs (%n. inverse(real (fact n))) = (%n. inverse(real (fact n)))"
559 by (simp add: diffs_def mult_assoc [symmetric] real_of_nat_def of_nat_mult
560 del: mult_Suc of_nat_Suc)
562 lemma diffs_of_real: "diffs (\<lambda>n. of_real (f n)) = (\<lambda>n. of_real (diffs f n))"
563 by (simp add: diffs_def)
566 "diffs(%n. if even n then 0
567 else -1 ^ ((n - Suc 0) div 2)/(real (fact n)))
568 = (%n. if even n then
569 -1 ^ (n div 2)/(real (fact n))
572 simp add: diffs_def divide_inverse real_of_nat_def of_nat_mult
573 simp del: mult_Suc of_nat_Suc)
576 "diffs(%n. if even n then 0
577 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) n
579 -1 ^ (n div 2)/(real (fact n))
581 by (simp only: sin_fdiffs)
584 "diffs(%n. if even n then
585 -1 ^ (n div 2)/(real (fact n)) else 0)
586 = (%n. - (if even n then 0
587 else -1 ^ ((n - Suc 0)div 2)/(real (fact n))))"
589 simp add: diffs_def divide_inverse odd_Suc_mult_two_ex real_of_nat_def of_nat_mult
590 simp del: mult_Suc of_nat_Suc)
594 "diffs(%n. if even n then
595 -1 ^ (n div 2)/(real (fact n)) else 0) n
596 = - (if even n then 0
597 else -1 ^ ((n - Suc 0)div 2)/(real (fact n)))"
598 by (simp only: cos_fdiffs)
600 text{*Now at last we can get the derivatives of exp, sin and cos*}
602 lemma lemma_sin_minus:
603 "- sin x = (\<Sum>n. - ((if even n then 0
604 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * x ^ n))"
605 by (auto intro!: sums_unique sums_minus sin_converges)
607 lemma lemma_exp_ext: "exp = (\<lambda>x. \<Sum>n. x ^ n /\<^sub>R real (fact n))"
608 by (auto intro!: ext simp add: exp_def)
610 lemma DERIV_exp [simp]: "DERIV exp x :> exp(x)"
611 apply (simp add: exp_def)
612 apply (subst lemma_exp_ext)
613 apply (subgoal_tac "DERIV (\<lambda>u. \<Sum>n. of_real (inverse (real (fact n))) * u ^ n) x :> (\<Sum>n. diffs (\<lambda>n. of_real (inverse (real (fact n)))) n * x ^ n)")
614 apply (rule_tac [2] K = "of_real (1 + norm x)" in termdiffs)
615 apply (simp_all only: diffs_of_real scaleR_conv_of_real exp_fdiffs)
616 apply (rule exp_converges [THEN sums_summable, unfolded scaleR_conv_of_real])+
617 apply (simp del: of_real_add)
623 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) *
625 by (auto intro!: ext simp add: sin_def)
629 (if even n then -1 ^ (n div 2)/(real (fact n)) else 0) *
631 by (auto intro!: ext simp add: cos_def)
633 lemma DERIV_sin [simp]: "DERIV sin x :> cos(x)"
634 apply (simp add: cos_def)
635 apply (subst lemma_sin_ext)
636 apply (auto simp add: sin_fdiffs2 [symmetric])
637 apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs)
638 apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs)
641 lemma DERIV_cos [simp]: "DERIV cos x :> -sin(x)"
642 apply (subst lemma_cos_ext)
643 apply (auto simp add: lemma_sin_minus cos_fdiffs2 [symmetric] minus_mult_left)
644 apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs)
645 apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs diffs_minus)
648 lemma isCont_exp [simp]: "isCont exp x"
649 by (rule DERIV_exp [THEN DERIV_isCont])
651 lemma isCont_sin [simp]: "isCont sin x"
652 by (rule DERIV_sin [THEN DERIV_isCont])
654 lemma isCont_cos [simp]: "isCont cos x"
655 by (rule DERIV_cos [THEN DERIV_isCont])
658 subsection{*Properties of the Exponential Function*}
661 fixes f :: "nat \<Rightarrow> 'a::{real_normed_algebra_1,recpower}"
662 shows "(\<Sum>n. f n * 0 ^ n) = f 0"
664 have "(\<Sum>n = 0..<1. f n * 0 ^ n) = (\<Sum>n. f n * 0 ^ n)"
665 by (rule sums_unique [OF series_zero], simp add: power_0_left)
669 lemma exp_zero [simp]: "exp 0 = 1"
670 unfolding exp_def by (simp add: scaleR_conv_of_real powser_zero)
672 lemma setsum_cl_ivl_Suc2:
673 "(\<Sum>i=m..Suc n. f i) = (if Suc n < m then 0 else f m + (\<Sum>i=m..n. f (Suc i)))"
674 by (simp add: setsum_head_Suc setsum_shift_bounds_cl_Suc_ivl
675 del: setsum_cl_ivl_Suc)
677 lemma exp_series_add:
678 fixes x y :: "'a::{real_field,recpower}"
679 defines S_def: "S \<equiv> \<lambda>x n. x ^ n /\<^sub>R real (fact n)"
680 shows "S (x + y) n = (\<Sum>i=0..n. S x i * S y (n - i))"
684 unfolding S_def by simp
687 have S_Suc: "\<And>x n. S x (Suc n) = (x * S x n) /\<^sub>R real (Suc n)"
688 unfolding S_def by (simp add: power_Suc del: mult_Suc)
689 hence times_S: "\<And>x n. x * S x n = real (Suc n) *\<^sub>R S x (Suc n)"
692 have "real (Suc n) *\<^sub>R S (x + y) (Suc n) = (x + y) * S (x + y) n"
693 by (simp only: times_S)
694 also have "\<dots> = (x + y) * (\<Sum>i=0..n. S x i * S y (n-i))"
696 also have "\<dots> = x * (\<Sum>i=0..n. S x i * S y (n-i))
697 + y * (\<Sum>i=0..n. S x i * S y (n-i))"
698 by (rule left_distrib)
699 also have "\<dots> = (\<Sum>i=0..n. (x * S x i) * S y (n-i))
700 + (\<Sum>i=0..n. S x i * (y * S y (n-i)))"
701 by (simp only: setsum_right_distrib mult_ac)
702 also have "\<dots> = (\<Sum>i=0..n. real (Suc i) *\<^sub>R (S x (Suc i) * S y (n-i)))
703 + (\<Sum>i=0..n. real (Suc n-i) *\<^sub>R (S x i * S y (Suc n-i)))"
704 by (simp add: times_S Suc_diff_le)
705 also have "(\<Sum>i=0..n. real (Suc i) *\<^sub>R (S x (Suc i) * S y (n-i))) =
706 (\<Sum>i=0..Suc n. real i *\<^sub>R (S x i * S y (Suc n-i)))"
707 by (subst setsum_cl_ivl_Suc2, simp)
708 also have "(\<Sum>i=0..n. real (Suc n-i) *\<^sub>R (S x i * S y (Suc n-i))) =
709 (\<Sum>i=0..Suc n. real (Suc n-i) *\<^sub>R (S x i * S y (Suc n-i)))"
710 by (subst setsum_cl_ivl_Suc, simp)
711 also have "(\<Sum>i=0..Suc n. real i *\<^sub>R (S x i * S y (Suc n-i))) +
712 (\<Sum>i=0..Suc n. real (Suc n-i) *\<^sub>R (S x i * S y (Suc n-i))) =
713 (\<Sum>i=0..Suc n. real (Suc n) *\<^sub>R (S x i * S y (Suc n-i)))"
714 by (simp only: setsum_addf [symmetric] scaleR_left_distrib [symmetric]
715 real_of_nat_add [symmetric], simp)
716 also have "\<dots> = real (Suc n) *\<^sub>R (\<Sum>i=0..Suc n. S x i * S y (Suc n-i))"
717 by (simp only: scaleR_right.setsum)
719 "S (x + y) (Suc n) = (\<Sum>i=0..Suc n. S x i * S y (Suc n - i))"
720 by (simp add: scaleR_cancel_left del: setsum_cl_ivl_Suc)
723 lemma exp_add: "exp (x + y) = exp x * exp y"
725 by (simp only: Cauchy_product summable_norm_exp exp_series_add)
727 lemma exp_of_real: "exp (of_real x) = of_real (exp x)"
729 apply (subst of_real.suminf)
730 apply (rule summable_exp_generic)
731 apply (simp add: scaleR_conv_of_real)
734 lemma exp_ge_add_one_self_aux: "0 \<le> (x::real) ==> (1 + x) \<le> exp(x)"
735 apply (drule order_le_imp_less_or_eq, auto)
736 apply (simp add: exp_def)
737 apply (rule real_le_trans)
738 apply (rule_tac [2] n = 2 and f = "(%n. inverse (real (fact n)) * x ^ n)" in series_pos_le)
739 apply (auto intro: summable_exp simp add: numeral_2_eq_2 zero_le_mult_iff)
742 lemma exp_gt_one [simp]: "0 < (x::real) ==> 1 < exp x"
743 apply (rule order_less_le_trans)
744 apply (rule_tac [2] exp_ge_add_one_self_aux, auto)
747 lemma DERIV_exp_add_const: "DERIV (%x. exp (x + y)) x :> exp(x + y)"
749 have "DERIV (exp \<circ> (\<lambda>x. x + y)) x :> exp (x + y) * (1+0)"
750 by (fast intro: DERIV_chain DERIV_add DERIV_exp DERIV_ident DERIV_const)
751 thus ?thesis by (simp add: o_def)
754 lemma DERIV_exp_minus [simp]: "DERIV (%x. exp (-x)) x :> - exp(-x)"
756 have "DERIV (exp \<circ> uminus) x :> exp (- x) * - 1"
757 by (fast intro: DERIV_chain DERIV_minus DERIV_exp DERIV_ident)
758 thus ?thesis by (simp add: o_def)
761 lemma DERIV_exp_exp_zero [simp]: "DERIV (%x. exp (x + y) * exp (- x)) x :> 0"
763 have "DERIV (\<lambda>x. exp (x + y) * exp (- x)) x
764 :> exp (x + y) * exp (- x) + - exp (- x) * exp (x + y)"
765 by (fast intro: DERIV_exp_add_const DERIV_exp_minus DERIV_mult)
766 thus ?thesis by (simp add: mult_commute)
769 lemma exp_add_mult_minus [simp]: "exp(x + y)*exp(-x) = exp(y::real)"
771 have "\<forall>x. DERIV (%x. exp (x + y) * exp (- x)) x :> 0" by simp
772 hence "exp (x + y) * exp (- x) = exp (0 + y) * exp (- 0)"
773 by (rule DERIV_isconst_all)
777 lemma exp_mult_minus [simp]: "exp x * exp(-x) = 1"
778 by (simp add: exp_add [symmetric])
780 lemma exp_mult_minus2 [simp]: "exp(-x)*exp(x) = 1"
781 by (simp add: mult_commute)
784 lemma exp_minus: "exp(-x) = inverse(exp(x))"
785 by (auto intro: inverse_unique [symmetric])
787 text{*Proof: because every exponential can be seen as a square.*}
788 lemma exp_ge_zero [simp]: "0 \<le> exp (x::real)"
789 apply (rule_tac t = x in real_sum_of_halves [THEN subst])
790 apply (subst exp_add, auto)
793 lemma exp_not_eq_zero [simp]: "exp x \<noteq> 0"
794 apply (cut_tac x = x in exp_mult_minus2)
795 apply (auto simp del: exp_mult_minus2)
798 lemma exp_gt_zero [simp]: "0 < exp (x::real)"
799 by (simp add: order_less_le)
801 lemma inv_exp_gt_zero [simp]: "0 < inverse(exp x::real)"
802 by (auto intro: positive_imp_inverse_positive)
804 lemma abs_exp_cancel [simp]: "\<bar>exp x::real\<bar> = exp x"
807 lemma exp_real_of_nat_mult: "exp(real n * x) = exp(x) ^ n"
809 apply (auto simp add: real_of_nat_Suc right_distrib exp_add mult_commute)
812 lemma exp_diff: "exp(x - y) = exp(x)/(exp y)"
813 apply (simp add: diff_minus divide_inverse)
814 apply (simp (no_asm) add: exp_add exp_minus)
820 assumes xy: "x < y" shows "exp x < exp y"
822 from xy have "1 < exp (y + - x)"
823 by (rule real_less_sum_gt_zero [THEN exp_gt_one])
824 hence "exp x * inverse (exp x) < exp y * inverse (exp x)"
825 by (auto simp add: exp_add exp_minus)
827 by (simp add: divide_inverse [symmetric] pos_less_divide_eq
831 lemma exp_less_cancel: "exp (x::real) < exp y ==> x < y"
832 apply (simp add: linorder_not_le [symmetric])
833 apply (auto simp add: order_le_less exp_less_mono)
836 lemma exp_less_cancel_iff [iff]: "(exp(x::real) < exp(y)) = (x < y)"
837 by (auto intro: exp_less_mono exp_less_cancel)
839 lemma exp_le_cancel_iff [iff]: "(exp(x::real) \<le> exp(y)) = (x \<le> y)"
840 by (auto simp add: linorder_not_less [symmetric])
842 lemma exp_inj_iff [iff]: "(exp (x::real) = exp y) = (x = y)"
843 by (simp add: order_eq_iff)
845 lemma lemma_exp_total: "1 \<le> y ==> \<exists>x. 0 \<le> x & x \<le> y - 1 & exp(x::real) = y"
847 apply (auto intro: isCont_exp simp add: le_diff_eq)
848 apply (subgoal_tac "1 + (y - 1) \<le> exp (y - 1)")
850 apply (rule exp_ge_add_one_self_aux, simp)
853 lemma exp_total: "0 < (y::real) ==> \<exists>x. exp x = y"
854 apply (rule_tac x = 1 and y = y in linorder_cases)
855 apply (drule order_less_imp_le [THEN lemma_exp_total])
856 apply (rule_tac [2] x = 0 in exI)
857 apply (frule_tac [3] real_inverse_gt_one)
858 apply (drule_tac [4] order_less_imp_le [THEN lemma_exp_total], auto)
859 apply (rule_tac x = "-x" in exI)
860 apply (simp add: exp_minus)
864 subsection{*Properties of the Logarithmic Function*}
867 ln :: "real => real" where
868 "ln x = (THE u. exp u = x)"
870 lemma ln_exp [simp]: "ln (exp x) = x"
871 by (simp add: ln_def)
873 lemma exp_ln [simp]: "0 < x \<Longrightarrow> exp (ln x) = x"
874 by (auto dest: exp_total)
876 lemma exp_ln_iff [simp]: "(exp (ln x) = x) = (0 < x)"
877 apply (auto dest: exp_total)
878 apply (erule subst, simp)
881 lemma ln_mult: "[| 0 < x; 0 < y |] ==> ln(x * y) = ln(x) + ln(y)"
882 apply (rule exp_inj_iff [THEN iffD1])
883 apply (simp add: exp_add exp_ln mult_pos_pos)
886 lemma ln_inj_iff[simp]: "[| 0 < x; 0 < y |] ==> (ln x = ln y) = (x = y)"
887 apply (simp only: exp_ln_iff [symmetric])
892 lemma ln_one[simp]: "ln 1 = 0"
893 by (rule exp_inj_iff [THEN iffD1], auto)
895 lemma ln_inverse: "0 < x ==> ln(inverse x) = - ln x"
896 apply (rule_tac a1 = "ln x" in add_left_cancel [THEN iffD1])
897 apply (auto simp add: positive_imp_inverse_positive ln_mult [symmetric])
901 "[|0 < x; 0 < y|] ==> ln(x/y) = ln x - ln y"
902 apply (simp add: divide_inverse)
903 apply (auto simp add: positive_imp_inverse_positive ln_mult ln_inverse)
906 lemma ln_less_cancel_iff[simp]: "[| 0 < x; 0 < y|] ==> (ln x < ln y) = (x < y)"
907 apply (simp only: exp_ln_iff [symmetric])
912 lemma ln_le_cancel_iff[simp]: "[| 0 < x; 0 < y|] ==> (ln x \<le> ln y) = (x \<le> y)"
913 by (auto simp add: linorder_not_less [symmetric])
915 lemma ln_realpow: "0 < x ==> ln(x ^ n) = real n * ln(x)"
916 by (auto dest!: exp_total simp add: exp_real_of_nat_mult [symmetric])
918 lemma ln_add_one_self_le_self [simp]: "0 \<le> x ==> ln(1 + x) \<le> x"
919 apply (rule ln_exp [THEN subst])
920 apply (rule ln_le_cancel_iff [THEN iffD2])
921 apply (auto simp add: exp_ge_add_one_self_aux)
924 lemma ln_less_self [simp]: "0 < x ==> ln x < x"
925 apply (rule order_less_le_trans)
926 apply (rule_tac [2] ln_add_one_self_le_self)
927 apply (rule ln_less_cancel_iff [THEN iffD2], auto)
930 lemma ln_ge_zero [simp]:
931 assumes x: "1 \<le> x" shows "0 \<le> ln x"
933 have "0 < x" using x by arith
934 hence "exp 0 \<le> exp (ln x)"
936 thus ?thesis by (simp only: exp_le_cancel_iff)
939 lemma ln_ge_zero_imp_ge_one:
940 assumes ln: "0 \<le> ln x"
944 from ln have "ln 1 \<le> ln x" by simp
945 thus ?thesis by (simp add: x del: ln_one)
948 lemma ln_ge_zero_iff [simp]: "0 < x ==> (0 \<le> ln x) = (1 \<le> x)"
949 by (blast intro: ln_ge_zero ln_ge_zero_imp_ge_one)
951 lemma ln_less_zero_iff [simp]: "0 < x ==> (ln x < 0) = (x < 1)"
952 by (insert ln_ge_zero_iff [of x], arith)
955 assumes x: "1 < x" shows "0 < ln x"
957 have "0 < x" using x by arith
958 hence "exp 0 < exp (ln x)" by (simp add: x)
959 thus ?thesis by (simp only: exp_less_cancel_iff)
962 lemma ln_gt_zero_imp_gt_one:
963 assumes ln: "0 < ln x"
967 from ln have "ln 1 < ln x" by simp
968 thus ?thesis by (simp add: x del: ln_one)
971 lemma ln_gt_zero_iff [simp]: "0 < x ==> (0 < ln x) = (1 < x)"
972 by (blast intro: ln_gt_zero ln_gt_zero_imp_gt_one)
974 lemma ln_eq_zero_iff [simp]: "0 < x ==> (ln x = 0) = (x = 1)"
975 by (insert ln_less_zero_iff [of x] ln_gt_zero_iff [of x], arith)
977 lemma ln_less_zero: "[| 0 < x; x < 1 |] ==> ln x < 0"
980 lemma exp_ln_eq: "exp u = x ==> ln x = u"
983 lemma isCont_ln: "0 < x \<Longrightarrow> isCont ln x"
984 apply (subgoal_tac "isCont ln (exp (ln x))", simp)
985 apply (rule isCont_inverse_function [where f=exp], simp_all)
988 lemma DERIV_ln: "0 < x \<Longrightarrow> DERIV ln x :> inverse x"
989 apply (rule DERIV_inverse_function [where f=exp and a=0 and b="x+1"])
990 apply (erule lemma_DERIV_subst [OF DERIV_exp exp_ln])
991 apply (simp_all add: abs_if isCont_ln)
995 subsection{*Basic Properties of the Trigonometric Functions*}
997 lemma sin_zero [simp]: "sin 0 = 0"
998 unfolding sin_def by (simp add: powser_zero)
1000 lemma cos_zero [simp]: "cos 0 = 1"
1001 unfolding cos_def by (simp add: powser_zero)
1003 lemma DERIV_sin_sin_mult [simp]:
1004 "DERIV (%x. sin(x)*sin(x)) x :> cos(x) * sin(x) + cos(x) * sin(x)"
1005 by (rule DERIV_mult, auto)
1007 lemma DERIV_sin_sin_mult2 [simp]:
1008 "DERIV (%x. sin(x)*sin(x)) x :> 2 * cos(x) * sin(x)"
1009 apply (cut_tac x = x in DERIV_sin_sin_mult)
1010 apply (auto simp add: mult_assoc)
1013 lemma DERIV_sin_realpow2 [simp]:
1014 "DERIV (%x. (sin x)\<twosuperior>) x :> cos(x) * sin(x) + cos(x) * sin(x)"
1015 by (auto simp add: numeral_2_eq_2 real_mult_assoc [symmetric])
1017 lemma DERIV_sin_realpow2a [simp]:
1018 "DERIV (%x. (sin x)\<twosuperior>) x :> 2 * cos(x) * sin(x)"
1019 by (auto simp add: numeral_2_eq_2)
1021 lemma DERIV_cos_cos_mult [simp]:
1022 "DERIV (%x. cos(x)*cos(x)) x :> -sin(x) * cos(x) + -sin(x) * cos(x)"
1023 by (rule DERIV_mult, auto)
1025 lemma DERIV_cos_cos_mult2 [simp]:
1026 "DERIV (%x. cos(x)*cos(x)) x :> -2 * cos(x) * sin(x)"
1027 apply (cut_tac x = x in DERIV_cos_cos_mult)
1028 apply (auto simp add: mult_ac)
1031 lemma DERIV_cos_realpow2 [simp]:
1032 "DERIV (%x. (cos x)\<twosuperior>) x :> -sin(x) * cos(x) + -sin(x) * cos(x)"
1033 by (auto simp add: numeral_2_eq_2 real_mult_assoc [symmetric])
1035 lemma DERIV_cos_realpow2a [simp]:
1036 "DERIV (%x. (cos x)\<twosuperior>) x :> -2 * cos(x) * sin(x)"
1037 by (auto simp add: numeral_2_eq_2)
1039 lemma lemma_DERIV_subst: "[| DERIV f x :> D; D = E |] ==> DERIV f x :> E"
1042 lemma DERIV_cos_realpow2b: "DERIV (%x. (cos x)\<twosuperior>) x :> -(2 * cos(x) * sin(x))"
1043 apply (rule lemma_DERIV_subst)
1044 apply (rule DERIV_cos_realpow2a, auto)
1048 lemma DERIV_cos_cos_mult3 [simp]:
1049 "DERIV (%x. cos(x)*cos(x)) x :> -(2 * cos(x) * sin(x))"
1050 apply (rule lemma_DERIV_subst)
1051 apply (rule DERIV_cos_cos_mult2, auto)
1054 lemma DERIV_sin_circle_all:
1055 "\<forall>x. DERIV (%x. (sin x)\<twosuperior> + (cos x)\<twosuperior>) x :>
1056 (2*cos(x)*sin(x) - 2*cos(x)*sin(x))"
1057 apply (simp only: diff_minus, safe)
1058 apply (rule DERIV_add)
1059 apply (auto simp add: numeral_2_eq_2)
1062 lemma DERIV_sin_circle_all_zero [simp]:
1063 "\<forall>x. DERIV (%x. (sin x)\<twosuperior> + (cos x)\<twosuperior>) x :> 0"
1064 by (cut_tac DERIV_sin_circle_all, auto)
1066 lemma sin_cos_squared_add [simp]: "((sin x)\<twosuperior>) + ((cos x)\<twosuperior>) = 1"
1067 apply (cut_tac x = x and y = 0 in DERIV_sin_circle_all_zero [THEN DERIV_isconst_all])
1068 apply (auto simp add: numeral_2_eq_2)
1071 lemma sin_cos_squared_add2 [simp]: "((cos x)\<twosuperior>) + ((sin x)\<twosuperior>) = 1"
1072 apply (subst add_commute)
1073 apply (simp (no_asm) del: realpow_Suc)
1076 lemma sin_cos_squared_add3 [simp]: "cos x * cos x + sin x * sin x = 1"
1077 apply (cut_tac x = x in sin_cos_squared_add2)
1078 apply (auto simp add: numeral_2_eq_2)
1081 lemma sin_squared_eq: "(sin x)\<twosuperior> = 1 - (cos x)\<twosuperior>"
1082 apply (rule_tac a1 = "(cos x)\<twosuperior>" in add_right_cancel [THEN iffD1])
1083 apply (simp del: realpow_Suc)
1086 lemma cos_squared_eq: "(cos x)\<twosuperior> = 1 - (sin x)\<twosuperior>"
1087 apply (rule_tac a1 = "(sin x)\<twosuperior>" in add_right_cancel [THEN iffD1])
1088 apply (simp del: realpow_Suc)
1091 lemma real_gt_one_ge_zero_add_less: "[| 1 < x; 0 \<le> y |] ==> 1 < x + (y::real)"
1094 lemma abs_sin_le_one [simp]: "\<bar>sin x\<bar> \<le> 1"
1095 by (rule power2_le_imp_le, simp_all add: sin_squared_eq)
1097 lemma sin_ge_minus_one [simp]: "-1 \<le> sin x"
1098 apply (insert abs_sin_le_one [of x])
1099 apply (simp add: abs_le_iff del: abs_sin_le_one)
1102 lemma sin_le_one [simp]: "sin x \<le> 1"
1103 apply (insert abs_sin_le_one [of x])
1104 apply (simp add: abs_le_iff del: abs_sin_le_one)
1107 lemma abs_cos_le_one [simp]: "\<bar>cos x\<bar> \<le> 1"
1108 by (rule power2_le_imp_le, simp_all add: cos_squared_eq)
1110 lemma cos_ge_minus_one [simp]: "-1 \<le> cos x"
1111 apply (insert abs_cos_le_one [of x])
1112 apply (simp add: abs_le_iff del: abs_cos_le_one)
1115 lemma cos_le_one [simp]: "cos x \<le> 1"
1116 apply (insert abs_cos_le_one [of x])
1117 apply (simp add: abs_le_iff del: abs_cos_le_one)
1120 lemma DERIV_fun_pow: "DERIV g x :> m ==>
1121 DERIV (%x. (g x) ^ n) x :> real n * (g x) ^ (n - 1) * m"
1122 apply (rule lemma_DERIV_subst)
1123 apply (rule_tac f = "(%x. x ^ n)" in DERIV_chain2)
1124 apply (rule DERIV_pow, auto)
1127 lemma DERIV_fun_exp:
1128 "DERIV g x :> m ==> DERIV (%x. exp(g x)) x :> exp(g x) * m"
1129 apply (rule lemma_DERIV_subst)
1130 apply (rule_tac f = exp in DERIV_chain2)
1131 apply (rule DERIV_exp, auto)
1134 lemma DERIV_fun_sin:
1135 "DERIV g x :> m ==> DERIV (%x. sin(g x)) x :> cos(g x) * m"
1136 apply (rule lemma_DERIV_subst)
1137 apply (rule_tac f = sin in DERIV_chain2)
1138 apply (rule DERIV_sin, auto)
1141 lemma DERIV_fun_cos:
1142 "DERIV g x :> m ==> DERIV (%x. cos(g x)) x :> -sin(g x) * m"
1143 apply (rule lemma_DERIV_subst)
1144 apply (rule_tac f = cos in DERIV_chain2)
1145 apply (rule DERIV_cos, auto)
1148 lemmas DERIV_intros = DERIV_ident DERIV_const DERIV_cos DERIV_cmult
1149 DERIV_sin DERIV_exp DERIV_inverse DERIV_pow
1150 DERIV_add DERIV_diff DERIV_mult DERIV_minus
1151 DERIV_inverse_fun DERIV_quotient DERIV_fun_pow
1152 DERIV_fun_exp DERIV_fun_sin DERIV_fun_cos
1155 lemma lemma_DERIV_sin_cos_add:
1157 DERIV (%x. (sin (x + y) - (sin x * cos y + cos x * sin y)) ^ 2 +
1158 (cos (x + y) - (cos x * cos y - sin x * sin y)) ^ 2) x :> 0"
1159 apply (safe, rule lemma_DERIV_subst)
1160 apply (best intro!: DERIV_intros intro: DERIV_chain2)
1161 --{*replaces the old @{text DERIV_tac}*}
1162 apply (auto simp add: diff_minus left_distrib right_distrib mult_ac add_ac)
1165 lemma sin_cos_add [simp]:
1166 "(sin (x + y) - (sin x * cos y + cos x * sin y)) ^ 2 +
1167 (cos (x + y) - (cos x * cos y - sin x * sin y)) ^ 2 = 0"
1168 apply (cut_tac y = 0 and x = x and y7 = y
1169 in lemma_DERIV_sin_cos_add [THEN DERIV_isconst_all])
1170 apply (auto simp add: numeral_2_eq_2)
1173 lemma sin_add: "sin (x + y) = sin x * cos y + cos x * sin y"
1174 apply (cut_tac x = x and y = y in sin_cos_add)
1175 apply (simp del: sin_cos_add)
1178 lemma cos_add: "cos (x + y) = cos x * cos y - sin x * sin y"
1179 apply (cut_tac x = x and y = y in sin_cos_add)
1180 apply (simp del: sin_cos_add)
1183 lemma lemma_DERIV_sin_cos_minus:
1184 "\<forall>x. DERIV (%x. (sin(-x) + (sin x)) ^ 2 + (cos(-x) - (cos x)) ^ 2) x :> 0"
1185 apply (safe, rule lemma_DERIV_subst)
1186 apply (best intro!: DERIV_intros intro: DERIV_chain2)
1187 apply (auto simp add: diff_minus left_distrib right_distrib mult_ac add_ac)
1190 lemma sin_cos_minus [simp]:
1191 "(sin(-x) + (sin x)) ^ 2 + (cos(-x) - (cos x)) ^ 2 = 0"
1192 apply (cut_tac y = 0 and x = x
1193 in lemma_DERIV_sin_cos_minus [THEN DERIV_isconst_all])
1197 lemma sin_minus [simp]: "sin (-x) = -sin(x)"
1198 apply (cut_tac x = x in sin_cos_minus)
1199 apply (simp del: sin_cos_minus)
1202 lemma cos_minus [simp]: "cos (-x) = cos(x)"
1203 apply (cut_tac x = x in sin_cos_minus)
1204 apply (simp del: sin_cos_minus)
1207 lemma sin_diff: "sin (x - y) = sin x * cos y - cos x * sin y"
1208 by (simp add: diff_minus sin_add)
1210 lemma sin_diff2: "sin (x - y) = cos y * sin x - sin y * cos x"
1211 by (simp add: sin_diff mult_commute)
1213 lemma cos_diff: "cos (x - y) = cos x * cos y + sin x * sin y"
1214 by (simp add: diff_minus cos_add)
1216 lemma cos_diff2: "cos (x - y) = cos y * cos x + sin y * sin x"
1217 by (simp add: cos_diff mult_commute)
1219 lemma sin_double [simp]: "sin(2 * x) = 2* sin x * cos x"
1220 by (cut_tac x = x and y = x in sin_add, auto)
1223 lemma cos_double: "cos(2* x) = ((cos x)\<twosuperior>) - ((sin x)\<twosuperior>)"
1224 apply (cut_tac x = x and y = x in cos_add)
1225 apply (simp add: power2_eq_square)
1229 subsection{*The Constant Pi*}
1233 "pi = 2 * (THE x. 0 \<le> (x::real) & x \<le> 2 & cos x = 0)"
1235 text{*Show that there's a least positive @{term x} with @{term "cos(x) = 0"};
1239 "(%n. -1 ^ n /(real (fact (2 * n + 1))) * x ^ (2 * n + 1))
1242 have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
1244 else -1 ^ ((k - Suc 0) div 2) / real (fact k)) *
1248 by (rule sin_converges [THEN sums_summable, THEN sums_group], simp)
1249 thus ?thesis by (simp add: mult_ac)
1252 lemma sin_gt_zero: "[|0 < x; x < 2 |] ==> 0 < sin x"
1254 "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
1255 -1 ^ k / real (fact (2 * k + 1)) * x ^ (2 * k + 1))
1256 sums (\<Sum>n. -1 ^ n / real (fact (2 * n + 1)) * x ^ (2 * n + 1))")
1258 apply (rule sin_paired [THEN sums_summable, THEN sums_group], simp)
1259 apply (rotate_tac 2)
1260 apply (drule sin_paired [THEN sums_unique, THEN ssubst])
1261 apply (auto simp del: fact_Suc realpow_Suc)
1262 apply (frule sums_unique)
1263 apply (auto simp del: fact_Suc realpow_Suc)
1264 apply (rule_tac n1 = 0 in series_pos_less [THEN [2] order_le_less_trans])
1265 apply (auto simp del: fact_Suc realpow_Suc)
1266 apply (erule sums_summable)
1267 apply (case_tac "m=0")
1268 apply (simp (no_asm_simp))
1269 apply (subgoal_tac "6 * (x * (x * x) / real (Suc (Suc (Suc (Suc (Suc (Suc 0))))))) < 6 * x")
1270 apply (simp only: mult_less_cancel_left, simp)
1271 apply (simp (no_asm_simp) add: numeral_2_eq_2 [symmetric] mult_assoc [symmetric])
1272 apply (subgoal_tac "x*x < 2*3", simp)
1273 apply (rule mult_strict_mono)
1274 apply (auto simp add: real_0_less_add_iff real_of_nat_Suc simp del: fact_Suc)
1275 apply (subst fact_Suc)
1276 apply (subst fact_Suc)
1277 apply (subst fact_Suc)
1278 apply (subst fact_Suc)
1279 apply (subst real_of_nat_mult)
1280 apply (subst real_of_nat_mult)
1281 apply (subst real_of_nat_mult)
1282 apply (subst real_of_nat_mult)
1283 apply (simp (no_asm) add: divide_inverse del: fact_Suc)
1284 apply (auto simp add: mult_assoc [symmetric] simp del: fact_Suc)
1285 apply (rule_tac c="real (Suc (Suc (4*m)))" in mult_less_imp_less_right)
1286 apply (auto simp add: mult_assoc simp del: fact_Suc)
1287 apply (rule_tac c="real (Suc (Suc (Suc (4*m))))" in mult_less_imp_less_right)
1288 apply (auto simp add: mult_assoc mult_less_cancel_left simp del: fact_Suc)
1289 apply (subgoal_tac "x * (x * x ^ (4*m)) = (x ^ (4*m)) * (x * x)")
1290 apply (erule ssubst)+
1291 apply (auto simp del: fact_Suc)
1292 apply (subgoal_tac "0 < x ^ (4 * m) ")
1293 prefer 2 apply (simp only: zero_less_power)
1294 apply (simp (no_asm_simp) add: mult_less_cancel_left)
1295 apply (rule mult_strict_mono)
1296 apply (simp_all (no_asm_simp))
1299 lemma sin_gt_zero1: "[|0 < x; x < 2 |] ==> 0 < sin x"
1300 by (auto intro: sin_gt_zero)
1302 lemma cos_double_less_one: "[| 0 < x; x < 2 |] ==> cos (2 * x) < 1"
1303 apply (cut_tac x = x in sin_gt_zero1)
1304 apply (auto simp add: cos_squared_eq cos_double)
1308 "(%n. -1 ^ n /(real (fact (2 * n))) * x ^ (2 * n)) sums cos x"
1310 have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
1311 (if even k then -1 ^ (k div 2) / real (fact k) else 0) *
1315 by (rule cos_converges [THEN sums_summable, THEN sums_group], simp)
1316 thus ?thesis by (simp add: mult_ac)
1319 lemma fact_lemma: "real (n::nat) * 4 = real (4 * n)"
1322 lemma cos_two_less_zero [simp]: "cos (2) < 0"
1323 apply (cut_tac x = 2 in cos_paired)
1324 apply (drule sums_minus)
1325 apply (rule neg_less_iff_less [THEN iffD1])
1326 apply (frule sums_unique, auto)
1328 "\<Sum>n=0..< Suc(Suc(Suc 0)). - (-1 ^ n / (real(fact (2*n))) * 2 ^ (2*n))"
1329 in order_less_trans)
1330 apply (simp (no_asm) add: fact_num_eq_if realpow_num_eq_if del: fact_Suc realpow_Suc)
1331 apply (simp (no_asm) add: mult_assoc del: setsum_op_ivl_Suc)
1332 apply (rule sumr_pos_lt_pair)
1333 apply (erule sums_summable, safe)
1334 apply (simp (no_asm) add: divide_inverse real_0_less_add_iff mult_assoc [symmetric]
1336 apply (rule real_mult_inverse_cancel2)
1337 apply (rule real_of_nat_fact_gt_zero)+
1338 apply (simp (no_asm) add: mult_assoc [symmetric] del: fact_Suc)
1339 apply (subst fact_lemma)
1340 apply (subst fact_Suc [of "Suc (Suc (Suc (Suc (Suc (Suc (Suc (4 * d)))))))"])
1341 apply (simp only: real_of_nat_mult)
1342 apply (rule mult_strict_mono, force)
1343 apply (rule_tac [3] real_of_nat_ge_zero)
1344 prefer 2 apply force
1345 apply (rule real_of_nat_less_iff [THEN iffD2])
1346 apply (rule fact_less_mono, auto)
1349 lemmas cos_two_neq_zero [simp] = cos_two_less_zero [THEN less_imp_neq]
1350 lemmas cos_two_le_zero [simp] = cos_two_less_zero [THEN order_less_imp_le]
1352 lemma cos_is_zero: "EX! x. 0 \<le> x & x \<le> 2 & cos x = 0"
1353 apply (subgoal_tac "\<exists>x. 0 \<le> x & x \<le> 2 & cos x = 0")
1354 apply (rule_tac [2] IVT2)
1355 apply (auto intro: DERIV_isCont DERIV_cos)
1356 apply (cut_tac x = xa and y = y in linorder_less_linear)
1358 apply (subgoal_tac " (\<forall>x. cos differentiable x) & (\<forall>x. isCont cos x) ")
1359 apply (auto intro: DERIV_cos DERIV_isCont simp add: differentiable_def)
1360 apply (drule_tac f = cos in Rolle)
1361 apply (drule_tac [5] f = cos in Rolle)
1362 apply (auto dest!: DERIV_cos [THEN DERIV_unique] simp add: differentiable_def)
1363 apply (drule_tac y1 = xa in order_le_less_trans [THEN sin_gt_zero])
1364 apply (assumption, rule_tac y=y in order_less_le_trans, simp_all)
1365 apply (drule_tac y1 = y in order_le_less_trans [THEN sin_gt_zero], assumption, simp_all)
1368 lemma pi_half: "pi/2 = (THE x. 0 \<le> x & x \<le> 2 & cos x = 0)"
1369 by (simp add: pi_def)
1371 lemma cos_pi_half [simp]: "cos (pi / 2) = 0"
1372 by (simp add: pi_half cos_is_zero [THEN theI'])
1374 lemma pi_half_gt_zero [simp]: "0 < pi / 2"
1375 apply (rule order_le_neq_trans)
1376 apply (simp add: pi_half cos_is_zero [THEN theI'])
1377 apply (rule notI, drule arg_cong [where f=cos], simp)
1380 lemmas pi_half_neq_zero [simp] = pi_half_gt_zero [THEN less_imp_neq, symmetric]
1381 lemmas pi_half_ge_zero [simp] = pi_half_gt_zero [THEN order_less_imp_le]
1383 lemma pi_half_less_two [simp]: "pi / 2 < 2"
1384 apply (rule order_le_neq_trans)
1385 apply (simp add: pi_half cos_is_zero [THEN theI'])
1386 apply (rule notI, drule arg_cong [where f=cos], simp)
1389 lemmas pi_half_neq_two [simp] = pi_half_less_two [THEN less_imp_neq]
1390 lemmas pi_half_le_two [simp] = pi_half_less_two [THEN order_less_imp_le]
1392 lemma pi_gt_zero [simp]: "0 < pi"
1393 by (insert pi_half_gt_zero, simp)
1395 lemma pi_ge_zero [simp]: "0 \<le> pi"
1396 by (rule pi_gt_zero [THEN order_less_imp_le])
1398 lemma pi_neq_zero [simp]: "pi \<noteq> 0"
1399 by (rule pi_gt_zero [THEN less_imp_neq, THEN not_sym])
1401 lemma pi_not_less_zero [simp]: "\<not> pi < 0"
1402 by (simp add: linorder_not_less)
1404 lemma minus_pi_half_less_zero [simp]: "-(pi/2) < 0"
1407 lemma sin_pi_half [simp]: "sin(pi/2) = 1"
1408 apply (cut_tac x = "pi/2" in sin_cos_squared_add2)
1409 apply (cut_tac sin_gt_zero [OF pi_half_gt_zero pi_half_less_two])
1410 apply (simp add: power2_eq_square)
1413 lemma cos_pi [simp]: "cos pi = -1"
1414 by (cut_tac x = "pi/2" and y = "pi/2" in cos_add, simp)
1416 lemma sin_pi [simp]: "sin pi = 0"
1417 by (cut_tac x = "pi/2" and y = "pi/2" in sin_add, simp)
1419 lemma sin_cos_eq: "sin x = cos (pi/2 - x)"
1420 by (simp add: diff_minus cos_add)
1421 declare sin_cos_eq [symmetric, simp]
1423 lemma minus_sin_cos_eq: "-sin x = cos (x + pi/2)"
1424 by (simp add: cos_add)
1425 declare minus_sin_cos_eq [symmetric, simp]
1427 lemma cos_sin_eq: "cos x = sin (pi/2 - x)"
1428 by (simp add: diff_minus sin_add)
1429 declare cos_sin_eq [symmetric, simp]
1431 lemma sin_periodic_pi [simp]: "sin (x + pi) = - sin x"
1432 by (simp add: sin_add)
1434 lemma sin_periodic_pi2 [simp]: "sin (pi + x) = - sin x"
1435 by (simp add: sin_add)
1437 lemma cos_periodic_pi [simp]: "cos (x + pi) = - cos x"
1438 by (simp add: cos_add)
1440 lemma sin_periodic [simp]: "sin (x + 2*pi) = sin x"
1441 by (simp add: sin_add cos_double)
1443 lemma cos_periodic [simp]: "cos (x + 2*pi) = cos x"
1444 by (simp add: cos_add cos_double)
1446 lemma cos_npi [simp]: "cos (real n * pi) = -1 ^ n"
1448 apply (auto simp add: real_of_nat_Suc left_distrib)
1451 lemma cos_npi2 [simp]: "cos (pi * real n) = -1 ^ n"
1453 have "cos (pi * real n) = cos (real n * pi)" by (simp only: mult_commute)
1454 also have "... = -1 ^ n" by (rule cos_npi)
1455 finally show ?thesis .
1458 lemma sin_npi [simp]: "sin (real (n::nat) * pi) = 0"
1460 apply (auto simp add: real_of_nat_Suc left_distrib)
1463 lemma sin_npi2 [simp]: "sin (pi * real (n::nat)) = 0"
1464 by (simp add: mult_commute [of pi])
1466 lemma cos_two_pi [simp]: "cos (2 * pi) = 1"
1467 by (simp add: cos_double)
1469 lemma sin_two_pi [simp]: "sin (2 * pi) = 0"
1472 lemma sin_gt_zero2: "[| 0 < x; x < pi/2 |] ==> 0 < sin x"
1473 apply (rule sin_gt_zero, assumption)
1474 apply (rule order_less_trans, assumption)
1475 apply (rule pi_half_less_two)
1478 lemma sin_less_zero:
1479 assumes lb: "- pi/2 < x" and "x < 0" shows "sin x < 0"
1481 have "0 < sin (- x)" using prems by (simp only: sin_gt_zero2)
1482 thus ?thesis by simp
1485 lemma pi_less_4: "pi < 4"
1486 by (cut_tac pi_half_less_two, auto)
1488 lemma cos_gt_zero: "[| 0 < x; x < pi/2 |] ==> 0 < cos x"
1489 apply (cut_tac pi_less_4)
1490 apply (cut_tac f = cos and a = 0 and b = x and y = 0 in IVT2_objl, safe, simp_all)
1491 apply (cut_tac cos_is_zero, safe)
1492 apply (rename_tac y z)
1493 apply (drule_tac x = y in spec)
1494 apply (drule_tac x = "pi/2" in spec, simp)
1497 lemma cos_gt_zero_pi: "[| -(pi/2) < x; x < pi/2 |] ==> 0 < cos x"
1498 apply (rule_tac x = x and y = 0 in linorder_cases)
1499 apply (rule cos_minus [THEN subst])
1500 apply (rule cos_gt_zero)
1501 apply (auto intro: cos_gt_zero)
1504 lemma cos_ge_zero: "[| -(pi/2) \<le> x; x \<le> pi/2 |] ==> 0 \<le> cos x"
1505 apply (auto simp add: order_le_less cos_gt_zero_pi)
1506 apply (subgoal_tac "x = pi/2", auto)
1509 lemma sin_gt_zero_pi: "[| 0 < x; x < pi |] ==> 0 < sin x"
1510 apply (subst sin_cos_eq)
1511 apply (rotate_tac 1)
1512 apply (drule real_sum_of_halves [THEN ssubst])
1513 apply (auto intro!: cos_gt_zero_pi simp del: sin_cos_eq [symmetric])
1516 lemma sin_ge_zero: "[| 0 \<le> x; x \<le> pi |] ==> 0 \<le> sin x"
1517 by (auto simp add: order_le_less sin_gt_zero_pi)
1519 lemma cos_total: "[| -1 \<le> y; y \<le> 1 |] ==> EX! x. 0 \<le> x & x \<le> pi & (cos x = y)"
1520 apply (subgoal_tac "\<exists>x. 0 \<le> x & x \<le> pi & cos x = y")
1521 apply (rule_tac [2] IVT2)
1522 apply (auto intro: order_less_imp_le DERIV_isCont DERIV_cos)
1523 apply (cut_tac x = xa and y = y in linorder_less_linear)
1524 apply (rule ccontr, auto)
1525 apply (drule_tac f = cos in Rolle)
1526 apply (drule_tac [5] f = cos in Rolle)
1527 apply (auto intro: order_less_imp_le DERIV_isCont DERIV_cos
1528 dest!: DERIV_cos [THEN DERIV_unique]
1529 simp add: differentiable_def)
1530 apply (auto dest: sin_gt_zero_pi [OF order_le_less_trans order_less_le_trans])
1534 "[| -1 \<le> y; y \<le> 1 |] ==> EX! x. -(pi/2) \<le> x & x \<le> pi/2 & (sin x = y)"
1536 apply (subgoal_tac "\<forall>x. (- (pi/2) \<le> x & x \<le> pi/2 & (sin x = y)) = (0 \<le> (x + pi/2) & (x + pi/2) \<le> pi & (cos (x + pi/2) = -y))")
1537 apply (erule contrapos_np)
1538 apply (simp del: minus_sin_cos_eq [symmetric])
1539 apply (cut_tac y="-y" in cos_total, simp) apply simp
1541 apply (rule_tac a = "x - (pi/2)" in ex1I)
1542 apply (simp (no_asm) add: add_assoc)
1543 apply (rotate_tac 3)
1544 apply (drule_tac x = "xa + pi/2" in spec, safe, simp_all)
1547 lemma reals_Archimedean4:
1548 "[| 0 < y; 0 \<le> x |] ==> \<exists>n. real n * y \<le> x & x < real (Suc n) * y"
1549 apply (auto dest!: reals_Archimedean3)
1550 apply (drule_tac x = x in spec, clarify)
1551 apply (subgoal_tac "x < real(LEAST m::nat. x < real m * y) * y")
1552 prefer 2 apply (erule LeastI)
1553 apply (case_tac "LEAST m::nat. x < real m * y", simp)
1554 apply (subgoal_tac "~ x < real nat * y")
1555 prefer 2 apply (rule not_less_Least, simp, force)
1558 (* Pre Isabelle99-2 proof was simpler- numerals arithmetic
1559 now causes some unwanted re-arrangements of literals! *)
1560 lemma cos_zero_lemma:
1561 "[| 0 \<le> x; cos x = 0 |] ==>
1562 \<exists>n::nat. ~even n & x = real n * (pi/2)"
1563 apply (drule pi_gt_zero [THEN reals_Archimedean4], safe)
1564 apply (subgoal_tac "0 \<le> x - real n * pi &
1565 (x - real n * pi) \<le> pi & (cos (x - real n * pi) = 0) ")
1566 apply (auto simp add: compare_rls)
1567 prefer 3 apply (simp add: cos_diff)
1568 prefer 2 apply (simp add: real_of_nat_Suc left_distrib)
1569 apply (simp add: cos_diff)
1570 apply (subgoal_tac "EX! x. 0 \<le> x & x \<le> pi & cos x = 0")
1571 apply (rule_tac [2] cos_total, safe)
1572 apply (drule_tac x = "x - real n * pi" in spec)
1573 apply (drule_tac x = "pi/2" in spec)
1574 apply (simp add: cos_diff)
1575 apply (rule_tac x = "Suc (2 * n)" in exI)
1576 apply (simp add: real_of_nat_Suc left_distrib, auto)
1579 lemma sin_zero_lemma:
1580 "[| 0 \<le> x; sin x = 0 |] ==>
1581 \<exists>n::nat. even n & x = real n * (pi/2)"
1582 apply (subgoal_tac "\<exists>n::nat. ~ even n & x + pi/2 = real n * (pi/2) ")
1583 apply (clarify, rule_tac x = "n - 1" in exI)
1584 apply (force simp add: odd_Suc_mult_two_ex real_of_nat_Suc left_distrib)
1585 apply (rule cos_zero_lemma)
1586 apply (simp_all add: add_increasing)
1592 ((\<exists>n::nat. ~even n & (x = real n * (pi/2))) |
1593 (\<exists>n::nat. ~even n & (x = -(real n * (pi/2)))))"
1595 apply (cut_tac linorder_linear [of 0 x], safe)
1596 apply (drule cos_zero_lemma, assumption+)
1597 apply (cut_tac x="-x" in cos_zero_lemma, simp, simp)
1598 apply (force simp add: minus_equation_iff [of x])
1599 apply (auto simp only: odd_Suc_mult_two_ex real_of_nat_Suc left_distrib)
1600 apply (auto simp add: cos_add)
1603 (* ditto: but to a lesser extent *)
1606 ((\<exists>n::nat. even n & (x = real n * (pi/2))) |
1607 (\<exists>n::nat. even n & (x = -(real n * (pi/2)))))"
1609 apply (cut_tac linorder_linear [of 0 x], safe)
1610 apply (drule sin_zero_lemma, assumption+)
1611 apply (cut_tac x="-x" in sin_zero_lemma, simp, simp, safe)
1612 apply (force simp add: minus_equation_iff [of x])
1613 apply (auto simp add: even_mult_two_ex)
1617 subsection{*Tangent*}
1620 tan :: "real => real" where
1621 "tan x = (sin x)/(cos x)"
1623 lemma tan_zero [simp]: "tan 0 = 0"
1624 by (simp add: tan_def)
1626 lemma tan_pi [simp]: "tan pi = 0"
1627 by (simp add: tan_def)
1629 lemma tan_npi [simp]: "tan (real (n::nat) * pi) = 0"
1630 by (simp add: tan_def)
1632 lemma tan_minus [simp]: "tan (-x) = - tan x"
1633 by (simp add: tan_def minus_mult_left)
1635 lemma tan_periodic [simp]: "tan (x + 2*pi) = tan x"
1636 by (simp add: tan_def)
1638 lemma lemma_tan_add1:
1639 "[| cos x \<noteq> 0; cos y \<noteq> 0 |]
1640 ==> 1 - tan(x)*tan(y) = cos (x + y)/(cos x * cos y)"
1641 apply (simp add: tan_def divide_inverse)
1642 apply (auto simp del: inverse_mult_distrib
1643 simp add: inverse_mult_distrib [symmetric] mult_ac)
1644 apply (rule_tac c1 = "cos x * cos y" in real_mult_right_cancel [THEN subst])
1645 apply (auto simp del: inverse_mult_distrib
1646 simp add: mult_assoc left_diff_distrib cos_add)
1650 "[| cos x \<noteq> 0; cos y \<noteq> 0 |]
1651 ==> tan x + tan y = sin(x + y)/(cos x * cos y)"
1652 apply (simp add: tan_def)
1653 apply (rule_tac c1 = "cos x * cos y" in real_mult_right_cancel [THEN subst])
1654 apply (auto simp add: mult_assoc left_distrib)
1655 apply (simp add: sin_add)
1659 "[| cos x \<noteq> 0; cos y \<noteq> 0; cos (x + y) \<noteq> 0 |]
1660 ==> tan(x + y) = (tan(x) + tan(y))/(1 - tan(x) * tan(y))"
1661 apply (simp (no_asm_simp) add: add_tan_eq lemma_tan_add1)
1662 apply (simp add: tan_def)
1666 "[| cos x \<noteq> 0; cos (2 * x) \<noteq> 0 |]
1667 ==> tan (2 * x) = (2 * tan x)/(1 - (tan(x) ^ 2))"
1668 apply (insert tan_add [of x x])
1669 apply (simp add: mult_2 [symmetric])
1670 apply (auto simp add: numeral_2_eq_2)
1673 lemma tan_gt_zero: "[| 0 < x; x < pi/2 |] ==> 0 < tan x"
1674 by (simp add: tan_def zero_less_divide_iff sin_gt_zero2 cos_gt_zero_pi)
1676 lemma tan_less_zero:
1677 assumes lb: "- pi/2 < x" and "x < 0" shows "tan x < 0"
1679 have "0 < tan (- x)" using prems by (simp only: tan_gt_zero)
1680 thus ?thesis by simp
1683 lemma lemma_DERIV_tan:
1684 "cos x \<noteq> 0 ==> DERIV (%x. sin(x)/cos(x)) x :> inverse((cos x)\<twosuperior>)"
1685 apply (rule lemma_DERIV_subst)
1686 apply (best intro!: DERIV_intros intro: DERIV_chain2)
1687 apply (auto simp add: divide_inverse numeral_2_eq_2)
1690 lemma DERIV_tan [simp]: "cos x \<noteq> 0 ==> DERIV tan x :> inverse((cos x)\<twosuperior>)"
1691 by (auto dest: lemma_DERIV_tan simp add: tan_def [symmetric])
1693 lemma isCont_tan [simp]: "cos x \<noteq> 0 ==> isCont tan x"
1694 by (rule DERIV_tan [THEN DERIV_isCont])
1696 lemma LIM_cos_div_sin [simp]: "(%x. cos(x)/sin(x)) -- pi/2 --> 0"
1697 apply (subgoal_tac "(\<lambda>x. cos x * inverse (sin x)) -- pi * inverse 2 --> 0*1")
1698 apply (simp add: divide_inverse [symmetric])
1699 apply (rule LIM_mult)
1700 apply (rule_tac [2] inverse_1 [THEN subst])
1701 apply (rule_tac [2] LIM_inverse)
1702 apply (simp_all add: divide_inverse [symmetric])
1703 apply (simp_all only: isCont_def [symmetric] cos_pi_half [symmetric] sin_pi_half [symmetric])
1704 apply (blast intro!: DERIV_isCont DERIV_sin DERIV_cos)+
1707 lemma lemma_tan_total: "0 < y ==> \<exists>x. 0 < x & x < pi/2 & y < tan x"
1708 apply (cut_tac LIM_cos_div_sin)
1709 apply (simp only: LIM_def)
1710 apply (drule_tac x = "inverse y" in spec, safe, force)
1711 apply (drule_tac ?d1.0 = s in pi_half_gt_zero [THEN [2] real_lbound_gt_zero], safe)
1712 apply (rule_tac x = "(pi/2) - e" in exI)
1713 apply (simp (no_asm_simp))
1714 apply (drule_tac x = "(pi/2) - e" in spec)
1715 apply (auto simp add: tan_def)
1716 apply (rule inverse_less_iff_less [THEN iffD1])
1717 apply (auto simp add: divide_inverse)
1718 apply (rule real_mult_order)
1719 apply (subgoal_tac [3] "0 < sin e & 0 < cos e")
1720 apply (auto intro: cos_gt_zero sin_gt_zero2 simp add: mult_commute)
1723 lemma tan_total_pos: "0 \<le> y ==> \<exists>x. 0 \<le> x & x < pi/2 & tan x = y"
1724 apply (frule order_le_imp_less_or_eq, safe)
1725 prefer 2 apply force
1726 apply (drule lemma_tan_total, safe)
1727 apply (cut_tac f = tan and a = 0 and b = x and y = y in IVT_objl)
1728 apply (auto intro!: DERIV_tan [THEN DERIV_isCont])
1729 apply (drule_tac y = xa in order_le_imp_less_or_eq)
1730 apply (auto dest: cos_gt_zero)
1733 lemma lemma_tan_total1: "\<exists>x. -(pi/2) < x & x < (pi/2) & tan x = y"
1734 apply (cut_tac linorder_linear [of 0 y], safe)
1735 apply (drule tan_total_pos)
1736 apply (cut_tac [2] y="-y" in tan_total_pos, safe)
1737 apply (rule_tac [3] x = "-x" in exI)
1738 apply (auto intro!: exI)
1741 lemma tan_total: "EX! x. -(pi/2) < x & x < (pi/2) & tan x = y"
1742 apply (cut_tac y = y in lemma_tan_total1, auto)
1743 apply (cut_tac x = xa and y = y in linorder_less_linear, auto)
1744 apply (subgoal_tac [2] "\<exists>z. y < z & z < xa & DERIV tan z :> 0")
1745 apply (subgoal_tac "\<exists>z. xa < z & z < y & DERIV tan z :> 0")
1746 apply (rule_tac [4] Rolle)
1747 apply (rule_tac [2] Rolle)
1748 apply (auto intro!: DERIV_tan DERIV_isCont exI
1749 simp add: differentiable_def)
1750 txt{*Now, simulate TRYALL*}
1751 apply (rule_tac [!] DERIV_tan asm_rl)
1752 apply (auto dest!: DERIV_unique [OF _ DERIV_tan]
1753 simp add: cos_gt_zero_pi [THEN less_imp_neq, THEN not_sym])
1757 subsection {* Inverse Trigonometric Functions *}
1760 arcsin :: "real => real" where
1761 "arcsin y = (THE x. -(pi/2) \<le> x & x \<le> pi/2 & sin x = y)"
1764 arccos :: "real => real" where
1765 "arccos y = (THE x. 0 \<le> x & x \<le> pi & cos x = y)"
1768 arctan :: "real => real" where
1769 "arctan y = (THE x. -(pi/2) < x & x < pi/2 & tan x = y)"
1772 "[| -1 \<le> y; y \<le> 1 |]
1773 ==> -(pi/2) \<le> arcsin y &
1774 arcsin y \<le> pi/2 & sin(arcsin y) = y"
1775 unfolding arcsin_def by (rule theI' [OF sin_total])
1778 "[| -1 \<le> y; y \<le> 1 |]
1779 ==> -(pi/2) \<le> arcsin y & arcsin y \<le> pi & sin(arcsin y) = y"
1780 apply (drule (1) arcsin)
1781 apply (force intro: order_trans)
1784 lemma sin_arcsin [simp]: "[| -1 \<le> y; y \<le> 1 |] ==> sin(arcsin y) = y"
1785 by (blast dest: arcsin)
1787 lemma arcsin_bounded:
1788 "[| -1 \<le> y; y \<le> 1 |] ==> -(pi/2) \<le> arcsin y & arcsin y \<le> pi/2"
1789 by (blast dest: arcsin)
1791 lemma arcsin_lbound: "[| -1 \<le> y; y \<le> 1 |] ==> -(pi/2) \<le> arcsin y"
1792 by (blast dest: arcsin)
1794 lemma arcsin_ubound: "[| -1 \<le> y; y \<le> 1 |] ==> arcsin y \<le> pi/2"
1795 by (blast dest: arcsin)
1797 lemma arcsin_lt_bounded:
1798 "[| -1 < y; y < 1 |] ==> -(pi/2) < arcsin y & arcsin y < pi/2"
1799 apply (frule order_less_imp_le)
1800 apply (frule_tac y = y in order_less_imp_le)
1801 apply (frule arcsin_bounded)
1803 apply (drule_tac y = "arcsin y" in order_le_imp_less_or_eq)
1804 apply (drule_tac [2] y = "pi/2" in order_le_imp_less_or_eq, safe)
1805 apply (drule_tac [!] f = sin in arg_cong, auto)
1808 lemma arcsin_sin: "[|-(pi/2) \<le> x; x \<le> pi/2 |] ==> arcsin(sin x) = x"
1809 apply (unfold arcsin_def)
1810 apply (rule the1_equality)
1811 apply (rule sin_total, auto)
1815 "[| -1 \<le> y; y \<le> 1 |]
1816 ==> 0 \<le> arccos y & arccos y \<le> pi & cos(arccos y) = y"
1817 unfolding arccos_def by (rule theI' [OF cos_total])
1819 lemma cos_arccos [simp]: "[| -1 \<le> y; y \<le> 1 |] ==> cos(arccos y) = y"
1820 by (blast dest: arccos)
1822 lemma arccos_bounded: "[| -1 \<le> y; y \<le> 1 |] ==> 0 \<le> arccos y & arccos y \<le> pi"
1823 by (blast dest: arccos)
1825 lemma arccos_lbound: "[| -1 \<le> y; y \<le> 1 |] ==> 0 \<le> arccos y"
1826 by (blast dest: arccos)
1828 lemma arccos_ubound: "[| -1 \<le> y; y \<le> 1 |] ==> arccos y \<le> pi"
1829 by (blast dest: arccos)
1831 lemma arccos_lt_bounded:
1832 "[| -1 < y; y < 1 |]
1833 ==> 0 < arccos y & arccos y < pi"
1834 apply (frule order_less_imp_le)
1835 apply (frule_tac y = y in order_less_imp_le)
1836 apply (frule arccos_bounded, auto)
1837 apply (drule_tac y = "arccos y" in order_le_imp_less_or_eq)
1838 apply (drule_tac [2] y = pi in order_le_imp_less_or_eq, auto)
1839 apply (drule_tac [!] f = cos in arg_cong, auto)
1842 lemma arccos_cos: "[|0 \<le> x; x \<le> pi |] ==> arccos(cos x) = x"
1843 apply (simp add: arccos_def)
1844 apply (auto intro!: the1_equality cos_total)
1847 lemma arccos_cos2: "[|x \<le> 0; -pi \<le> x |] ==> arccos(cos x) = -x"
1848 apply (simp add: arccos_def)
1849 apply (auto intro!: the1_equality cos_total)
1852 lemma cos_arcsin: "\<lbrakk>-1 \<le> x; x \<le> 1\<rbrakk> \<Longrightarrow> cos (arcsin x) = sqrt (1 - x\<twosuperior>)"
1853 apply (subgoal_tac "x\<twosuperior> \<le> 1")
1854 apply (rule power2_eq_imp_eq)
1855 apply (simp add: cos_squared_eq)
1856 apply (rule cos_ge_zero)
1857 apply (erule (1) arcsin_lbound)
1858 apply (erule (1) arcsin_ubound)
1860 apply (subgoal_tac "\<bar>x\<bar>\<twosuperior> \<le> 1\<twosuperior>", simp)
1861 apply (rule power_mono, simp, simp)
1864 lemma sin_arccos: "\<lbrakk>-1 \<le> x; x \<le> 1\<rbrakk> \<Longrightarrow> sin (arccos x) = sqrt (1 - x\<twosuperior>)"
1865 apply (subgoal_tac "x\<twosuperior> \<le> 1")
1866 apply (rule power2_eq_imp_eq)
1867 apply (simp add: sin_squared_eq)
1868 apply (rule sin_ge_zero)
1869 apply (erule (1) arccos_lbound)
1870 apply (erule (1) arccos_ubound)
1872 apply (subgoal_tac "\<bar>x\<bar>\<twosuperior> \<le> 1\<twosuperior>", simp)
1873 apply (rule power_mono, simp, simp)
1876 lemma arctan [simp]:
1877 "- (pi/2) < arctan y & arctan y < pi/2 & tan (arctan y) = y"
1878 unfolding arctan_def by (rule theI' [OF tan_total])
1880 lemma tan_arctan: "tan(arctan y) = y"
1883 lemma arctan_bounded: "- (pi/2) < arctan y & arctan y < pi/2"
1884 by (auto simp only: arctan)
1886 lemma arctan_lbound: "- (pi/2) < arctan y"
1889 lemma arctan_ubound: "arctan y < pi/2"
1890 by (auto simp only: arctan)
1893 "[|-(pi/2) < x; x < pi/2 |] ==> arctan(tan x) = x"
1894 apply (unfold arctan_def)
1895 apply (rule the1_equality)
1896 apply (rule tan_total, auto)
1899 lemma arctan_zero_zero [simp]: "arctan 0 = 0"
1900 by (insert arctan_tan [of 0], simp)
1902 lemma cos_arctan_not_zero [simp]: "cos(arctan x) \<noteq> 0"
1903 apply (auto simp add: cos_zero_iff)
1904 apply (case_tac "n")
1905 apply (case_tac [3] "n")
1906 apply (cut_tac [2] y = x in arctan_ubound)
1907 apply (cut_tac [4] y = x in arctan_lbound)
1908 apply (auto simp add: real_of_nat_Suc left_distrib mult_less_0_iff)
1911 lemma tan_sec: "cos x \<noteq> 0 ==> 1 + tan(x) ^ 2 = inverse(cos x) ^ 2"
1912 apply (rule power_inverse [THEN subst])
1913 apply (rule_tac c1 = "(cos x)\<twosuperior>" in real_mult_right_cancel [THEN iffD1])
1914 apply (auto dest: field_power_not_zero
1915 simp add: power_mult_distrib left_distrib power_divide tan_def
1916 mult_assoc power_inverse [symmetric]
1917 simp del: realpow_Suc)
1920 lemma isCont_inverse_function2:
1921 fixes f g :: "real \<Rightarrow> real" shows
1922 "\<lbrakk>a < x; x < b;
1923 \<forall>z. a \<le> z \<and> z \<le> b \<longrightarrow> g (f z) = z;
1924 \<forall>z. a \<le> z \<and> z \<le> b \<longrightarrow> isCont f z\<rbrakk>
1925 \<Longrightarrow> isCont g (f x)"
1926 apply (rule isCont_inverse_function
1927 [where f=f and d="min (x - a) (b - x)"])
1928 apply (simp_all add: abs_le_iff)
1931 lemma isCont_arcsin: "\<lbrakk>-1 < x; x < 1\<rbrakk> \<Longrightarrow> isCont arcsin x"
1932 apply (subgoal_tac "isCont arcsin (sin (arcsin x))", simp)
1933 apply (rule isCont_inverse_function2 [where f=sin])
1934 apply (erule (1) arcsin_lt_bounded [THEN conjunct1])
1935 apply (erule (1) arcsin_lt_bounded [THEN conjunct2])
1936 apply (fast intro: arcsin_sin, simp)
1939 lemma isCont_arccos: "\<lbrakk>-1 < x; x < 1\<rbrakk> \<Longrightarrow> isCont arccos x"
1940 apply (subgoal_tac "isCont arccos (cos (arccos x))", simp)
1941 apply (rule isCont_inverse_function2 [where f=cos])
1942 apply (erule (1) arccos_lt_bounded [THEN conjunct1])
1943 apply (erule (1) arccos_lt_bounded [THEN conjunct2])
1944 apply (fast intro: arccos_cos, simp)
1947 lemma isCont_arctan: "isCont arctan x"
1948 apply (rule arctan_lbound [of x, THEN dense, THEN exE], clarify)
1949 apply (rule arctan_ubound [of x, THEN dense, THEN exE], clarify)
1950 apply (subgoal_tac "isCont arctan (tan (arctan x))", simp)
1951 apply (erule (1) isCont_inverse_function2 [where f=tan])
1952 apply (clarify, rule arctan_tan)
1953 apply (erule (1) order_less_le_trans)
1954 apply (erule (1) order_le_less_trans)
1955 apply (clarify, rule isCont_tan)
1956 apply (rule less_imp_neq [symmetric])
1957 apply (rule cos_gt_zero_pi)
1958 apply (erule (1) order_less_le_trans)
1959 apply (erule (1) order_le_less_trans)
1963 "\<lbrakk>-1 < x; x < 1\<rbrakk> \<Longrightarrow> DERIV arcsin x :> inverse (sqrt (1 - x\<twosuperior>))"
1964 apply (rule DERIV_inverse_function [where f=sin and a="-1" and b="1"])
1965 apply (rule lemma_DERIV_subst [OF DERIV_sin])
1966 apply (simp add: cos_arcsin)
1967 apply (subgoal_tac "\<bar>x\<bar>\<twosuperior> < 1\<twosuperior>", simp)
1968 apply (rule power_strict_mono, simp, simp, simp)
1972 apply (erule (1) isCont_arcsin)
1976 "\<lbrakk>-1 < x; x < 1\<rbrakk> \<Longrightarrow> DERIV arccos x :> inverse (- sqrt (1 - x\<twosuperior>))"
1977 apply (rule DERIV_inverse_function [where f=cos and a="-1" and b="1"])
1978 apply (rule lemma_DERIV_subst [OF DERIV_cos])
1979 apply (simp add: sin_arccos)
1980 apply (subgoal_tac "\<bar>x\<bar>\<twosuperior> < 1\<twosuperior>", simp)
1981 apply (rule power_strict_mono, simp, simp, simp)
1985 apply (erule (1) isCont_arccos)
1988 lemma DERIV_arctan: "DERIV arctan x :> inverse (1 + x\<twosuperior>)"
1989 apply (rule DERIV_inverse_function [where f=tan and a="x - 1" and b="x + 1"])
1990 apply (rule lemma_DERIV_subst [OF DERIV_tan])
1991 apply (rule cos_arctan_not_zero)
1992 apply (simp add: power_inverse tan_sec [symmetric])
1993 apply (subgoal_tac "0 < 1 + x\<twosuperior>", simp)
1994 apply (simp add: add_pos_nonneg)
1995 apply (simp, simp, simp, rule isCont_arctan)
1999 subsection {* More Theorems about Sin and Cos *}
2001 lemma cos_45: "cos (pi / 4) = sqrt 2 / 2"
2003 let ?c = "cos (pi / 4)" and ?s = "sin (pi / 4)"
2004 have nonneg: "0 \<le> ?c"
2005 by (rule cos_ge_zero, rule order_trans [where y=0], simp_all)
2006 have "0 = cos (pi / 4 + pi / 4)"
2008 also have "cos (pi / 4 + pi / 4) = ?c\<twosuperior> - ?s\<twosuperior>"
2009 by (simp only: cos_add power2_eq_square)
2010 also have "\<dots> = 2 * ?c\<twosuperior> - 1"
2011 by (simp add: sin_squared_eq)
2012 finally have "?c\<twosuperior> = (sqrt 2 / 2)\<twosuperior>"
2013 by (simp add: power_divide)
2015 using nonneg by (rule power2_eq_imp_eq) simp
2018 lemma cos_30: "cos (pi / 6) = sqrt 3 / 2"
2020 let ?c = "cos (pi / 6)" and ?s = "sin (pi / 6)"
2021 have pos_c: "0 < ?c"
2022 by (rule cos_gt_zero, simp, simp)
2023 have "0 = cos (pi / 6 + pi / 6 + pi / 6)"
2025 also have "\<dots> = (?c * ?c - ?s * ?s) * ?c - (?s * ?c + ?c * ?s) * ?s"
2026 by (simp only: cos_add sin_add)
2027 also have "\<dots> = ?c * (?c\<twosuperior> - 3 * ?s\<twosuperior>)"
2028 by (simp add: ring_simps power2_eq_square)
2029 finally have "?c\<twosuperior> = (sqrt 3 / 2)\<twosuperior>"
2030 using pos_c by (simp add: sin_squared_eq power_divide)
2032 using pos_c [THEN order_less_imp_le]
2033 by (rule power2_eq_imp_eq) simp
2036 lemma sin_45: "sin (pi / 4) = sqrt 2 / 2"
2038 have "sin (pi / 4) = cos (pi / 2 - pi / 4)" by (rule sin_cos_eq)
2039 also have "pi / 2 - pi / 4 = pi / 4" by simp
2040 also have "cos (pi / 4) = sqrt 2 / 2" by (rule cos_45)
2041 finally show ?thesis .
2044 lemma sin_60: "sin (pi / 3) = sqrt 3 / 2"
2046 have "sin (pi / 3) = cos (pi / 2 - pi / 3)" by (rule sin_cos_eq)
2047 also have "pi / 2 - pi / 3 = pi / 6" by simp
2048 also have "cos (pi / 6) = sqrt 3 / 2" by (rule cos_30)
2049 finally show ?thesis .
2052 lemma cos_60: "cos (pi / 3) = 1 / 2"
2053 apply (rule power2_eq_imp_eq)
2054 apply (simp add: cos_squared_eq sin_60 power_divide)
2055 apply (rule cos_ge_zero, rule order_trans [where y=0], simp_all)
2058 lemma sin_30: "sin (pi / 6) = 1 / 2"
2060 have "sin (pi / 6) = cos (pi / 2 - pi / 6)" by (rule sin_cos_eq)
2061 also have "pi / 2 - pi / 6 = pi / 3" by simp
2062 also have "cos (pi / 3) = 1 / 2" by (rule cos_60)
2063 finally show ?thesis .
2066 lemma tan_30: "tan (pi / 6) = 1 / sqrt 3"
2067 unfolding tan_def by (simp add: sin_30 cos_30)
2069 lemma tan_45: "tan (pi / 4) = 1"
2070 unfolding tan_def by (simp add: sin_45 cos_45)
2072 lemma tan_60: "tan (pi / 3) = sqrt 3"
2073 unfolding tan_def by (simp add: sin_60 cos_60)
2077 "sin (x + 1 / 2 * real (Suc m) * pi) =
2078 cos (x + 1 / 2 * real (m) * pi)"
2079 by (simp only: cos_add sin_add real_of_nat_Suc left_distrib right_distrib, auto)
2083 "sin (x + real (Suc m) * pi / 2) =
2084 cos (x + real (m) * pi / 2)"
2085 by (simp only: cos_add sin_add real_of_nat_Suc add_divide_distrib left_distrib, auto)
2087 lemma DERIV_sin_add [simp]: "DERIV (%x. sin (x + k)) xa :> cos (xa + k)"
2088 apply (rule lemma_DERIV_subst)
2089 apply (rule_tac f = sin and g = "%x. x + k" in DERIV_chain2)
2090 apply (best intro!: DERIV_intros intro: DERIV_chain2)+
2091 apply (simp (no_asm))
2094 lemma sin_cos_npi [simp]: "sin (real (Suc (2 * n)) * pi / 2) = (-1) ^ n"
2096 have "sin ((real n + 1/2) * pi) = cos (real n * pi)"
2097 by (auto simp add: right_distrib sin_add left_distrib mult_ac)
2099 by (simp add: real_of_nat_Suc left_distrib add_divide_distrib
2100 mult_commute [of pi])
2103 lemma cos_2npi [simp]: "cos (2 * real (n::nat) * pi) = 1"
2104 by (simp add: cos_double mult_assoc power_add [symmetric] numeral_2_eq_2)
2106 lemma cos_3over2_pi [simp]: "cos (3 / 2 * pi) = 0"
2107 apply (subgoal_tac "cos (pi + pi/2) = 0", simp)
2108 apply (subst cos_add, simp)
2111 lemma sin_2npi [simp]: "sin (2 * real (n::nat) * pi) = 0"
2112 by (auto simp add: mult_assoc)
2114 lemma sin_3over2_pi [simp]: "sin (3 / 2 * pi) = - 1"
2115 apply (subgoal_tac "sin (pi + pi/2) = - 1", simp)
2116 apply (subst sin_add, simp)
2121 "cos(x + 1 / 2 * real(Suc m) * pi) = -sin (x + 1 / 2 * real m * pi)"
2122 apply (simp only: cos_add sin_add real_of_nat_Suc right_distrib left_distrib minus_mult_right, auto)
2126 lemma [simp]: "cos (x + real(Suc m) * pi / 2) = -sin (x + real m * pi / 2)"
2127 by (simp only: cos_add sin_add real_of_nat_Suc left_distrib add_divide_distrib, auto)
2129 lemma cos_pi_eq_zero [simp]: "cos (pi * real (Suc (2 * m)) / 2) = 0"
2130 by (simp only: cos_add sin_add real_of_nat_Suc left_distrib right_distrib add_divide_distrib, auto)
2132 lemma DERIV_cos_add [simp]: "DERIV (%x. cos (x + k)) xa :> - sin (xa + k)"
2133 apply (rule lemma_DERIV_subst)
2134 apply (rule_tac f = cos and g = "%x. x + k" in DERIV_chain2)
2135 apply (best intro!: DERIV_intros intro: DERIV_chain2)+
2136 apply (simp (no_asm))
2139 lemma sin_zero_abs_cos_one: "sin x = 0 ==> \<bar>cos x\<bar> = 1"
2140 by (auto simp add: sin_zero_iff even_mult_two_ex)
2142 lemma exp_eq_one_iff [simp]: "(exp (x::real) = 1) = (x = 0)"
2144 apply (drule_tac f = ln in arg_cong, auto)
2147 lemma cos_one_sin_zero: "cos x = 1 ==> sin x = 0"
2148 by (cut_tac x = x in sin_cos_squared_add3, auto)
2151 subsection {* Existence of Polar Coordinates *}
2153 lemma cos_x_y_le_one: "\<bar>x / sqrt (x\<twosuperior> + y\<twosuperior>)\<bar> \<le> 1"
2154 apply (rule power2_le_imp_le [OF _ zero_le_one])
2155 apply (simp add: abs_divide power_divide divide_le_eq not_sum_power2_lt_zero)
2158 lemma cos_arccos_abs: "\<bar>y\<bar> \<le> 1 \<Longrightarrow> cos (arccos y) = y"
2159 by (simp add: abs_le_iff)
2161 lemma sin_arccos_abs: "\<bar>y\<bar> \<le> 1 \<Longrightarrow> sin (arccos y) = sqrt (1 - y\<twosuperior>)"
2162 by (simp add: sin_arccos abs_le_iff)
2164 lemmas cos_arccos_lemma1 = cos_arccos_abs [OF cos_x_y_le_one]
2166 lemmas sin_arccos_lemma1 = sin_arccos_abs [OF cos_x_y_le_one]
2169 "0 < y ==> \<exists>r a. x = r * cos a & y = r * sin a"
2170 apply (rule_tac x = "sqrt (x\<twosuperior> + y\<twosuperior>)" in exI)
2171 apply (rule_tac x = "arccos (x / sqrt (x\<twosuperior> + y\<twosuperior>))" in exI)
2172 apply (simp add: cos_arccos_lemma1)
2173 apply (simp add: sin_arccos_lemma1)
2174 apply (simp add: power_divide)
2175 apply (simp add: real_sqrt_mult [symmetric])
2176 apply (simp add: right_diff_distrib)
2180 "y < 0 ==> \<exists>r a. x = r * cos a & y = r * sin a"
2181 apply (insert polar_ex1 [where x=x and y="-y"], simp, clarify)
2182 apply (rule_tac x = r in exI)
2183 apply (rule_tac x = "-a" in exI, simp)
2186 lemma polar_Ex: "\<exists>r a. x = r * cos a & y = r * sin a"
2187 apply (rule_tac x=0 and y=y in linorder_cases)
2188 apply (erule polar_ex1)
2189 apply (rule_tac x=x in exI, rule_tac x=0 in exI, simp)
2190 apply (erule polar_ex2)
2194 subsection {* Theorems about Limits *}
2196 (* need to rename second isCont_inverse *)
2198 lemma isCont_inv_fun:
2199 fixes f g :: "real \<Rightarrow> real"
2200 shows "[| 0 < d; \<forall>z. \<bar>z - x\<bar> \<le> d --> g(f(z)) = z;
2201 \<forall>z. \<bar>z - x\<bar> \<le> d --> isCont f z |]
2203 by (rule isCont_inverse_function)
2205 lemma isCont_inv_fun_inv:
2206 fixes f g :: "real \<Rightarrow> real"
2208 \<forall>z. \<bar>z - x\<bar> \<le> d --> g(f(z)) = z;
2209 \<forall>z. \<bar>z - x\<bar> \<le> d --> isCont f z |]
2210 ==> \<exists>e. 0 < e &
2211 (\<forall>y. 0 < \<bar>y - f(x)\<bar> & \<bar>y - f(x)\<bar> < e --> f(g(y)) = y)"
2212 apply (drule isCont_inj_range)
2213 prefer 2 apply (assumption, assumption, auto)
2214 apply (rule_tac x = e in exI, auto)
2215 apply (rotate_tac 2)
2216 apply (drule_tac x = y in spec, auto)
2220 text{*Bartle/Sherbert: Introduction to Real Analysis, Theorem 4.2.9, p. 110*}
2221 lemma LIM_fun_gt_zero:
2222 "[| f -- c --> (l::real); 0 < l |]
2223 ==> \<exists>r. 0 < r & (\<forall>x::real. x \<noteq> c & \<bar>c - x\<bar> < r --> 0 < f x)"
2224 apply (auto simp add: LIM_def)
2225 apply (drule_tac x = "l/2" in spec, safe, force)
2226 apply (rule_tac x = s in exI)
2227 apply (auto simp only: abs_less_iff)
2230 lemma LIM_fun_less_zero:
2231 "[| f -- c --> (l::real); l < 0 |]
2232 ==> \<exists>r. 0 < r & (\<forall>x::real. x \<noteq> c & \<bar>c - x\<bar> < r --> f x < 0)"
2233 apply (auto simp add: LIM_def)
2234 apply (drule_tac x = "-l/2" in spec, safe, force)
2235 apply (rule_tac x = s in exI)
2236 apply (auto simp only: abs_less_iff)
2240 lemma LIM_fun_not_zero:
2241 "[| f -- c --> (l::real); l \<noteq> 0 |]
2242 ==> \<exists>r. 0 < r & (\<forall>x::real. x \<noteq> c & \<bar>c - x\<bar> < r --> f x \<noteq> 0)"
2243 apply (cut_tac x = l and y = 0 in linorder_less_linear, auto)
2244 apply (drule LIM_fun_less_zero)
2245 apply (drule_tac [3] LIM_fun_gt_zero)