740 using f0 |
740 using f0 |
741 unfolding mult_cancel_right |
741 unfolding mult_cancel_right |
742 by (auto simp add: expand_fps_eq) |
742 by (auto simp add: expand_fps_eq) |
743 qed |
743 qed |
744 |
744 |
745 lemma fps_inverse_gp: "inverse (Abs_fps(\<lambda>n. (1::'a::field))) |
745 lemma setsum_zero_lemma: |
746 = Abs_fps (\<lambda>n. if n= 0 then 1 else if n=1 then - 1 else 0)" |
746 fixes n::nat |
747 apply (rule fps_inverse_unique) |
747 assumes "0 < n" |
748 apply simp |
748 shows "(\<Sum>i = 0..n. if n = i then 1 else if n - i = 1 then - 1 else 0) = (0::'a::field)" |
749 apply (simp add: fps_eq_iff fps_mult_nth) |
749 proof - |
750 apply clarsimp |
750 let ?f = "\<lambda>i. if n = i then 1 else if n - i = 1 then - 1 else 0" |
751 proof - |
751 let ?g = "\<lambda>i. if i = n then 1 else if i = n - 1 then - 1 else 0" |
752 fix n :: nat |
|
753 assume n: "n > 0" |
|
754 let ?f = "\<lambda>i. if n = i then (1::'a) else if n - i = 1 then - 1 else 0" |
|
755 let ?g = "\<lambda>i. if i = n then 1 else if i=n - 1 then - 1 else 0" |
|
756 let ?h = "\<lambda>i. if i=n - 1 then - 1 else 0" |
752 let ?h = "\<lambda>i. if i=n - 1 then - 1 else 0" |
757 have th1: "setsum ?f {0..n} = setsum ?g {0..n}" |
753 have th1: "setsum ?f {0..n} = setsum ?g {0..n}" |
758 by (rule setsum.cong) auto |
754 by (rule setsum.cong) auto |
759 have th2: "setsum ?g {0..n - 1} = setsum ?h {0..n - 1}" |
755 have th2: "setsum ?g {0..n - 1} = setsum ?h {0..n - 1}" |
760 apply (insert n) |
|
761 apply (rule setsum.cong) |
756 apply (rule setsum.cong) |
|
757 using assms |
762 apply auto |
758 apply auto |
763 done |
759 done |
764 have eq: "{0 .. n} = {0.. n - 1} \<union> {n}" |
760 have eq: "{0 .. n} = {0.. n - 1} \<union> {n}" |
765 by auto |
761 by auto |
766 from n have d: "{0.. n - 1} \<inter> {n} = {}" |
762 from assms have d: "{0.. n - 1} \<inter> {n} = {}" |
767 by auto |
763 by auto |
768 have f: "finite {0.. n - 1}" "finite {n}" |
764 have f: "finite {0.. n - 1}" "finite {n}" |
769 by auto |
765 by auto |
770 show "setsum ?f {0..n} = 0" |
766 show ?thesis |
771 unfolding th1 |
767 unfolding th1 |
772 apply (simp add: setsum.union_disjoint[OF f d, unfolded eq[symmetric]] del: One_nat_def) |
768 apply (simp add: setsum.union_disjoint[OF f d, unfolded eq[symmetric]] del: One_nat_def) |
773 unfolding th2 |
769 unfolding th2 |
774 apply (simp add: setsum.delta) |
770 apply (simp add: setsum.delta) |
775 done |
771 done |
776 qed |
772 qed |
|
773 |
|
774 lemma fps_inverse_gp: "inverse (Abs_fps(\<lambda>n. (1::'a::field))) |
|
775 = Abs_fps (\<lambda>n. if n= 0 then 1 else if n=1 then - 1 else 0)" |
|
776 apply (rule fps_inverse_unique) |
|
777 apply (simp_all add: fps_eq_iff fps_mult_nth setsum_zero_lemma) |
|
778 done |
777 |
779 |
778 |
780 |
779 subsection {* Formal Derivatives, and the MacLaurin theorem around 0 *} |
781 subsection {* Formal Derivatives, and the MacLaurin theorem around 0 *} |
780 |
782 |
781 definition "fps_deriv f = Abs_fps (\<lambda>n. of_nat (n + 1) * f $ (n + 1))" |
783 definition "fps_deriv f = Abs_fps (\<lambda>n. of_nat (n + 1) * f $ (n + 1))" |
2883 apply (induct n) |
2885 apply (induct n) |
2884 apply simp |
2886 apply simp |
2885 unfolding th |
2887 unfolding th |
2886 using fact_gt_zero |
2888 using fact_gt_zero |
2887 apply (simp add: field_simps del: of_nat_Suc fact_Suc) |
2889 apply (simp add: field_simps del: of_nat_Suc fact_Suc) |
2888 apply (drule sym) |
2890 apply simp |
2889 apply (simp add: field_simps of_nat_mult) |
|
2890 done |
2891 done |
2891 } |
2892 } |
2892 note th' = this |
2893 note th' = this |
2893 show ?rhs by (auto simp add: fps_eq_iff fps_const_mult_left E_def intro: th') |
2894 show ?rhs by (auto simp add: fps_eq_iff fps_const_mult_left E_def intro: th') |
2894 next |
2895 next |
2895 assume h: ?rhs |
2896 assume h: ?rhs |
2896 show ?lhs |
2897 show ?lhs |
2897 apply (subst h) |
2898 by (metis E_deriv fps_deriv_mult_const_left h mult.left_commute) |
2898 apply simp |
|
2899 apply (simp only: h[symmetric]) |
|
2900 apply simp |
|
2901 done |
|
2902 qed |
2899 qed |
2903 |
2900 |
2904 lemma E_add_mult: "E (a + b) = E (a::'a::field_char_0) * E b" (is "?l = ?r") |
2901 lemma E_add_mult: "E (a + b) = E (a::'a::field_char_0) * E b" (is "?l = ?r") |
2905 proof - |
2902 proof - |
2906 have "fps_deriv (?r) = fps_const (a+b) * ?r" |
2903 have "fps_deriv (?r) = fps_const (a+b) * ?r" |
2946 "a \<noteq> 0 \<Longrightarrow> inverse (fps_const (a::'a::field)) = fps_const (inverse a)" |
2943 "a \<noteq> 0 \<Longrightarrow> inverse (fps_const (a::'a::field)) = fps_const (inverse a)" |
2947 apply (auto simp add: fps_eq_iff fps_inverse_def) |
2944 apply (auto simp add: fps_eq_iff fps_inverse_def) |
2948 apply (case_tac n) |
2945 apply (case_tac n) |
2949 apply auto |
2946 apply auto |
2950 done |
2947 done |
2951 |
|
2952 lemma inverse_one_plus_X: |
|
2953 "inverse (1 + X) = Abs_fps (\<lambda>n. (- 1 ::'a::field)^n)" |
|
2954 (is "inverse ?l = ?r") |
|
2955 proof - |
|
2956 have th: "?l * ?r = 1" |
|
2957 by (auto simp add: field_simps fps_eq_iff minus_one_power_iff) |
|
2958 have th': "?l $ 0 \<noteq> 0" by (simp add: ) |
|
2959 from fps_inverse_unique[OF th' th] show ?thesis . |
|
2960 qed |
|
2961 |
2948 |
2962 lemma E_power_mult: "(E (c::'a::field_char_0))^n = E (of_nat n * c)" |
2949 lemma E_power_mult: "(E (c::'a::field_char_0))^n = E (of_nat n * c)" |
2963 by (induct n) (auto simp add: field_simps E_add_mult) |
2950 by (induct n) (auto simp add: field_simps E_add_mult) |
2964 |
2951 |
2965 lemma radical_E: |
2952 lemma radical_E: |
2991 |
2978 |
2992 definition L :: "'a::field_char_0 \<Rightarrow> 'a fps" |
2979 definition L :: "'a::field_char_0 \<Rightarrow> 'a fps" |
2993 where "L c = fps_const (1/c) * Abs_fps (\<lambda>n. if n = 0 then 0 else (- 1) ^ (n - 1) / of_nat n)" |
2980 where "L c = fps_const (1/c) * Abs_fps (\<lambda>n. if n = 0 then 0 else (- 1) ^ (n - 1) / of_nat n)" |
2994 |
2981 |
2995 lemma fps_deriv_L: "fps_deriv (L c) = fps_const (1/c) * inverse (1 + X)" |
2982 lemma fps_deriv_L: "fps_deriv (L c) = fps_const (1/c) * inverse (1 + X)" |
2996 unfolding inverse_one_plus_X |
2983 unfolding fps_inverse_X_plus1 |
2997 by (simp add: L_def fps_eq_iff del: of_nat_Suc) |
2984 by (simp add: L_def fps_eq_iff del: of_nat_Suc) |
2998 |
2985 |
2999 lemma L_nth: "L c $ n = (if n=0 then 0 else 1/c * ((- 1) ^ (n - 1) / of_nat n))" |
2986 lemma L_nth: "L c $ n = (if n=0 then 0 else 1/c * ((- 1) ^ (n - 1) / of_nat n))" |
3000 by (simp add: L_def field_simps) |
2987 by (simp add: L_def field_simps) |
3001 |
2988 |
3436 also have "\<dots> = 1" |
3423 also have "\<dots> = 1" |
3437 by (auto simp add: fps_eq_iff numeral_2_eq_2 fps_mult_nth fps_cos_def fps_sin_def) |
3424 by (auto simp add: fps_eq_iff numeral_2_eq_2 fps_mult_nth fps_cos_def fps_sin_def) |
3438 finally show ?thesis . |
3425 finally show ?thesis . |
3439 qed |
3426 qed |
3440 |
3427 |
3441 lemma divide_eq_iff: "a \<noteq> (0::'a::field) \<Longrightarrow> x / a = y \<longleftrightarrow> x = y * a" |
|
3442 by auto |
|
3443 |
|
3444 lemma eq_divide_iff: "a \<noteq> (0::'a::field) \<Longrightarrow> x = y / a \<longleftrightarrow> x * a = y" |
|
3445 by auto |
|
3446 |
|
3447 lemma fps_sin_nth_0 [simp]: "fps_sin c $ 0 = 0" |
3428 lemma fps_sin_nth_0 [simp]: "fps_sin c $ 0 = 0" |
3448 unfolding fps_sin_def by simp |
3429 unfolding fps_sin_def by simp |
3449 |
3430 |
3450 lemma fps_sin_nth_1 [simp]: "fps_sin c $ 1 = c" |
3431 lemma fps_sin_nth_1 [simp]: "fps_sin c $ 1 = c" |
3451 unfolding fps_sin_def by simp |
3432 unfolding fps_sin_def by simp |
3452 |
3433 |
3453 lemma fps_sin_nth_add_2: |
3434 lemma fps_sin_nth_add_2: |
3454 "fps_sin c $ (n + 2) = - (c * c * fps_sin c $ n / (of_nat(n+1) * of_nat(n+2)))" |
3435 "fps_sin c $ (n + 2) = - (c * c * fps_sin c $ n / (of_nat(n+1) * of_nat(n+2)))" |
3455 unfolding fps_sin_def |
3436 unfolding fps_sin_def |
3456 apply (cases n, simp) |
3437 apply (cases n, simp) |
3457 apply (simp add: divide_eq_iff eq_divide_iff del: of_nat_Suc fact_Suc) |
3438 apply (simp add: nonzero_divide_eq_eq nonzero_eq_divide_eq del: of_nat_Suc fact_Suc) |
3458 apply (simp add: of_nat_mult del: of_nat_Suc mult_Suc) |
3439 apply (simp add: of_nat_mult del: of_nat_Suc mult_Suc) |
3459 done |
3440 done |
3460 |
3441 |
3461 lemma fps_cos_nth_0 [simp]: "fps_cos c $ 0 = 1" |
3442 lemma fps_cos_nth_0 [simp]: "fps_cos c $ 0 = 1" |
3462 unfolding fps_cos_def by simp |
3443 unfolding fps_cos_def by simp |
3465 unfolding fps_cos_def by simp |
3446 unfolding fps_cos_def by simp |
3466 |
3447 |
3467 lemma fps_cos_nth_add_2: |
3448 lemma fps_cos_nth_add_2: |
3468 "fps_cos c $ (n + 2) = - (c * c * fps_cos c $ n / (of_nat(n+1) * of_nat(n+2)))" |
3449 "fps_cos c $ (n + 2) = - (c * c * fps_cos c $ n / (of_nat(n+1) * of_nat(n+2)))" |
3469 unfolding fps_cos_def |
3450 unfolding fps_cos_def |
3470 apply (simp add: divide_eq_iff eq_divide_iff del: of_nat_Suc fact_Suc) |
3451 apply (simp add: nonzero_divide_eq_eq nonzero_eq_divide_eq del: of_nat_Suc fact_Suc) |
3471 apply (simp add: of_nat_mult del: of_nat_Suc mult_Suc) |
3452 apply (simp add: of_nat_mult del: of_nat_Suc mult_Suc) |
3472 done |
3453 done |
3473 |
3454 |
3474 lemma nat_induct2: "P 0 \<Longrightarrow> P 1 \<Longrightarrow> (\<And>n. P n \<Longrightarrow> P (n + 2)) \<Longrightarrow> P (n::nat)" |
3455 lemma nat_induct2: "P 0 \<Longrightarrow> P 1 \<Longrightarrow> (\<And>n. P n \<Longrightarrow> P (n + 2)) \<Longrightarrow> P (n::nat)" |
3475 unfolding One_nat_def numeral_2_eq_2 |
3456 unfolding One_nat_def numeral_2_eq_2 |
3498 apply (simp add: 1 del: One_nat_def) |
3479 apply (simp add: 1 del: One_nat_def) |
3499 apply (rename_tac m, cut_tac f="\<lambda>a. a $ m" in arg_cong [OF 2]) |
3480 apply (rename_tac m, cut_tac f="\<lambda>a. a $ m" in arg_cong [OF 2]) |
3500 apply (simp add: nat_add_1_add_1 fps_sin_nth_add_2 |
3481 apply (simp add: nat_add_1_add_1 fps_sin_nth_add_2 |
3501 del: One_nat_def of_nat_Suc of_nat_add add_2_eq_Suc') |
3482 del: One_nat_def of_nat_Suc of_nat_add add_2_eq_Suc') |
3502 apply (subst minus_divide_left) |
3483 apply (subst minus_divide_left) |
3503 apply (subst eq_divide_iff) |
3484 apply (subst nonzero_eq_divide_eq) |
3504 apply (simp del: of_nat_add of_nat_Suc) |
3485 apply (simp del: of_nat_add of_nat_Suc) |
3505 apply (simp only: ac_simps) |
3486 apply (simp only: ac_simps) |
3506 done |
3487 done |
3507 |
3488 |
3508 lemma eq_fps_cos: |
3489 lemma eq_fps_cos: |
3516 apply (simp add: 1 del: One_nat_def) |
3497 apply (simp add: 1 del: One_nat_def) |
3517 apply (rename_tac m, cut_tac f="\<lambda>a. a $ m" in arg_cong [OF 2]) |
3498 apply (rename_tac m, cut_tac f="\<lambda>a. a $ m" in arg_cong [OF 2]) |
3518 apply (simp add: nat_add_1_add_1 fps_cos_nth_add_2 |
3499 apply (simp add: nat_add_1_add_1 fps_cos_nth_add_2 |
3519 del: One_nat_def of_nat_Suc of_nat_add add_2_eq_Suc') |
3500 del: One_nat_def of_nat_Suc of_nat_add add_2_eq_Suc') |
3520 apply (subst minus_divide_left) |
3501 apply (subst minus_divide_left) |
3521 apply (subst eq_divide_iff) |
3502 apply (subst nonzero_eq_divide_eq) |
3522 apply (simp del: of_nat_add of_nat_Suc) |
3503 apply (simp del: of_nat_add of_nat_Suc) |
3523 apply (simp only: ac_simps) |
3504 apply (simp only: ac_simps) |
3524 done |
3505 done |
3525 |
3506 |
3526 lemma mult_nth_0 [simp]: "(a * b) $ 0 = a $ 0 * b $ 0" |
3507 lemma mult_nth_0 [simp]: "(a * b) $ 0 = a $ 0 * b $ 0" |
3791 fix e::real assume "0 < e" |
3772 fix e::real assume "0 < e" |
3792 with LIMSEQ_inverse_realpow_zero[of 2, simplified, simplified filterlim_iff, |
3773 with LIMSEQ_inverse_realpow_zero[of 2, simplified, simplified filterlim_iff, |
3793 THEN spec, of "\<lambda>x. x < e"] |
3774 THEN spec, of "\<lambda>x. x < e"] |
3794 have "eventually (\<lambda>i. inverse (2 ^ i) < e) sequentially" |
3775 have "eventually (\<lambda>i. inverse (2 ^ i) < e) sequentially" |
3795 unfolding eventually_nhds |
3776 unfolding eventually_nhds |
3796 apply safe |
3777 apply clarsimp |
|
3778 apply (rule FalseE) |
3797 apply auto --{*slow*} |
3779 apply auto --{*slow*} |
3798 done |
3780 done |
3799 then obtain i where "inverse (2 ^ i) < e" by (auto simp: eventually_sequentially) |
3781 then obtain i where "inverse (2 ^ i) < e" by (auto simp: eventually_sequentially) |
3800 have "eventually (\<lambda>x. M i \<le> x) sequentially" by (auto simp: eventually_sequentially) |
3782 have "eventually (\<lambda>x. M i \<le> x) sequentially" by (auto simp: eventually_sequentially) |
3801 then show "eventually (\<lambda>x. dist (X x) (Abs_fps (\<lambda>i. X (M i) $ i)) < e) sequentially" |
3783 then show "eventually (\<lambda>x. dist (X x) (Abs_fps (\<lambda>i. X (M i) $ i)) < e) sequentially" |