src/HOL/Hyperreal/MacLaurin.thy
changeset 15079 2ef899e4526d
parent 14738 83f1a514dcb4
child 15081 32402f5624d1
     1.1 --- a/src/HOL/Hyperreal/MacLaurin.thy	Tue Jul 27 15:39:59 2004 +0200
     1.2 +++ b/src/HOL/Hyperreal/MacLaurin.thy	Wed Jul 28 10:49:29 2004 +0200
     1.3 @@ -2,48 +2,614 @@
     1.4      Author      : Jacques D. Fleuriot
     1.5      Copyright   : 2001 University of Edinburgh
     1.6      Description : MacLaurin series
     1.7 +    Conversion to Isar and new proofs by Lawrence C Paulson, 2004
     1.8  *)
     1.9  
    1.10 -theory MacLaurin = Log
    1.11 -files ("MacLaurin_lemmas.ML"):
    1.12 +theory MacLaurin = Log:
    1.13 +
    1.14 +lemma sumr_offset: "sumr 0 n (%m. f (m+k)) = sumr 0 (n+k) f - sumr 0 k f"
    1.15 +by (induct_tac "n", auto)
    1.16 +
    1.17 +lemma sumr_offset2: "\<forall>f. sumr 0 n (%m. f (m+k)) = sumr 0 (n+k) f - sumr 0 k f"
    1.18 +by (induct_tac "n", auto)
    1.19 +
    1.20 +lemma sumr_offset3: "sumr 0 (n+k) f = sumr 0 n (%m. f (m+k)) + sumr 0 k f"
    1.21 +by (simp  add: sumr_offset)
    1.22 +
    1.23 +lemma sumr_offset4: "\<forall>n f. sumr 0 (n+k) f = sumr 0 n (%m. f (m+k)) + sumr 0 k f"
    1.24 +by (simp add: sumr_offset)
    1.25 +
    1.26 +lemma sumr_from_1_from_0: "0 < n ==>
    1.27 +      sumr (Suc 0) (Suc n) (%n. (if even(n) then 0 else
    1.28 +             ((- 1) ^ ((n - (Suc 0)) div 2))/(real (fact n))) * a ^ n) =
    1.29 +      sumr 0 (Suc n) (%n. (if even(n) then 0 else
    1.30 +             ((- 1) ^ ((n - (Suc 0)) div 2))/(real (fact n))) * a ^ n)"
    1.31 +by (rule_tac n1 = 1 in sumr_split_add [THEN subst], auto)
    1.32 +
    1.33 +
    1.34 +subsection{*Maclaurin's Theorem with Lagrange Form of Remainder*}
    1.35 +
    1.36 +text{*This is a very long, messy proof even now that it's been broken down
    1.37 +into lemmas.*}
    1.38 +
    1.39 +lemma Maclaurin_lemma:
    1.40 +    "0 < h ==>
    1.41 +     \<exists>B. f h = sumr 0 n (%m. (j m / real (fact m)) * (h^m)) +
    1.42 +               (B * ((h^n) / real(fact n)))"
    1.43 +by (rule_tac x = "(f h - sumr 0 n (%m. (j m / real (fact m)) * h^m)) *
    1.44 +                 real(fact n) / (h^n)"
    1.45 +       in exI, auto)
    1.46 +
    1.47 +
    1.48 +lemma eq_diff_eq': "(x = y - z) = (y = x + (z::real))"
    1.49 +by arith
    1.50 +
    1.51 +text{*A crude tactic to differentiate by proof.*}
    1.52 +ML
    1.53 +{*
    1.54 +exception DERIV_name;
    1.55 +fun get_fun_name (_ $ (Const ("Lim.deriv",_) $ Abs(_,_, Const (f,_) $ _) $ _ $ _)) = f
    1.56 +|   get_fun_name (_ $ (_ $ (Const ("Lim.deriv",_) $ Abs(_,_, Const (f,_) $ _) $ _ $ _))) = f
    1.57 +|   get_fun_name _ = raise DERIV_name;
    1.58 +
    1.59 +val deriv_rulesI = [DERIV_Id,DERIV_const,DERIV_cos,DERIV_cmult,
    1.60 +                    DERIV_sin, DERIV_exp, DERIV_inverse,DERIV_pow,
    1.61 +                    DERIV_add, DERIV_diff, DERIV_mult, DERIV_minus,
    1.62 +                    DERIV_inverse_fun,DERIV_quotient,DERIV_fun_pow,
    1.63 +                    DERIV_fun_exp,DERIV_fun_sin,DERIV_fun_cos,
    1.64 +                    DERIV_Id,DERIV_const,DERIV_cos];
    1.65 +
    1.66 +val deriv_tac =
    1.67 +  SUBGOAL (fn (prem,i) =>
    1.68 +   (resolve_tac deriv_rulesI i) ORELSE
    1.69 +    ((rtac (read_instantiate [("f",get_fun_name prem)]
    1.70 +                     DERIV_chain2) i) handle DERIV_name => no_tac));;
    1.71 +
    1.72 +val DERIV_tac = ALLGOALS(fn i => REPEAT(deriv_tac i));
    1.73 +*}
    1.74 +
    1.75 +lemma Maclaurin_lemma2:
    1.76 +      "[| \<forall>m t. m < n \<and> 0\<le>t \<and> t\<le>h \<longrightarrow> DERIV (diff m) t :> diff (Suc m) t;
    1.77 +          n = Suc k;
    1.78 +        difg =
    1.79 +        (\<lambda>m t. diff m t -
    1.80 +               ((\<Sum>p = 0..<n - m. diff (m + p) 0 / real (fact p) * t ^ p) +
    1.81 +                B * (t ^ (n - m) / real (fact (n - m)))))|] ==>
    1.82 +        \<forall>m t. m < n & 0 \<le> t & t \<le> h -->
    1.83 +                    DERIV (difg m) t :> difg (Suc m) t"
    1.84 +apply clarify
    1.85 +apply (rule DERIV_diff)
    1.86 +apply (simp (no_asm_simp))
    1.87 +apply (tactic DERIV_tac)
    1.88 +apply (tactic DERIV_tac)
    1.89 +apply (rule_tac [2] lemma_DERIV_subst)
    1.90 +apply (rule_tac [2] DERIV_quotient)
    1.91 +apply (rule_tac [3] DERIV_const)
    1.92 +apply (rule_tac [2] DERIV_pow)
    1.93 +  prefer 3 apply (simp add: fact_diff_Suc)
    1.94 + prefer 2 apply simp
    1.95 +apply (frule_tac m = m in less_add_one, clarify)
    1.96 +apply (simp del: sumr_Suc)
    1.97 +apply (insert sumr_offset4 [of 1])
    1.98 +apply (simp del: sumr_Suc fact_Suc realpow_Suc)
    1.99 +apply (rule lemma_DERIV_subst)
   1.100 +apply (rule DERIV_add)
   1.101 +apply (rule_tac [2] DERIV_const)
   1.102 +apply (rule DERIV_sumr, clarify)
   1.103 + prefer 2 apply simp
   1.104 +apply (simp (no_asm) add: divide_inverse mult_assoc del: fact_Suc realpow_Suc)
   1.105 +apply (rule DERIV_cmult)
   1.106 +apply (rule lemma_DERIV_subst)
   1.107 +apply (best intro: DERIV_chain2 intro!: DERIV_intros)
   1.108 +apply (subst fact_Suc)
   1.109 +apply (subst real_of_nat_mult)
   1.110 +apply (simp add: inverse_mult_distrib mult_ac)
   1.111 +done
   1.112 +
   1.113 +
   1.114 +lemma Maclaurin_lemma3:
   1.115 +     "[|\<forall>k t. k < Suc m \<and> 0\<le>t & t\<le>h \<longrightarrow> DERIV (difg k) t :> difg (Suc k) t;
   1.116 +        \<forall>k<Suc m. difg k 0 = 0; DERIV (difg n) t :> 0;  n < m; 0 < t;
   1.117 +        t < h|]
   1.118 +     ==> \<exists>ta. 0 < ta & ta < t & DERIV (difg (Suc n)) ta :> 0"
   1.119 +apply (rule Rolle, assumption, simp)
   1.120 +apply (drule_tac x = n and P="%k. k<Suc m --> difg k 0 = 0" in spec)
   1.121 +apply (rule DERIV_unique)
   1.122 +prefer 2 apply assumption
   1.123 +apply force
   1.124 +apply (subgoal_tac "\<forall>ta. 0 \<le> ta & ta \<le> t --> (difg (Suc n)) differentiable ta")
   1.125 +apply (simp add: differentiable_def)
   1.126 +apply (blast dest!: DERIV_isCont)
   1.127 +apply (simp add: differentiable_def, clarify)
   1.128 +apply (rule_tac x = "difg (Suc (Suc n)) ta" in exI)
   1.129 +apply force
   1.130 +apply (simp add: differentiable_def, clarify)
   1.131 +apply (rule_tac x = "difg (Suc (Suc n)) x" in exI)
   1.132 +apply force
   1.133 +done
   1.134  
   1.135 -use "MacLaurin_lemmas.ML"
   1.136 +lemma Maclaurin:
   1.137 +   "[| 0 < h; 0 < n; diff 0 = f;
   1.138 +       \<forall>m t. m < n & 0 \<le> t & t \<le> h --> DERIV (diff m) t :> diff (Suc m) t |]
   1.139 +    ==> \<exists>t. 0 < t &
   1.140 +              t < h &
   1.141 +              f h =
   1.142 +              sumr 0 n (%m. (diff m 0 / real (fact m)) * h ^ m) +
   1.143 +              (diff n t / real (fact n)) * h ^ n"
   1.144 +apply (case_tac "n = 0", force)
   1.145 +apply (drule not0_implies_Suc)
   1.146 +apply (erule exE)
   1.147 +apply (frule_tac f=f and n=n and j="%m. diff m 0" in Maclaurin_lemma)
   1.148 +apply (erule exE)
   1.149 +apply (subgoal_tac "\<exists>g.
   1.150 +     g = (%t. f t - (sumr 0 n (%m. (diff m 0 / real(fact m)) * t^m) + (B * (t^n / real(fact n)))))")
   1.151 + prefer 2 apply blast
   1.152 +apply (erule exE)
   1.153 +apply (subgoal_tac "g 0 = 0 & g h =0")
   1.154 + prefer 2
   1.155 + apply (simp del: sumr_Suc)
   1.156 + apply (cut_tac n = m and k = 1 in sumr_offset2)
   1.157 + apply (simp add: eq_diff_eq' del: sumr_Suc)
   1.158 +apply (subgoal_tac "\<exists>difg. difg = (%m t. diff m t - (sumr 0 (n - m) (%p. (diff (m + p) 0 / real (fact p)) * (t ^ p)) + (B * ((t ^ (n - m)) / real (fact (n - m))))))")
   1.159 + prefer 2 apply blast
   1.160 +apply (erule exE)
   1.161 +apply (subgoal_tac "difg 0 = g")
   1.162 + prefer 2 apply simp
   1.163 +apply (frule Maclaurin_lemma2, assumption+)
   1.164 +apply (subgoal_tac "\<forall>ma. ma < n --> (\<exists>t. 0 < t & t < h & difg (Suc ma) t = 0) ")
   1.165 +apply (drule_tac x = m and P="%m. m<n --> (\<exists>t. ?QQ m t)" in spec)
   1.166 +apply (erule impE)
   1.167 +apply (simp (no_asm_simp))
   1.168 +apply (erule exE)
   1.169 +apply (rule_tac x = t in exI)
   1.170 +apply (simp del: realpow_Suc fact_Suc)
   1.171 +apply (subgoal_tac "\<forall>m. m < n --> difg m 0 = 0")
   1.172 + prefer 2
   1.173 + apply clarify
   1.174 + apply simp
   1.175 + apply (frule_tac m = ma in less_add_one, clarify)
   1.176 + apply (simp del: sumr_Suc)
   1.177 +apply (insert sumr_offset4 [of 1])
   1.178 +apply (simp del: sumr_Suc fact_Suc realpow_Suc)
   1.179 +apply (subgoal_tac "\<forall>m. m < n --> (\<exists>t. 0 < t & t < h & DERIV (difg m) t :> 0) ")
   1.180 +apply (rule allI, rule impI)
   1.181 +apply (drule_tac x = ma and P="%m. m<n --> (\<exists>t. ?QQ m t)" in spec)
   1.182 +apply (erule impE, assumption)
   1.183 +apply (erule exE)
   1.184 +apply (rule_tac x = t in exI)
   1.185 +(* do some tidying up *)
   1.186 +apply (erule_tac [!] V= "difg = (%m t. diff m t - (sumr 0 (n - m) (%p. diff (m + p) 0 / real (fact p) * t ^ p) + B * (t ^ (n - m) / real (fact (n - m)))))"
   1.187 +       in thin_rl)
   1.188 +apply (erule_tac [!] V="g = (%t. f t - (sumr 0 n (%m. diff m 0 / real (fact m) * t ^ m) + B * (t ^ n / real (fact n))))"
   1.189 +       in thin_rl)
   1.190 +apply (erule_tac [!] V="f h = sumr 0 n (%m. diff m 0 / real (fact m) * h ^ m) + B * (h ^ n / real (fact n))"
   1.191 +       in thin_rl)
   1.192 +(* back to business *)
   1.193 +apply (simp (no_asm_simp))
   1.194 +apply (rule DERIV_unique)
   1.195 +prefer 2 apply blast
   1.196 +apply force
   1.197 +apply (rule allI, induct_tac "ma")
   1.198 +apply (rule impI, rule Rolle, assumption, simp, simp)
   1.199 +apply (subgoal_tac "\<forall>t. 0 \<le> t & t \<le> h --> g differentiable t")
   1.200 +apply (simp add: differentiable_def)
   1.201 +apply (blast dest: DERIV_isCont)
   1.202 +apply (simp add: differentiable_def, clarify)
   1.203 +apply (rule_tac x = "difg (Suc 0) t" in exI)
   1.204 +apply force
   1.205 +apply (simp add: differentiable_def, clarify)
   1.206 +apply (rule_tac x = "difg (Suc 0) x" in exI)
   1.207 +apply force
   1.208 +apply safe
   1.209 +apply force
   1.210 +apply (frule Maclaurin_lemma3, assumption+, safe)
   1.211 +apply (rule_tac x = ta in exI, force)
   1.212 +done
   1.213 +
   1.214 +lemma Maclaurin_objl:
   1.215 +     "0 < h & 0 < n & diff 0 = f &
   1.216 +       (\<forall>m t. m < n & 0 \<le> t & t \<le> h --> DERIV (diff m) t :> diff (Suc m) t)
   1.217 +    --> (\<exists>t. 0 < t &
   1.218 +              t < h &
   1.219 +              f h =
   1.220 +              sumr 0 n (%m. diff m 0 / real (fact m) * h ^ m) +
   1.221 +              diff n t / real (fact n) * h ^ n)"
   1.222 +by (blast intro: Maclaurin)
   1.223 +
   1.224 +
   1.225 +lemma Maclaurin2:
   1.226 +   "[| 0 < h; diff 0 = f;
   1.227 +       \<forall>m t.
   1.228 +          m < n & 0 \<le> t & t \<le> h --> DERIV (diff m) t :> diff (Suc m) t |]
   1.229 +    ==> \<exists>t. 0 < t &
   1.230 +              t \<le> h &
   1.231 +              f h =
   1.232 +              sumr 0 n (%m. diff m 0 / real (fact m) * h ^ m) +
   1.233 +              diff n t / real (fact n) * h ^ n"
   1.234 +apply (case_tac "n", auto)
   1.235 +apply (drule Maclaurin, auto)
   1.236 +done
   1.237 +
   1.238 +lemma Maclaurin2_objl:
   1.239 +     "0 < h & diff 0 = f &
   1.240 +       (\<forall>m t.
   1.241 +          m < n & 0 \<le> t & t \<le> h --> DERIV (diff m) t :> diff (Suc m) t)
   1.242 +    --> (\<exists>t. 0 < t &
   1.243 +              t \<le> h &
   1.244 +              f h =
   1.245 +              sumr 0 n (%m. diff m 0 / real (fact m) * h ^ m) +
   1.246 +              diff n t / real (fact n) * h ^ n)"
   1.247 +by (blast intro: Maclaurin2)
   1.248 +
   1.249 +lemma Maclaurin_minus:
   1.250 +   "[| h < 0; 0 < n; diff 0 = f;
   1.251 +       \<forall>m t. m < n & h \<le> t & t \<le> 0 --> DERIV (diff m) t :> diff (Suc m) t |]
   1.252 +    ==> \<exists>t. h < t &
   1.253 +              t < 0 &
   1.254 +              f h =
   1.255 +              sumr 0 n (%m. diff m 0 / real (fact m) * h ^ m) +
   1.256 +              diff n t / real (fact n) * h ^ n"
   1.257 +apply (cut_tac f = "%x. f (-x)"
   1.258 +        and diff = "%n x. ((- 1) ^ n) * diff n (-x)"
   1.259 +        and h = "-h" and n = n in Maclaurin_objl)
   1.260 +apply simp
   1.261 +apply safe
   1.262 +apply (subst minus_mult_right)
   1.263 +apply (rule DERIV_cmult)
   1.264 +apply (rule lemma_DERIV_subst)
   1.265 +apply (rule DERIV_chain2 [where g=uminus])
   1.266 +apply (rule_tac [2] DERIV_minus, rule_tac [2] DERIV_Id)
   1.267 +prefer 2 apply force
   1.268 +apply force
   1.269 +apply (rule_tac x = "-t" in exI, auto)
   1.270 +apply (subgoal_tac "(\<Sum>m = 0..<n. -1 ^ m * diff m 0 * (-h)^m / real(fact m)) =
   1.271 +                    (\<Sum>m = 0..<n. diff m 0 * h ^ m / real(fact m))")
   1.272 +apply (rule_tac [2] sumr_fun_eq)
   1.273 +apply (auto simp add: divide_inverse power_mult_distrib [symmetric])
   1.274 +done
   1.275 +
   1.276 +lemma Maclaurin_minus_objl:
   1.277 +     "(h < 0 & 0 < n & diff 0 = f &
   1.278 +       (\<forall>m t.
   1.279 +          m < n & h \<le> t & t \<le> 0 --> DERIV (diff m) t :> diff (Suc m) t))
   1.280 +    --> (\<exists>t. h < t &
   1.281 +              t < 0 &
   1.282 +              f h =
   1.283 +              sumr 0 n (%m. diff m 0 / real (fact m) * h ^ m) +
   1.284 +              diff n t / real (fact n) * h ^ n)"
   1.285 +by (blast intro: Maclaurin_minus)
   1.286 +
   1.287 +
   1.288 +subsection{*More Convenient "Bidirectional" Version.*}
   1.289 +
   1.290 +(* not good for PVS sin_approx, cos_approx *)
   1.291 +
   1.292 +lemma Maclaurin_bi_le_lemma [rule_format]:
   1.293 +     "0 < n \<longrightarrow>
   1.294 +       diff 0 0 =
   1.295 +       (\<Sum>m = 0..<n. diff m 0 * 0 ^ m / real (fact m)) +
   1.296 +       diff n 0 * 0 ^ n / real (fact n)"
   1.297 +by (induct_tac "n", auto)
   1.298  
   1.299 -lemma Maclaurin_sin_bound: 
   1.300 -  "abs(sin x - sumr 0 n (%m. (if even m then 0 else ((- 1) ^ ((m - (Suc 0)) div 2)) / real (fact m)) * 
   1.301 -  x ^ m))  <= inverse(real (fact n)) * abs(x) ^ n"
   1.302 +lemma Maclaurin_bi_le:
   1.303 +   "[| diff 0 = f;
   1.304 +       \<forall>m t. m < n & abs t \<le> abs x --> DERIV (diff m) t :> diff (Suc m) t |]
   1.305 +    ==> \<exists>t. abs t \<le> abs x &
   1.306 +              f x =
   1.307 +              sumr 0 n (%m. diff m 0 / real (fact m) * x ^ m) +
   1.308 +              diff n t / real (fact n) * x ^ n"
   1.309 +apply (case_tac "n = 0", force)
   1.310 +apply (case_tac "x = 0")
   1.311 +apply (rule_tac x = 0 in exI)
   1.312 +apply (force simp add: Maclaurin_bi_le_lemma)
   1.313 +apply (cut_tac x = x and y = 0 in linorder_less_linear, auto)
   1.314 +txt{*Case 1, where @{term "x < 0"}*}
   1.315 +apply (cut_tac f = "diff 0" and diff = diff and h = x and n = n in Maclaurin_minus_objl, safe)
   1.316 +apply (simp add: abs_if)
   1.317 +apply (rule_tac x = t in exI)
   1.318 +apply (simp add: abs_if)
   1.319 +txt{*Case 2, where @{term "0 < x"}*}
   1.320 +apply (cut_tac f = "diff 0" and diff = diff and h = x and n = n in Maclaurin_objl, safe)
   1.321 +apply (simp add: abs_if)
   1.322 +apply (rule_tac x = t in exI)
   1.323 +apply (simp add: abs_if)
   1.324 +done
   1.325 +
   1.326 +lemma Maclaurin_all_lt:
   1.327 +     "[| diff 0 = f;
   1.328 +         \<forall>m x. DERIV (diff m) x :> diff(Suc m) x;
   1.329 +        x ~= 0; 0 < n
   1.330 +      |] ==> \<exists>t. 0 < abs t & abs t < abs x &
   1.331 +               f x = sumr 0 n (%m. (diff m 0 / real (fact m)) * x ^ m) +
   1.332 +                     (diff n t / real (fact n)) * x ^ n"
   1.333 +apply (rule_tac x = x and y = 0 in linorder_cases)
   1.334 +prefer 2 apply blast
   1.335 +apply (drule_tac [2] diff=diff in Maclaurin)
   1.336 +apply (drule_tac diff=diff in Maclaurin_minus, simp_all, safe)
   1.337 +apply (rule_tac [!] x = t in exI, auto, arith+)
   1.338 +done
   1.339 +
   1.340 +lemma Maclaurin_all_lt_objl:
   1.341 +     "diff 0 = f &
   1.342 +      (\<forall>m x. DERIV (diff m) x :> diff(Suc m) x) &
   1.343 +      x ~= 0 & 0 < n
   1.344 +      --> (\<exists>t. 0 < abs t & abs t < abs x &
   1.345 +               f x = sumr 0 n (%m. (diff m 0 / real (fact m)) * x ^ m) +
   1.346 +                     (diff n t / real (fact n)) * x ^ n)"
   1.347 +by (blast intro: Maclaurin_all_lt)
   1.348 +
   1.349 +lemma Maclaurin_zero [rule_format]:
   1.350 +     "x = (0::real)
   1.351 +      ==> 0 < n -->
   1.352 +          sumr 0 n (%m. (diff m (0::real) / real (fact m)) * x ^ m) =
   1.353 +          diff 0 0"
   1.354 +by (induct n, auto)
   1.355 +
   1.356 +lemma Maclaurin_all_le: "[| diff 0 = f;
   1.357 +        \<forall>m x. DERIV (diff m) x :> diff (Suc m) x
   1.358 +      |] ==> \<exists>t. abs t \<le> abs x &
   1.359 +              f x = sumr 0 n (%m. (diff m 0 / real (fact m)) * x ^ m) +
   1.360 +                    (diff n t / real (fact n)) * x ^ n"
   1.361 +apply (insert linorder_le_less_linear [of n 0])
   1.362 +apply (erule disjE, force)
   1.363 +apply (case_tac "x = 0")
   1.364 +apply (frule_tac diff = diff and n = n in Maclaurin_zero, assumption)
   1.365 +apply (drule gr_implies_not0 [THEN not0_implies_Suc])
   1.366 +apply (rule_tac x = 0 in exI, force)
   1.367 +apply (frule_tac diff = diff and n = n in Maclaurin_all_lt, auto)
   1.368 +apply (rule_tac x = t in exI, auto)
   1.369 +done
   1.370 +
   1.371 +lemma Maclaurin_all_le_objl: "diff 0 = f &
   1.372 +      (\<forall>m x. DERIV (diff m) x :> diff (Suc m) x)
   1.373 +      --> (\<exists>t. abs t \<le> abs x &
   1.374 +              f x = sumr 0 n (%m. (diff m 0 / real (fact m)) * x ^ m) +
   1.375 +                    (diff n t / real (fact n)) * x ^ n)"
   1.376 +by (blast intro: Maclaurin_all_le)
   1.377 +
   1.378 +
   1.379 +subsection{*Version for Exponential Function*}
   1.380 +
   1.381 +lemma Maclaurin_exp_lt: "[| x ~= 0; 0 < n |]
   1.382 +      ==> (\<exists>t. 0 < abs t &
   1.383 +                abs t < abs x &
   1.384 +                exp x = sumr 0 n (%m. (x ^ m) / real (fact m)) +
   1.385 +                        (exp t / real (fact n)) * x ^ n)"
   1.386 +by (cut_tac diff = "%n. exp" and f = exp and x = x and n = n in Maclaurin_all_lt_objl, auto)
   1.387 +
   1.388 +
   1.389 +lemma Maclaurin_exp_le:
   1.390 +     "\<exists>t. abs t \<le> abs x &
   1.391 +            exp x = sumr 0 n (%m. (x ^ m) / real (fact m)) +
   1.392 +                       (exp t / real (fact n)) * x ^ n"
   1.393 +by (cut_tac diff = "%n. exp" and f = exp and x = x and n = n in Maclaurin_all_le_objl, auto)
   1.394 +
   1.395 +
   1.396 +subsection{*Version for Sine Function*}
   1.397 +
   1.398 +lemma MVT2:
   1.399 +     "[| a < b; \<forall>x. a \<le> x & x \<le> b --> DERIV f x :> f'(x) |]
   1.400 +      ==> \<exists>z. a < z & z < b & (f b - f a = (b - a) * f'(z))"
   1.401 +apply (drule MVT)
   1.402 +apply (blast intro: DERIV_isCont)
   1.403 +apply (force dest: order_less_imp_le simp add: differentiable_def)
   1.404 +apply (blast dest: DERIV_unique order_less_imp_le)
   1.405 +done
   1.406 +
   1.407 +lemma mod_exhaust_less_4:
   1.408 +     "m mod 4 = 0 | m mod 4 = 1 | m mod 4 = 2 | m mod 4 = (3::nat)"
   1.409 +by (case_tac "m mod 4", auto, arith)
   1.410 +
   1.411 +lemma Suc_Suc_mult_two_diff_two [rule_format, simp]:
   1.412 +     "0 < n --> Suc (Suc (2 * n - 2)) = 2*n"
   1.413 +by (induct_tac "n", auto)
   1.414 +
   1.415 +lemma lemma_Suc_Suc_4n_diff_2 [rule_format, simp]:
   1.416 +     "0 < n --> Suc (Suc (4*n - 2)) = 4*n"
   1.417 +by (induct_tac "n", auto)
   1.418 +
   1.419 +lemma Suc_mult_two_diff_one [rule_format, simp]:
   1.420 +      "0 < n --> Suc (2 * n - 1) = 2*n"
   1.421 +by (induct_tac "n", auto)
   1.422 +
   1.423 +lemma Maclaurin_sin_expansion:
   1.424 +     "\<exists>t. sin x =
   1.425 +       (sumr 0 n (%m. (if even m then 0
   1.426 +                       else ((- 1) ^ ((m - (Suc 0)) div 2)) / real (fact m)) *
   1.427 +                       x ^ m))
   1.428 +      + ((sin(t + 1/2 * real (n) *pi) / real (fact n)) * x ^ n)"
   1.429 +apply (cut_tac f = sin and n = n and x = x and diff = "%n x. sin (x + 1/2*real (n) *pi)" in Maclaurin_all_lt_objl)
   1.430 +apply safe
   1.431 +apply (simp (no_asm))
   1.432 +apply (simp (no_asm))
   1.433 +apply (case_tac "n", clarify, simp)
   1.434 +apply (drule_tac x = 0 in spec, simp, simp)
   1.435 +apply (rule ccontr, simp)
   1.436 +apply (drule_tac x = x in spec, simp)
   1.437 +apply (erule ssubst)
   1.438 +apply (rule_tac x = t in exI, simp)
   1.439 +apply (rule sumr_fun_eq)
   1.440 +apply (auto simp add: odd_Suc_mult_two_ex)
   1.441 +apply (auto simp add: even_mult_two_ex simp del: fact_Suc realpow_Suc)
   1.442 +(*Could sin_zero_iff help?*)
   1.443 +done
   1.444 +
   1.445 +lemma Maclaurin_sin_expansion2:
   1.446 +     "\<exists>t. abs t \<le> abs x &
   1.447 +       sin x =
   1.448 +       (sumr 0 n (%m. (if even m then 0
   1.449 +                       else ((- 1) ^ ((m - (Suc 0)) div 2)) / real (fact m)) *
   1.450 +                       x ^ m))
   1.451 +      + ((sin(t + 1/2 * real (n) *pi) / real (fact n)) * x ^ n)"
   1.452 +apply (cut_tac f = sin and n = n and x = x
   1.453 +        and diff = "%n x. sin (x + 1/2*real n * pi)" in Maclaurin_all_lt_objl)
   1.454 +apply safe
   1.455 +apply (simp (no_asm))
   1.456 +apply (simp (no_asm))
   1.457 +apply (case_tac "n", clarify, simp, simp)
   1.458 +apply (rule ccontr, simp)
   1.459 +apply (drule_tac x = x in spec, simp)
   1.460 +apply (erule ssubst)
   1.461 +apply (rule_tac x = t in exI, simp)
   1.462 +apply (rule sumr_fun_eq)
   1.463 +apply (auto simp add: odd_Suc_mult_two_ex)
   1.464 +apply (auto simp add: even_mult_two_ex simp del: fact_Suc realpow_Suc)
   1.465 +done
   1.466 +
   1.467 +lemma Maclaurin_sin_expansion3:
   1.468 +     "[| 0 < n; 0 < x |] ==>
   1.469 +       \<exists>t. 0 < t & t < x &
   1.470 +       sin x =
   1.471 +       (sumr 0 n (%m. (if even m then 0
   1.472 +                       else ((- 1) ^ ((m - (Suc 0)) div 2)) / real (fact m)) *
   1.473 +                       x ^ m))
   1.474 +      + ((sin(t + 1/2 * real(n) *pi) / real (fact n)) * x ^ n)"
   1.475 +apply (cut_tac f = sin and n = n and h = x and diff = "%n x. sin (x + 1/2*real (n) *pi)" in Maclaurin_objl)
   1.476 +apply safe
   1.477 +apply simp
   1.478 +apply (simp (no_asm))
   1.479 +apply (erule ssubst)
   1.480 +apply (rule_tac x = t in exI, simp)
   1.481 +apply (rule sumr_fun_eq)
   1.482 +apply (auto simp add: odd_Suc_mult_two_ex)
   1.483 +apply (auto simp add: even_mult_two_ex simp del: fact_Suc realpow_Suc)
   1.484 +done
   1.485 +
   1.486 +lemma Maclaurin_sin_expansion4:
   1.487 +     "0 < x ==>
   1.488 +       \<exists>t. 0 < t & t \<le> x &
   1.489 +       sin x =
   1.490 +       (sumr 0 n (%m. (if even m then 0
   1.491 +                       else ((- 1) ^ ((m - (Suc 0)) div 2)) / real (fact m)) *
   1.492 +                       x ^ m))
   1.493 +      + ((sin(t + 1/2 * real (n) *pi) / real (fact n)) * x ^ n)"
   1.494 +apply (cut_tac f = sin and n = n and h = x and diff = "%n x. sin (x + 1/2*real (n) *pi)" in Maclaurin2_objl)
   1.495 +apply safe
   1.496 +apply simp
   1.497 +apply (simp (no_asm))
   1.498 +apply (erule ssubst)
   1.499 +apply (rule_tac x = t in exI, simp)
   1.500 +apply (rule sumr_fun_eq)
   1.501 +apply (auto simp add: odd_Suc_mult_two_ex)
   1.502 +apply (auto simp add: even_mult_two_ex simp del: fact_Suc realpow_Suc)
   1.503 +done
   1.504 +
   1.505 +
   1.506 +subsection{*Maclaurin Expansion for Cosine Function*}
   1.507 +
   1.508 +lemma sumr_cos_zero_one [simp]:
   1.509 +     "sumr 0 (Suc n)
   1.510 +         (%m. (if even m
   1.511 +               then (- 1) ^ (m div 2)/(real  (fact m))
   1.512 +               else 0) *
   1.513 +              0 ^ m) = 1"
   1.514 +by (induct_tac "n", auto)
   1.515 +
   1.516 +lemma Maclaurin_cos_expansion:
   1.517 +     "\<exists>t. abs t \<le> abs x &
   1.518 +       cos x =
   1.519 +       (sumr 0 n (%m. (if even m
   1.520 +                       then (- 1) ^ (m div 2)/(real (fact m))
   1.521 +                       else 0) *
   1.522 +                       x ^ m))
   1.523 +      + ((cos(t + 1/2 * real (n) *pi) / real (fact n)) * x ^ n)"
   1.524 +apply (cut_tac f = cos and n = n and x = x and diff = "%n x. cos (x + 1/2*real (n) *pi)" in Maclaurin_all_lt_objl)
   1.525 +apply safe
   1.526 +apply (simp (no_asm))
   1.527 +apply (simp (no_asm))
   1.528 +apply (case_tac "n", simp)
   1.529 +apply (simp del: sumr_Suc)
   1.530 +apply (rule ccontr, simp)
   1.531 +apply (drule_tac x = x in spec, simp)
   1.532 +apply (erule ssubst)
   1.533 +apply (rule_tac x = t in exI, simp)
   1.534 +apply (rule sumr_fun_eq)
   1.535 +apply (auto simp add: odd_Suc_mult_two_ex)
   1.536 +apply (auto simp add: even_mult_two_ex left_distrib cos_add simp del: fact_Suc realpow_Suc)
   1.537 +apply (simp add: mult_commute [of _ pi])
   1.538 +done
   1.539 +
   1.540 +lemma Maclaurin_cos_expansion2:
   1.541 +     "[| 0 < x; 0 < n |] ==>
   1.542 +       \<exists>t. 0 < t & t < x &
   1.543 +       cos x =
   1.544 +       (sumr 0 n (%m. (if even m
   1.545 +                       then (- 1) ^ (m div 2)/(real (fact m))
   1.546 +                       else 0) *
   1.547 +                       x ^ m))
   1.548 +      + ((cos(t + 1/2 * real (n) *pi) / real (fact n)) * x ^ n)"
   1.549 +apply (cut_tac f = cos and n = n and h = x and diff = "%n x. cos (x + 1/2*real (n) *pi)" in Maclaurin_objl)
   1.550 +apply safe
   1.551 +apply simp
   1.552 +apply (simp (no_asm))
   1.553 +apply (erule ssubst)
   1.554 +apply (rule_tac x = t in exI, simp)
   1.555 +apply (rule sumr_fun_eq)
   1.556 +apply (auto simp add: odd_Suc_mult_two_ex)
   1.557 +apply (auto simp add: even_mult_two_ex left_distrib cos_add simp del: fact_Suc realpow_Suc)
   1.558 +apply (simp add: mult_commute [of _ pi])
   1.559 +done
   1.560 +
   1.561 +lemma Maclaurin_minus_cos_expansion: "[| x < 0; 0 < n |] ==>
   1.562 +       \<exists>t. x < t & t < 0 &
   1.563 +       cos x =
   1.564 +       (sumr 0 n (%m. (if even m
   1.565 +                       then (- 1) ^ (m div 2)/(real (fact m))
   1.566 +                       else 0) *
   1.567 +                       x ^ m))
   1.568 +      + ((cos(t + 1/2 * real (n) *pi) / real (fact n)) * x ^ n)"
   1.569 +apply (cut_tac f = cos and n = n and h = x and diff = "%n x. cos (x + 1/2*real (n) *pi)" in Maclaurin_minus_objl)
   1.570 +apply safe
   1.571 +apply simp
   1.572 +apply (simp (no_asm))
   1.573 +apply (erule ssubst)
   1.574 +apply (rule_tac x = t in exI, simp)
   1.575 +apply (rule sumr_fun_eq)
   1.576 +apply (auto simp add: odd_Suc_mult_two_ex)
   1.577 +apply (auto simp add: even_mult_two_ex left_distrib cos_add simp del: fact_Suc realpow_Suc)
   1.578 +apply (simp add: mult_commute [of _ pi])
   1.579 +done
   1.580 +
   1.581 +(* ------------------------------------------------------------------------- *)
   1.582 +(* Version for ln(1 +/- x). Where is it??                                    *)
   1.583 +(* ------------------------------------------------------------------------- *)
   1.584 +
   1.585 +lemma sin_bound_lemma:
   1.586 +    "[|x = y; abs u \<le> (v::real) |] ==> abs ((x + u) - y) \<le> v"
   1.587 +by auto
   1.588 +
   1.589 +lemma Maclaurin_sin_bound:
   1.590 +  "abs(sin x - sumr 0 n (%m. (if even m then 0 else ((- 1) ^ ((m - (Suc 0)) div 2)) / real (fact m)) *
   1.591 +  x ^ m))  \<le> inverse(real (fact n)) * abs(x) ^ n"
   1.592  proof -
   1.593 -  have "!! x (y::real). x <= 1 \<Longrightarrow> 0 <= y \<Longrightarrow> x * y \<le> 1 * y" 
   1.594 +  have "!! x (y::real). x \<le> 1 \<Longrightarrow> 0 \<le> y \<Longrightarrow> x * y \<le> 1 * y"
   1.595      by (rule_tac mult_right_mono,simp_all)
   1.596    note est = this[simplified]
   1.597    show ?thesis
   1.598 -    apply (cut_tac f=sin and n=n and x=x and 
   1.599 +    apply (cut_tac f=sin and n=n and x=x and
   1.600        diff = "%n x. if n mod 4 = 0 then sin(x) else if n mod 4 = 1 then cos(x) else if n mod 4 = 2 then -sin(x) else -cos(x)"
   1.601        in Maclaurin_all_le_objl)
   1.602 -    apply (tactic{* (Step_tac 1) *})
   1.603 -    apply (simp)
   1.604 +    apply safe
   1.605 +    apply simp
   1.606      apply (subst mod_Suc_eq_Suc_mod)
   1.607 -    apply (tactic{* cut_inst_tac [("m1","m")] (CLAIM "0 < (4::nat)" RS mod_less_divisor RS lemma_exhaust_less_4) 1*})
   1.608 -    apply (tactic{* Step_tac 1 *})
   1.609 -    apply (simp)+
   1.610 +    apply (cut_tac m=m in mod_exhaust_less_4, safe, simp+)
   1.611      apply (rule DERIV_minus, simp+)
   1.612      apply (rule lemma_DERIV_subst, rule DERIV_minus, rule DERIV_cos, simp)
   1.613 -    apply (tactic{* dtac ssubst 1 THEN assume_tac 2 *})
   1.614 -    apply (tactic {* rtac (ARITH_PROVE "[|x = y; abs u <= (v::real) |] ==> abs ((x + u) - y) <= v") 1 *})
   1.615 -    apply (rule sumr_fun_eq)
   1.616 -    apply (tactic{* Step_tac 1 *})
   1.617 -    apply (tactic{*rtac (CLAIM "x = y ==> x * z = y * (z::real)") 1*})
   1.618 +    apply (erule ssubst)
   1.619 +    apply (rule sin_bound_lemma)
   1.620 +    apply (rule sumr_fun_eq, safe)
   1.621 +    apply (rule_tac f = "%u. u * (x^r)" in arg_cong)
   1.622      apply (subst even_even_mod_4_iff)
   1.623 -    apply (tactic{* cut_inst_tac [("m1","r")] (CLAIM "0 < (4::nat)" RS mod_less_divisor RS lemma_exhaust_less_4) 1 *})
   1.624 -    apply (tactic{* Step_tac 1 *})
   1.625 -    apply (simp)
   1.626 +    apply (cut_tac m=r in mod_exhaust_less_4, simp, safe)
   1.627      apply (simp_all add:even_num_iff)
   1.628      apply (drule lemma_even_mod_4_div_2[simplified])
   1.629 -    apply(simp add: numeral_2_eq_2 real_divide_def)
   1.630 -    apply (drule lemma_odd_mod_4_div_2 );
   1.631 -    apply (simp add: numeral_2_eq_2 real_divide_def)
   1.632 -    apply (auto intro: real_mult_le_lemma mult_right_mono simp add: est mult_pos_le mult_ac real_divide_def abs_mult abs_inverse power_abs[symmetric])
   1.633 +    apply(simp add: numeral_2_eq_2 divide_inverse)
   1.634 +    apply (drule lemma_odd_mod_4_div_2)
   1.635 +    apply (simp add: numeral_2_eq_2 divide_inverse)
   1.636 +    apply (auto intro: mult_right_mono [where b=1, simplified] mult_right_mono
   1.637 +                   simp add: est mult_pos_le mult_ac divide_inverse
   1.638 +                          power_abs [symmetric])
   1.639      done
   1.640  qed
   1.641  
   1.642 -end
   1.643 \ No newline at end of file
   1.644 +end