# HG changeset patch # User huffman # Date 1160019992 -7200 # Node ID 1a8efd618190a5ccca314c60263029bcb04ae8a4 # Parent d95f3df451e5130491cc66b70051d3c5b302593d reorganize and speed up termdiffs proofs diff -r d95f3df451e5 -r 1a8efd618190 src/HOL/Hyperreal/Transcendental.thy --- a/src/HOL/Hyperreal/Transcendental.thy Wed Oct 04 18:41:14 2006 +0200 +++ b/src/HOL/Hyperreal/Transcendental.thy Thu Oct 05 05:46:32 2006 +0200 @@ -281,104 +281,142 @@ lemma sumdiff: "a + b - (c + d) = a - c + b - (d::real)" by arith - lemma lemma_termdiff2: - "h \ 0 ==> - (((z + h) ^ n) - (z ^ n)) * inverse h - real n * (z ^ (n - Suc 0)) = - h * (\p=0..< n - Suc 0. (z ^ p) * - (\q=0..< (n - Suc 0) - p. ((z + h) ^ q) * (z ^ (((n - 2) - p) - q))))" -apply (rule real_mult_left_cancel [THEN iffD1], simp (no_asm_simp)) -apply (simp add: right_diff_distrib mult_ac) + assumes h: "h \ 0" shows + "((z + h) ^ n - z ^ n) / h - real n * z ^ (n - Suc 0) = + h * (\p=0..< n - Suc 0. \q=0..< n - Suc 0 - p. + (z + h) ^ q * z ^ (n - 2 - q))" +apply (rule real_mult_left_cancel [OF h, THEN iffD1]) +apply (simp add: right_diff_distrib diff_divide_distrib h) apply (simp add: mult_assoc [symmetric]) -apply (case_tac "n") -apply (auto simp add: lemma_realpow_diff_sumr2 - right_diff_distrib [symmetric] mult_assoc - simp del: realpow_Suc setsum_op_ivl_Suc) -apply (auto simp add: lemma_realpow_rev_sumr simp del: setsum_op_ivl_Suc) -apply (auto simp add: real_of_nat_Suc sumr_diff_mult_const left_distrib - sumdiff lemma_termdiff1 setsum_right_distrib) -apply (auto intro!: setsum_cong[OF refl] simp add: diff_minus real_add_assoc) +apply (cases "n", simp) +apply (simp add: lemma_realpow_diff_sumr2 h + right_diff_distrib [symmetric] mult_assoc + del: realpow_Suc setsum_op_ivl_Suc) +apply (subst lemma_realpow_rev_sumr) +apply (subst sumr_diff_mult_const) +apply simp +apply (simp only: lemma_termdiff1 setsum_right_distrib) +apply (rule setsum_cong [OF refl]) apply (simp add: diff_minus [symmetric] less_iff_Suc_add) -apply (auto simp add: setsum_right_distrib lemma_realpow_diff_sumr2 mult_ac simp - del: setsum_op_ivl_Suc realpow_Suc) +apply (clarify) +apply (simp add: setsum_right_distrib lemma_realpow_diff_sumr2 mult_ac + del: setsum_op_ivl_Suc realpow_Suc) +apply (subst mult_assoc [symmetric], subst power_add [symmetric]) +apply (simp add: mult_ac) +done + +lemma real_setsum_nat_ivl_bounded2: + "\\p::nat. p < n \ f p \ K; 0 \ K\ + \ setsum f {0.. real n * K" +apply (rule order_trans [OF real_setsum_nat_ivl_bounded mult_right_mono]) +apply simp_all done lemma lemma_termdiff3: - "[| h \ 0; \z\ \ K; \z + h\ \ K |] - ==> abs (((z + h) ^ n - z ^ n) * inverse h - real n * z ^ (n - Suc 0)) + assumes 1: "h \ 0" + assumes 2: "\z\ \ K" + assumes 3: "\z + h\ \ K" + shows "\((z + h) ^ n - z ^ n) / h - real n * z ^ (n - Suc 0)\ \ real n * real (n - Suc 0) * K ^ (n - 2) * \h\" -apply (subst lemma_termdiff2, assumption) -apply (simp add: mult_commute abs_mult) -apply (simp add: mult_commute [of _ "K ^ (n - 2)"]) -apply (rule setsum_abs [THEN real_le_trans]) -apply (simp add: mult_assoc [symmetric] abs_mult) -apply (simp add: mult_commute [of _ "real (n - Suc 0)"]) -apply (auto intro!: real_setsum_nat_ivl_bounded) -apply (case_tac "n", auto) -apply (drule less_add_one) -(*CLAIM_SIMP " (a * b * c = a * (c * (b::real))" mult_ac]*) -apply clarify -apply (subgoal_tac "K ^ p * K ^ d * real (Suc (Suc (p + d))) = - K ^ p * (real (Suc (Suc (p + d))) * K ^ d)") -apply (simp (no_asm_simp) add: power_add del: setsum_op_ivl_Suc) -apply (auto intro!: mult_mono simp del: setsum_op_ivl_Suc) -apply (auto intro!: power_mono simp add: power_abs - simp del: setsum_op_ivl_Suc) -apply (rule_tac j = "real (Suc d) * (K ^ d)" in real_le_trans) -apply (subgoal_tac [2] "0 \ K") -apply (drule_tac [2] n = d in zero_le_power) -apply (auto simp del: setsum_op_ivl_Suc) -apply (rule setsum_abs [THEN real_le_trans]) -apply (rule real_setsum_nat_ivl_bounded) -apply (auto dest!: less_add_one intro!: mult_mono simp add: power_add abs_mult) -apply (auto intro!: power_mono zero_le_power simp add: power_abs) -done +proof - + have "\((z + h) ^ n - z ^ n) / h - real n * z ^ (n - Suc 0)\ = + \\p = 0..q = 0.. * \h\" + apply (subst lemma_termdiff2 [OF 1]) + apply (subst abs_mult) + apply (rule mult_commute) + done + also have "\ \ real n * (real (n - Suc 0) * K ^ (n - 2)) * \h\" + proof (rule mult_right_mono [OF _ abs_ge_zero]) + from abs_ge_zero 2 have K: "0 \ K" by (rule order_trans) + have le_Kn: "\i j n. i + j = n \ \(z + h) ^ i * z ^ j\ \ K ^ n" + apply (erule subst) + apply (simp only: abs_mult power_abs power_add) + apply (intro mult_mono power_mono 2 3 abs_ge_zero zero_le_power K) + done + show "\\p = 0..q = 0.. + \ real n * (real (n - Suc 0) * K ^ (n - 2))" + apply (intro + order_trans [OF setsum_abs] + real_setsum_nat_ivl_bounded2 + mult_nonneg_nonneg + real_of_nat_ge_zero + zero_le_power K) + apply (rule le_Kn, simp) + done + qed + also have "\ = real n * real (n - Suc 0) * K ^ (n - 2) * \h\" + by (simp only: mult_assoc) + finally show ?thesis . +qed -lemma lemma_termdiff4: - "[| 0 < (k::real); - (\h. 0 < \h\ & \h\ < k --> \f h\ \ K * \h\) |] - ==> f -- 0 --> 0" -apply (simp add: LIM_def, auto) -apply (subgoal_tac "0 \ K") - prefer 2 - apply (drule_tac x = "k/2" in spec) -apply (simp add: ); - apply (subgoal_tac "0 \ K*k", simp add: zero_le_mult_iff) - apply (force intro: order_trans [of _ "\f (k / 2)\ * 2"]) -apply (drule real_le_imp_less_or_eq, auto) -apply (subgoal_tac "0 < (r * inverse K) / 2") -apply (drule_tac ?d1.0 = "(r * inverse K) / 2" and ?d2.0 = k in real_lbound_gt_zero) -apply (auto simp add: positive_imp_inverse_positive zero_less_mult_iff zero_less_divide_iff) -apply (rule_tac x = e in exI, auto) -apply (rule_tac y = "K * \x\" in order_le_less_trans) -apply (force ); -apply (rule_tac y = "K * e" in order_less_trans) -apply (simp add: mult_less_cancel_left) -apply (rule_tac c = "inverse K" in mult_right_less_imp_less) -apply (auto simp add: mult_ac) -done +lemma lemma_termdiff4: + assumes k: "0 < (k::real)" + assumes le: "\h. \h \ 0; \h\ < k\ \ \f h\ \ K * \h\" + shows "f -- 0 --> 0" +proof (simp add: LIM_def, safe) + fix r::real assume r: "0 < r" + have zero_le_K: "0 \ K" + apply (cut_tac k) + apply (cut_tac h="k/2" in le, simp, simp) + apply (subgoal_tac "0 \ K*k", simp add: zero_le_mult_iff) + apply (force intro: order_trans [of _ "\f (k / 2)\ * 2"]) + done + show "\s. 0 < s \ (\x. x \ 0 \ \x\ < s \ \f x\ < r)" + proof (cases) + assume "K = 0" + with k r le have "0 < k \ (\x. x \ 0 \ \x\ < k \ \f x\ < r)" + by simp + thus "\s. 0 < s \ (\x. x \ 0 \ \x\ < s \ \f x\ < r)" .. + next + assume K_neq_zero: "K \ 0" + with zero_le_K have K: "0 < K" by simp + show "\s. 0 < s \ (\x. x \ 0 \ \x\ < s \ \f x\ < r)" + proof (rule exI, safe) + from k r K show "0 < min k (r * inverse K / 2)" + by (simp add: mult_pos_pos positive_imp_inverse_positive) + next + fix x::real + assume x1: "x \ 0" and x2: "\x\ < min k (r * inverse K / 2)" + from x2 have x3: "\x\ < k" and x4: "\x\ < r * inverse K / 2" + by simp_all + from x1 x3 le have "\f x\ \ K * \x\" by simp + also from x4 K have "K * \x\ < K * (r * inverse K / 2)" + by (rule mult_strict_left_mono) + also have "\ = r / 2" + using K_neq_zero by simp + also have "r / 2 < r" + using r by simp + finally show "\f x\ < r" . + qed + qed +qed lemma lemma_termdiff5: - "[| 0 < (k::real); - summable f; - \h. 0 < \h\ & \h\ < k --> - (\n. abs(g(h) (n::nat)) \ (f(n) * \h\)) |] - ==> (%h. suminf(g h)) -- 0 --> 0" -apply (drule summable_sums) -apply (subgoal_tac "\h. 0 < \h\ & \h\ < k --> \suminf (g h)\ \ suminf f * \h\") -apply (auto intro!: lemma_termdiff4 simp add: sums_summable [THEN suminf_mult, symmetric]) -apply (subgoal_tac "summable (%n. f n * \h\) ") - prefer 2 - apply (simp add: summable_def) - apply (rule_tac x = "suminf f * \h\" in exI) - apply (drule_tac c = "\h\" in sums_mult) - apply (simp add: mult_ac) -apply (subgoal_tac "summable (%n. abs (g (h::real) (n::nat))) ") - apply (rule_tac [2] g = "%n. f n * \h\" in summable_comparison_test) - apply (rule_tac [2] x = 0 in exI, auto) -apply (rule_tac j = "\n. \g h n\" in real_le_trans) -apply (auto intro: summable_rabs summable_le simp add: sums_summable [THEN suminf_mult2]) -done + assumes k: "0 < (k::real)" + assumes f: "summable f" + assumes le: "\h n. \h \ 0; \h\ < k\ \ \g h n\ \ f n * \h\" + shows "(\h. suminf (g h)) -- 0 --> 0" +proof (rule lemma_termdiff4 [OF k]) + fix h assume "h \ 0" and "\h\ < k" + hence A: "\n. \g h n\ \ f n * \h\" + by (simp add: le) + hence "\N. \n\N. norm \g h n\ \ f n * \h\" + by simp + moreover from f have B: "summable (\n. f n * \h\)" + by (rule summable_mult2) + ultimately have C: "summable (\n. \g h n\)" + by (rule summable_comparison_test) + hence "\suminf (g h)\ \ (\n. \g h n\)" + by (rule summable_rabs) + also from A C B have "(\n. \g h n\) \ (\n. f n * \h\)" + by (rule summable_le) + also from f have "(\n. f n * \h\) = suminf f * \h\" + by (rule suminf_mult2 [symmetric]) + finally show "\suminf (g h)\ \ suminf f * \h\" . +qed text{* FIXME: Long proofs*} @@ -386,126 +424,112 @@ lemma termdiffs_aux: assumes 1: "summable (\n. diffs (diffs c) n * K ^ n)" assumes 2: "\x\ < \K\" - shows "(\h. \n. c n * - (((x + h) ^ n - x ^ n) * inverse h - - real n * x ^ (n - Suc 0))) - -- 0 --> 0" + shows "(\h. \n. c n * (((x + h) ^ n - x ^ n) / h + - real n * x ^ (n - Suc 0))) -- 0 --> 0" proof - - from dense [OF 2] obtain r where 3: "\x\ < r" and 4: "r < \K\" by fast - from 3 have r_neq_0: "r \ 0" by auto - show "(\h. suminf (\n. c n * (((x + h) ^ n - x ^ n) * inverse h - real n * x ^ (n - Suc 0)))) -- 0 --> 0" + from dense [OF 2] + obtain r where r1: "\x\ < r" and r2: "r < \K\" by fast + from abs_ge_zero r1 have r: "0 < r" + by (rule order_le_less_trans) + hence r_neq_0: "r \ 0" by simp + show ?thesis proof (rule lemma_termdiff5) - show "0 < r + - \x\" using 3 by simp + show "0 < r - \x\" using r1 by simp next - have A: "summable (%n. \diffs (diffs c) n\ * (r ^ n))" - apply (rule powser_insidea [OF 1]) - apply (subgoal_tac "\r\ = r", erule ssubst, rule 4) - apply (rule_tac y1 = "\x\" in order_trans [THEN abs_of_nonneg]) - apply (rule abs_ge_zero) - apply (rule order_less_imp_le [OF 3]) - done - have B: "\n. real (Suc n) * real (Suc (Suc n)) * - \c (Suc (Suc n))\ * (r ^ n) = diffs (diffs (%n. \c n\)) n * (r ^ n)" - by (simp add: diffs_def mult_assoc) - have C: "(%n. real n * (real (Suc n) * (\c (Suc n)\ * (r ^ (n - Suc 0))))) - = (%n. diffs (%m. real (m - Suc 0) * \c m\ * inverse r) n * (r ^ n))" + from r r2 have "\r\ < \K\" + by (simp only: abs_of_nonneg order_less_imp_le) + with 1 have "summable (\n. \diffs (diffs c) n\ * (r ^ n))" + by (rule powser_insidea) + hence "summable (\n. diffs (diffs (\n. \c n\)) n * r ^ n)" + by (simp only: diffs_def abs_mult abs_real_of_nat_cancel) + hence "summable (\n. real n * diffs (\n. \c n\) n * r ^ (n - Suc 0))" + by (rule diffs_equiv [THEN sums_summable]) + also have "(\n. real n * diffs (\n. \c n\) n * r ^ (n - Suc 0)) + = (\n. diffs (%m. real (m - Suc 0) * \c m\ * inverse r) n * (r ^ n))" apply (rule ext) apply (simp add: diffs_def) apply (case_tac n, simp_all add: r_neq_0) done - have D: - "(\n. real n * (real (n - Suc 0) * \c n\ * inverse r) * - r ^ (n - Suc 0)) = - (\n. real n * (\c n\ * (real (n - Suc 0) * r ^ (n - 2))))" + finally have "summable + (\n. real n * (real (n - Suc 0) * \c n\ * inverse r) * r ^ (n - Suc 0))" + by (rule diffs_equiv [THEN sums_summable]) + also have + "(\n. real n * (real (n - Suc 0) * \c n\ * inverse r) * + r ^ (n - Suc 0)) = + (\n. \c n\ * real n * real (n - Suc 0) * r ^ (n - 2))" apply (rule ext) apply (case_tac "n", simp) apply (case_tac "nat", simp) apply (simp add: r_neq_0) done - show "summable (\n. \c n\ * real n * real (n - Suc 0) * r ^ (n - 2))" - apply (cut_tac A) - apply (simp add: diffs_def mult_assoc [symmetric]) - apply (simp only: abs_mult abs_real_of_nat_cancel B) - apply (drule diffs_equiv) - apply (drule sums_summable) - apply (simp only: diffs_def mult_ac) - apply (simp only: C) - apply (drule diffs_equiv) - apply (drule sums_summable) - apply (simp only: D) - done + finally show + "summable (\n. \c n\ * real n * real (n - Suc 0) * r ^ (n - 2))" . next - show "\h. 0 < \h\ \ \h\ < r + - \x\ \ (\n. \c n * (((x + h) ^ n - x ^ n) * inverse h - real n * x ^ (n - Suc 0))\ \ \c n\ * real n * real (n - Suc 0) * r ^ (n - 2) * \h\)" - proof (clarify) - fix h::real and n::nat - assume A: "0 < \h\" and B: "\h\ < r + - \x\" - from A have C: "h \ 0" by simp - show "\c n * (((x + h) ^ n - x ^ n) * inverse h - real n * x ^ (n - Suc 0))\ \ \c n\ * real n * real (n - Suc 0) * r ^ (n - 2) * \h\" - apply (cut_tac 3 B C) - apply (subst abs_mult) - apply (drule abs_ge_zero [THEN order_le_less_trans]) - apply (simp only: mult_assoc) - apply (rule mult_left_mono) - prefer 2 apply arith - apply (simp (no_asm) add: mult_assoc [symmetric]) - apply (rule lemma_termdiff3) - apply assumption - apply (rule 3 [THEN order_less_imp_le]) - apply (rule abs_triangle_ineq [THEN order_trans]) - apply arith - done - qed + fix h::real and n::nat + assume h: "h \ 0" + assume "\h\ < r - \x\" + hence "\x\ + \h\ < r" by simp + with abs_triangle_ineq have xh: "\x + h\ < r" + by (rule order_le_less_trans) + show "\c n * (((x + h) ^ n - x ^ n) / h - real n * x ^ (n - Suc 0))\ + \ \c n\ * real n * real (n - Suc 0) * r ^ (n - 2) * \h\" + apply (simp only: abs_mult mult_assoc) + apply (rule mult_left_mono [OF _ abs_ge_zero]) + apply (simp (no_asm) add: mult_assoc [symmetric]) + apply (rule lemma_termdiff3) + apply (rule h) + apply (rule r1 [THEN order_less_imp_le]) + apply (rule xh [THEN order_less_imp_le]) + done qed qed -lemma termdiffs: - "[| summable(%n. c(n) * (K ^ n)); - summable(%n. (diffs c)(n) * (K ^ n)); - summable(%n. (diffs(diffs c))(n) * (K ^ n)); - \x\ < \K\ |] - ==> DERIV (%x. \n. c(n) * (x ^ n)) x :> - (\n. (diffs c)(n) * (x ^ n))" -apply (simp add: deriv_def) -apply (rule_tac g = "%h. \n. ((c (n) * ( (x + h) ^ n)) - (c (n) * (x ^ n))) * inverse h" in LIM_trans) -apply (simp add: LIM_def, safe) -apply (rule_tac x = "\K\ - \x\" in exI) -apply (auto simp add: less_diff_eq) -apply (drule abs_triangle_ineq [THEN order_le_less_trans]) -apply (rule_tac y = 0 in order_le_less_trans, auto) -apply (subgoal_tac " (%n. (c n) * (x ^ n)) sums (\n. (c n) * (x ^ n)) & (%n. (c n) * ((x + xa) ^ n)) sums (\n. (c n) * ( (x + xa) ^ n))") -apply (auto intro!: summable_sums) -apply (rule_tac [2] powser_inside, rule_tac [4] powser_inside) -apply (auto simp add: add_commute) -apply (drule_tac x="(\n. c n * (xa + x) ^ n)" in sums_diff, assumption) -apply (drule_tac f = "(%n. c n * (xa + x) ^ n - c n * x ^ n) " and c = "inverse xa" in sums_mult) -apply (rule sums_unique) -apply (simp add: diff_def divide_inverse add_ac mult_ac) -apply (rule LIM_zero_cancel) -apply (rule_tac g = "%h. \n. c (n) * ((( ((x + h) ^ n) - (x ^ n)) * inverse h) - (real n * (x ^ (n - Suc 0))))" in LIM_trans) - prefer 2 apply (blast intro: termdiffs_aux) -apply (simp add: LIM_def, safe) -apply (rule_tac x = "\K\ - \x\" in exI) -apply (auto simp add: less_diff_eq) -apply (drule abs_triangle_ineq [THEN order_le_less_trans]) -apply (rule_tac y = 0 in order_le_less_trans, auto) -apply (subgoal_tac "summable (%n. (diffs c) (n) * (x ^ n))") -apply (rule_tac [2] powser_inside, auto) -apply (drule_tac c = c and x = x in diffs_equiv) -apply (frule sums_unique, auto) -apply (subgoal_tac " (%n. (c n) * (x ^ n)) sums (\n. (c n) * (x ^ n)) & (%n. (c n) * ((x + xa) ^ n)) sums (\n. (c n) * ( (x + xa) ^ n))") -apply safe -apply (auto intro!: summable_sums) -apply (rule_tac [2] powser_inside, rule_tac [4] powser_inside) -apply (auto simp add: add_commute) -apply (frule_tac x = "(%n. c n * (xa + x) ^ n) " and y = "(%n. c n * x ^ n)" in sums_diff, assumption) -apply (simp add: suminf_diff [OF sums_summable sums_summable] - right_diff_distrib [symmetric]) -apply (subst suminf_diff) -apply (rule summable_mult2) -apply (erule sums_summable) -apply (erule sums_summable) -apply (simp add: ring_eq_simps) -done +lemma termdiffs: + assumes 1: "summable (\n. c n * K ^ n)" + assumes 2: "summable (\n. (diffs c) n * K ^ n)" + assumes 3: "summable (\n. (diffs (diffs c)) n * K ^ n)" + assumes 4: "\x\ < \K\" + shows "DERIV (\x. \n. c n * x ^ n) x :> (\n. (diffs c) n * x ^ n)" +proof (simp add: deriv_def, rule LIM_zero_cancel) + show "(\h. (suminf (\n. c n * (x + h) ^ n) - suminf (\n. c n * x ^ n)) / h + - suminf (\n. diffs c n * x ^ n)) -- 0 --> 0" + proof (rule LIM_equal2) + show "0 < \K\ - \x\" by (simp add: less_diff_eq 4) + next + fix h :: real + assume "h \ 0" + assume "norm (h - 0) < \K\ - \x\" + hence "\x\ + \h\ < \K\" by simp + hence 5: "\x + h\ < \K\" + by (rule abs_triangle_ineq [THEN order_le_less_trans]) + have A: "summable (\n. c n * x ^ n)" + by (rule powser_inside [OF 1 4]) + have B: "summable (\n. c n * (x + h) ^ n)" + by (rule powser_inside [OF 1 5]) + have C: "summable (\n. diffs c n * x ^ n)" + by (rule powser_inside [OF 2 4]) + show "((\n. c n * (x + h) ^ n) - (\n. c n * x ^ n)) / h + - (\n. diffs c n * x ^ n) = + (\n. c n * (((x + h) ^ n - x ^ n) / h - real n * x ^ (n - Suc 0)))" + apply (subst sums_unique [OF diffs_equiv [OF C]]) + apply (subst suminf_diff [OF B A]) + apply (subst suminf_divide [symmetric]) + apply (rule summable_diff [OF B A]) + apply (subst suminf_diff) + apply (rule summable_divide) + apply (rule summable_diff [OF B A]) + apply (rule sums_summable [OF diffs_equiv [OF C]]) + apply (rule_tac f="suminf" in arg_cong) + apply (rule ext) + apply (simp add: ring_eq_simps) + done + next + show "(\h. \n. c n * (((x + h) ^ n - x ^ n) / h - + real n * x ^ (n - Suc 0))) -- 0 --> 0" + by (rule termdiffs_aux [OF 3 4]) + qed +qed + subsection{*Formal Derivatives of Exp, Sin, and Cos Series*}