src/HOL/Library/Formal_Power_Series.thy
changeset 32042 df28ead1cf19
parent 31968 0314441a53a6
child 32047 c141f139ce26
equal deleted inserted replaced
32038:4127b89f48ab 32042:df28ead1cf19
  2512 
  2512 
  2513 lemma E_deriv[simp]: "fps_deriv (E a) = fps_const (a::'a::field_char_0) * E a" (is "?l = ?r")
  2513 lemma E_deriv[simp]: "fps_deriv (E a) = fps_const (a::'a::field_char_0) * E a" (is "?l = ?r")
  2514 proof-
  2514 proof-
  2515   {fix n
  2515   {fix n
  2516     have "?l$n = ?r $ n"
  2516     have "?l$n = ?r $ n"
  2517   apply (auto simp add: E_def field_simps power_Suc[symmetric]simp del: fact_Suc of_nat_Suc power_Suc)
  2517   apply (auto simp add: E_def field_simps power_Suc[symmetric]simp del: fact_Suc_nat of_nat_Suc power_Suc)
  2518   by (simp add: of_nat_mult ring_simps)}
  2518   by (simp add: of_nat_mult ring_simps)}
  2519 then show ?thesis by (simp add: fps_eq_iff)
  2519 then show ?thesis by (simp add: fps_eq_iff)
  2520 qed
  2520 qed
  2521 
  2521 
  2522 lemma E_unique_ODE:
  2522 lemma E_unique_ODE:
  2528     by (simp add: fps_deriv_def fps_eq_iff field_simps del: of_nat_Suc)
  2528     by (simp add: fps_deriv_def fps_eq_iff field_simps del: of_nat_Suc)
  2529   {fix n have "a$n = a$0 * c ^ n/ (of_nat (fact n))"
  2529   {fix n have "a$n = a$0 * c ^ n/ (of_nat (fact n))"
  2530       apply (induct n)
  2530       apply (induct n)
  2531       apply simp
  2531       apply simp
  2532       unfolding th
  2532       unfolding th
  2533       using fact_gt_zero
  2533       using fact_gt_zero_nat
  2534       apply (simp add: field_simps del: of_nat_Suc fact.simps)
  2534       apply (simp add: field_simps del: of_nat_Suc fact_Suc_nat)
  2535       apply (drule sym)
  2535       apply (drule sym)
  2536       by (simp add: ring_simps of_nat_mult power_Suc)}
  2536       by (simp add: ring_simps of_nat_mult power_Suc)}
  2537   note th' = this
  2537   note th' = this
  2538   have ?rhs
  2538   have ?rhs
  2539     by (auto simp add: fps_eq_iff fps_const_mult_left E_def intro : th')}
  2539     by (auto simp add: fps_eq_iff fps_const_mult_left E_def intro : th')}
  2695     {assume en: "even n"
  2695     {assume en: "even n"
  2696       have "?lhs$n = of_nat (n+1) * (fps_sin c $ (n+1))" by simp
  2696       have "?lhs$n = of_nat (n+1) * (fps_sin c $ (n+1))" by simp
  2697       also have "\<dots> = of_nat (n+1) * ((- 1)^(n div 2) * c^Suc n / of_nat (fact (Suc n)))"
  2697       also have "\<dots> = of_nat (n+1) * ((- 1)^(n div 2) * c^Suc n / of_nat (fact (Suc n)))"
  2698 	using en by (simp add: fps_sin_def)
  2698 	using en by (simp add: fps_sin_def)
  2699       also have "\<dots> = (- 1)^(n div 2) * c^Suc n * (of_nat (n+1) / (of_nat (Suc n) * of_nat (fact n)))"
  2699       also have "\<dots> = (- 1)^(n div 2) * c^Suc n * (of_nat (n+1) / (of_nat (Suc n) * of_nat (fact n)))"
  2700 	unfolding fact_Suc of_nat_mult
  2700 	unfolding fact_Suc_nat of_nat_mult
  2701 	by (simp add: field_simps del: of_nat_add of_nat_Suc)
  2701 	by (simp add: field_simps del: of_nat_add of_nat_Suc)
  2702       also have "\<dots> = (- 1)^(n div 2) *c^Suc n / of_nat (fact n)"
  2702       also have "\<dots> = (- 1)^(n div 2) *c^Suc n / of_nat (fact n)"
  2703 	by (simp add: field_simps del: of_nat_add of_nat_Suc)
  2703 	by (simp add: field_simps del: of_nat_add of_nat_Suc)
  2704       finally have "?lhs $n = ?rhs$n" using en
  2704       finally have "?lhs $n = ?rhs$n" using en
  2705 	by (simp add: fps_cos_def ring_simps power_Suc )}
  2705 	by (simp add: fps_cos_def ring_simps power_Suc )}
  2719       from en have n0: "n \<noteq>0 " by presburger
  2719       from en have n0: "n \<noteq>0 " by presburger
  2720       have "?lhs$n = of_nat (n+1) * (fps_cos c $ (n+1))" by simp
  2720       have "?lhs$n = of_nat (n+1) * (fps_cos c $ (n+1))" by simp
  2721       also have "\<dots> = of_nat (n+1) * ((- 1)^((n + 1) div 2) * c^Suc n / of_nat (fact (Suc n)))"
  2721       also have "\<dots> = of_nat (n+1) * ((- 1)^((n + 1) div 2) * c^Suc n / of_nat (fact (Suc n)))"
  2722 	using en by (simp add: fps_cos_def)
  2722 	using en by (simp add: fps_cos_def)
  2723       also have "\<dots> = (- 1)^((n + 1) div 2)*c^Suc n * (of_nat (n+1) / (of_nat (Suc n) * of_nat (fact n)))"
  2723       also have "\<dots> = (- 1)^((n + 1) div 2)*c^Suc n * (of_nat (n+1) / (of_nat (Suc n) * of_nat (fact n)))"
  2724 	unfolding fact_Suc of_nat_mult
  2724 	unfolding fact_Suc_nat of_nat_mult
  2725 	by (simp add: field_simps del: of_nat_add of_nat_Suc)
  2725 	by (simp add: field_simps del: of_nat_add of_nat_Suc)
  2726       also have "\<dots> = (- 1)^((n + 1) div 2) * c^Suc n / of_nat (fact n)"
  2726       also have "\<dots> = (- 1)^((n + 1) div 2) * c^Suc n / of_nat (fact n)"
  2727 	by (simp add: field_simps del: of_nat_add of_nat_Suc)
  2727 	by (simp add: field_simps del: of_nat_add of_nat_Suc)
  2728       also have "\<dots> = (- ((- 1)^((n - 1) div 2))) * c^Suc n / of_nat (fact n)"
  2728       also have "\<dots> = (- ((- 1)^((n - 1) div 2))) * c^Suc n / of_nat (fact n)"
  2729 	unfolding th0 unfolding th1[OF en] by simp
  2729 	unfolding th0 unfolding th1[OF en] by simp
  2745   also have "\<dots> = 1"
  2745   also have "\<dots> = 1"
  2746     by (auto simp add: fps_eq_iff numeral_2_eq_2 fps_mult_nth fps_cos_def fps_sin_def)
  2746     by (auto simp add: fps_eq_iff numeral_2_eq_2 fps_mult_nth fps_cos_def fps_sin_def)
  2747   finally show ?thesis .
  2747   finally show ?thesis .
  2748 qed
  2748 qed
  2749 
  2749 
  2750 lemma fact_1 [simp]: "fact 1 = 1"
       
  2751 unfolding One_nat_def fact_Suc by simp
       
  2752 
       
  2753 lemma divide_eq_iff: "a \<noteq> (0::'a::field) \<Longrightarrow> x / a = y \<longleftrightarrow> x = y * a"
  2750 lemma divide_eq_iff: "a \<noteq> (0::'a::field) \<Longrightarrow> x / a = y \<longleftrightarrow> x = y * a"
  2754 by auto
  2751 by auto
  2755 
  2752 
  2756 lemma eq_divide_iff: "a \<noteq> (0::'a::field) \<Longrightarrow> x = y / a \<longleftrightarrow> x * a = y"
  2753 lemma eq_divide_iff: "a \<noteq> (0::'a::field) \<Longrightarrow> x = y / a \<longleftrightarrow> x * a = y"
  2757 by auto
  2754 by auto
  2764 
  2761 
  2765 lemma fps_sin_nth_add_2:
  2762 lemma fps_sin_nth_add_2:
  2766   "fps_sin c $ (n + 2) = - (c * c * fps_sin c $ n / (of_nat(n+1) * of_nat(n+2)))"
  2763   "fps_sin c $ (n + 2) = - (c * c * fps_sin c $ n / (of_nat(n+1) * of_nat(n+2)))"
  2767 unfolding fps_sin_def
  2764 unfolding fps_sin_def
  2768 apply (cases n, simp)
  2765 apply (cases n, simp)
  2769 apply (simp add: divide_eq_iff eq_divide_iff del: of_nat_Suc fact_Suc)
  2766 apply (simp add: divide_eq_iff eq_divide_iff del: of_nat_Suc fact_Suc_nat)
  2770 apply (simp add: of_nat_mult del: of_nat_Suc mult_Suc)
  2767 apply (simp add: of_nat_mult del: of_nat_Suc mult_Suc)
  2771 done
  2768 done
  2772 
  2769 
  2773 lemma fps_cos_nth_0 [simp]: "fps_cos c $ 0 = 1"
  2770 lemma fps_cos_nth_0 [simp]: "fps_cos c $ 0 = 1"
  2774 unfolding fps_cos_def by simp
  2771 unfolding fps_cos_def by simp
  2777 unfolding fps_cos_def by simp
  2774 unfolding fps_cos_def by simp
  2778 
  2775 
  2779 lemma fps_cos_nth_add_2:
  2776 lemma fps_cos_nth_add_2:
  2780   "fps_cos c $ (n + 2) = - (c * c * fps_cos c $ n / (of_nat(n+1) * of_nat(n+2)))"
  2777   "fps_cos c $ (n + 2) = - (c * c * fps_cos c $ n / (of_nat(n+1) * of_nat(n+2)))"
  2781 unfolding fps_cos_def
  2778 unfolding fps_cos_def
  2782 apply (simp add: divide_eq_iff eq_divide_iff del: of_nat_Suc fact_Suc)
  2779 apply (simp add: divide_eq_iff eq_divide_iff del: of_nat_Suc fact_Suc_nat)
  2783 apply (simp add: of_nat_mult del: of_nat_Suc mult_Suc)
  2780 apply (simp add: of_nat_mult del: of_nat_Suc mult_Suc)
  2784 done
  2781 done
  2785 
  2782 
  2786 lemma nat_induct2:
  2783 lemma nat_induct2:
  2787   "\<lbrakk>P 0; P 1; \<And>n. P n \<Longrightarrow> P (n + 2)\<rbrakk> \<Longrightarrow> P (n::nat)"
  2784   "\<lbrakk>P 0; P 1; \<And>n. P n \<Longrightarrow> P (n + 2)\<rbrakk> \<Longrightarrow> P (n::nat)"