src/HOL/Hyperreal/Transcendental.thy
changeset 15546 5188ce7316b7
parent 15544 5f3ef1ddda1f
child 15561 045a07ac35a7
equal deleted inserted replaced
15545:0efa7126003f 15546:5188ce7316b7
    17 
    17 
    18     sqrt :: "real => real"
    18     sqrt :: "real => real"
    19     "sqrt x == root 2 x"
    19     "sqrt x == root 2 x"
    20 
    20 
    21     exp :: "real => real"
    21     exp :: "real => real"
    22     "exp x == suminf(%n. inverse(real (fact n)) * (x ^ n))"
    22     "exp x == \<Sum>n. inverse(real (fact n)) * (x ^ n)"
    23 
    23 
    24     sin :: "real => real"
    24     sin :: "real => real"
    25     "sin x == suminf(%n. (if even(n) then 0 else
    25     "sin x == \<Sum>n. (if even(n) then 0 else
    26              ((- 1) ^ ((n - Suc 0) div 2))/(real (fact n))) * x ^ n)"
    26              ((- 1) ^ ((n - Suc 0) div 2))/(real (fact n))) * x ^ n"
    27  
    27  
    28     diffs :: "(nat => real) => nat => real"
    28     diffs :: "(nat => real) => nat => real"
    29     "diffs c == (%n. real (Suc n) * c(Suc n))"
    29     "diffs c == (%n. real (Suc n) * c(Suc n))"
    30 
    30 
    31     cos :: "real => real"
    31     cos :: "real => real"
    32     "cos x == suminf(%n. (if even(n) then ((- 1) ^ (n div 2))/(real (fact n)) 
    32     "cos x == \<Sum>n. (if even(n) then ((- 1) ^ (n div 2))/(real (fact n)) 
    33                           else 0) * x ^ n)"
    33                           else 0) * x ^ n"
    34   
    34   
    35     ln :: "real => real"
    35     ln :: "real => real"
    36     "ln x == (@u. exp u = x)"
    36     "ln x == (@u. exp u = x)"
    37 
    37 
    38     pi :: "real"
    38     pi :: "real"
   450 
   450 
   451 
   451 
   452 lemma diffs_equiv:
   452 lemma diffs_equiv:
   453      "summable (%n. (diffs c)(n) * (x ^ n)) ==>  
   453      "summable (%n. (diffs c)(n) * (x ^ n)) ==>  
   454       (%n. real n * c(n) * (x ^ (n - Suc 0))) sums  
   454       (%n. real n * c(n) * (x ^ (n - Suc 0))) sums  
   455          (suminf(%n. (diffs c)(n) * (x ^ n)))"
   455          (\<Sum>n. (diffs c)(n) * (x ^ n))"
   456 apply (subgoal_tac " (%n. real n * c (n) * (x ^ (n - Suc 0))) ----> 0")
   456 apply (subgoal_tac " (%n. real n * c (n) * (x ^ (n - Suc 0))) ----> 0")
   457 apply (rule_tac [2] LIMSEQ_imp_Suc)
   457 apply (rule_tac [2] LIMSEQ_imp_Suc)
   458 apply (drule summable_sums) 
   458 apply (drule summable_sums) 
   459 apply (auto simp add: sums_def)
   459 apply (auto simp add: sums_def)
   460 apply (drule_tac X="(\<lambda>n. \<Sum>n = 0..<n. diffs c n * x ^ n)" in LIMSEQ_diff)
   460 apply (drule_tac X="(\<lambda>n. \<Sum>n = 0..<n. diffs c n * x ^ n)" in LIMSEQ_diff)
   569  apply (drule_tac c = "\<bar>h\<bar>" in sums_mult)
   569  apply (drule_tac c = "\<bar>h\<bar>" in sums_mult)
   570  apply (simp add: mult_ac) 
   570  apply (simp add: mult_ac) 
   571 apply (subgoal_tac "summable (%n. abs (g (h::real) (n::nat))) ")
   571 apply (subgoal_tac "summable (%n. abs (g (h::real) (n::nat))) ")
   572  apply (rule_tac [2] g = "%n. f n * \<bar>h\<bar>" in summable_comparison_test)
   572  apply (rule_tac [2] g = "%n. f n * \<bar>h\<bar>" in summable_comparison_test)
   573   apply (rule_tac [2] x = 0 in exI, auto)
   573   apply (rule_tac [2] x = 0 in exI, auto)
   574 apply (rule_tac j = "suminf (%n. \<bar>g h n\<bar>)" in real_le_trans)
   574 apply (rule_tac j = "\<Sum>n. \<bar>g h n\<bar>" in real_le_trans)
   575 apply (auto intro: summable_rabs summable_le simp add: sums_summable [THEN suminf_mult])
   575 apply (auto intro: summable_rabs summable_le simp add: sums_summable [THEN suminf_mult])
   576 done
   576 done
   577 
   577 
   578 
   578 
   579 
   579 
   580 text{* FIXME: Long proofs*}
   580 text{* FIXME: Long proofs*}
   581 
   581 
   582 lemma termdiffs_aux:
   582 lemma termdiffs_aux:
   583      "[|summable (\<lambda>n. diffs (diffs c) n * K ^ n); \<bar>x\<bar> < \<bar>K\<bar> |]
   583      "[|summable (\<lambda>n. diffs (diffs c) n * K ^ n); \<bar>x\<bar> < \<bar>K\<bar> |]
   584     ==> (\<lambda>h. suminf
   584     ==> (\<lambda>h. \<Sum>n. c n *
   585              (\<lambda>n. c n *
       
   586                   (((x + h) ^ n - x ^ n) * inverse h -
   585                   (((x + h) ^ n - x ^ n) * inverse h -
   587                    real n * x ^ (n - Suc 0))))
   586                    real n * x ^ (n - Suc 0)))
   588        -- 0 --> 0"
   587        -- 0 --> 0"
   589 apply (drule dense, safe)
   588 apply (drule dense, safe)
   590 apply (frule real_less_sum_gt_zero)
   589 apply (frule real_less_sum_gt_zero)
   591 apply (drule_tac
   590 apply (drule_tac
   592          f = "%n. \<bar>c n\<bar> * real n * real (n - Suc 0) * (r ^ (n - 2))" 
   591          f = "%n. \<bar>c n\<bar> * real n * real (n - Suc 0) * (r ^ (n - 2))" 
   646 lemma termdiffs: 
   645 lemma termdiffs: 
   647     "[| summable(%n. c(n) * (K ^ n));  
   646     "[| summable(%n. c(n) * (K ^ n));  
   648         summable(%n. (diffs c)(n) * (K ^ n));  
   647         summable(%n. (diffs c)(n) * (K ^ n));  
   649         summable(%n. (diffs(diffs c))(n) * (K ^ n));  
   648         summable(%n. (diffs(diffs c))(n) * (K ^ n));  
   650         \<bar>x\<bar> < \<bar>K\<bar> |]  
   649         \<bar>x\<bar> < \<bar>K\<bar> |]  
   651      ==> DERIV (%x. suminf (%n. c(n) * (x ^ n)))  x :>  
   650      ==> DERIV (%x. \<Sum>n. c(n) * (x ^ n))  x :>  
   652              suminf (%n. (diffs c)(n) * (x ^ n))"
   651              (\<Sum>n. (diffs c)(n) * (x ^ n))"
   653 apply (simp add: deriv_def)
   652 apply (simp add: deriv_def)
   654 apply (rule_tac g = "%h. suminf (%n. ((c (n) * ( (x + h) ^ n)) - (c (n) * (x ^ n))) * inverse h)" in LIM_trans)
   653 apply (rule_tac g = "%h. \<Sum>n. ((c (n) * ( (x + h) ^ n)) - (c (n) * (x ^ n))) * inverse h" in LIM_trans)
   655 apply (simp add: LIM_def, safe)
   654 apply (simp add: LIM_def, safe)
   656 apply (rule_tac x = "\<bar>K\<bar> - \<bar>x\<bar>" in exI)
   655 apply (rule_tac x = "\<bar>K\<bar> - \<bar>x\<bar>" in exI)
   657 apply (auto simp add: less_diff_eq)
   656 apply (auto simp add: less_diff_eq)
   658 apply (drule abs_triangle_ineq [THEN order_le_less_trans])
   657 apply (drule abs_triangle_ineq [THEN order_le_less_trans])
   659 apply (rule_tac y = 0 in order_le_less_trans, auto)
   658 apply (rule_tac y = 0 in order_le_less_trans, auto)
   660 apply (subgoal_tac " (%n. (c n) * (x ^ n)) sums (suminf (%n. (c n) * (x ^ n))) & (%n. (c n) * ((x + xa) ^ n)) sums (suminf (%n. (c n) * ( (x + xa) ^ n))) ")
   659 apply (subgoal_tac " (%n. (c n) * (x ^ n)) sums (\<Sum>n. (c n) * (x ^ n)) & (%n. (c n) * ((x + xa) ^ n)) sums (\<Sum>n. (c n) * ( (x + xa) ^ n))")
   661 apply (auto intro!: summable_sums)
   660 apply (auto intro!: summable_sums)
   662 apply (rule_tac [2] powser_inside, rule_tac [4] powser_inside)
   661 apply (rule_tac [2] powser_inside, rule_tac [4] powser_inside)
   663 apply (auto simp add: add_commute)
   662 apply (auto simp add: add_commute)
   664 apply (drule_tac x="(\<lambda>n. c n * (xa + x) ^ n)" in sums_diff, assumption) 
   663 apply (drule_tac x="(\<lambda>n. c n * (xa + x) ^ n)" in sums_diff, assumption) 
   665 apply (drule_tac x = "(%n. c n * (xa + x) ^ n - c n * x ^ n) " and c = "inverse xa" in sums_mult)
   664 apply (drule_tac x = "(%n. c n * (xa + x) ^ n - c n * x ^ n) " and c = "inverse xa" in sums_mult)
   666 apply (rule sums_unique)
   665 apply (rule sums_unique)
   667 apply (simp add: diff_def divide_inverse add_ac mult_ac)
   666 apply (simp add: diff_def divide_inverse add_ac mult_ac)
   668 apply (rule LIM_zero_cancel)
   667 apply (rule LIM_zero_cancel)
   669 apply (rule_tac g = "%h. suminf (%n. c (n) * ((( ((x + h) ^ n) - (x ^ n)) * inverse h) - (real n * (x ^ (n - Suc 0)))))" in LIM_trans)
   668 apply (rule_tac g = "%h. \<Sum>n. c (n) * ((( ((x + h) ^ n) - (x ^ n)) * inverse h) - (real n * (x ^ (n - Suc 0))))" in LIM_trans)
   670  prefer 2 apply (blast intro: termdiffs_aux) 
   669  prefer 2 apply (blast intro: termdiffs_aux) 
   671 apply (simp add: LIM_def, safe)
   670 apply (simp add: LIM_def, safe)
   672 apply (rule_tac x = "\<bar>K\<bar> - \<bar>x\<bar>" in exI)
   671 apply (rule_tac x = "\<bar>K\<bar> - \<bar>x\<bar>" in exI)
   673 apply (auto simp add: less_diff_eq)
   672 apply (auto simp add: less_diff_eq)
   674 apply (drule abs_triangle_ineq [THEN order_le_less_trans])
   673 apply (drule abs_triangle_ineq [THEN order_le_less_trans])
   675 apply (rule_tac y = 0 in order_le_less_trans, auto)
   674 apply (rule_tac y = 0 in order_le_less_trans, auto)
   676 apply (subgoal_tac "summable (%n. (diffs c) (n) * (x ^ n))")
   675 apply (subgoal_tac "summable (%n. (diffs c) (n) * (x ^ n))")
   677 apply (rule_tac [2] powser_inside, auto)
   676 apply (rule_tac [2] powser_inside, auto)
   678 apply (drule_tac c = c and x = x in diffs_equiv)
   677 apply (drule_tac c = c and x = x in diffs_equiv)
   679 apply (frule sums_unique, auto)
   678 apply (frule sums_unique, auto)
   680 apply (subgoal_tac " (%n. (c n) * (x ^ n)) sums (suminf (%n. (c n) * (x ^ n))) & (%n. (c n) * ((x + xa) ^ n)) sums (suminf (%n. (c n) * ( (x + xa) ^ n))) ")
   679 apply (subgoal_tac " (%n. (c n) * (x ^ n)) sums (\<Sum>n. (c n) * (x ^ n)) & (%n. (c n) * ((x + xa) ^ n)) sums (\<Sum>n. (c n) * ( (x + xa) ^ n))")
   681 apply safe
   680 apply safe
   682 apply (auto intro!: summable_sums)
   681 apply (auto intro!: summable_sums)
   683 apply (rule_tac [2] powser_inside, rule_tac [4] powser_inside)
   682 apply (rule_tac [2] powser_inside, rule_tac [4] powser_inside)
   684 apply (auto simp add: add_commute)
   683 apply (auto simp add: add_commute)
   685 apply (frule_tac x = "(%n. c n * (xa + x) ^ n) " and y = "(%n. c n * x ^ n)" in sums_diff, assumption)
   684 apply (frule_tac x = "(%n. c n * (xa + x) ^ n) " and y = "(%n. c n * x ^ n)" in sums_diff, assumption)
   740          simp del: mult_Suc)
   739          simp del: mult_Suc)
   741 
   740 
   742 text{*Now at last we can get the derivatives of exp, sin and cos*}
   741 text{*Now at last we can get the derivatives of exp, sin and cos*}
   743 
   742 
   744 lemma lemma_sin_minus:
   743 lemma lemma_sin_minus:
   745      "- sin x =
   744      "- sin x = (\<Sum>n. - ((if even n then 0 
   746          suminf(%n. - ((if even n then 0 
       
   747                   else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) * x ^ n))"
   745                   else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) * x ^ n))"
   748 by (auto intro!: sums_unique sums_minus sin_converges)
   746 by (auto intro!: sums_unique sums_minus sin_converges)
   749 
   747 
   750 lemma lemma_exp_ext: "exp = (%x. suminf (%n. inverse (real (fact n)) * x ^ n))"
   748 lemma lemma_exp_ext: "exp = (%x. \<Sum>n. inverse (real (fact n)) * x ^ n)"
   751 by (auto intro!: ext simp add: exp_def)
   749 by (auto intro!: ext simp add: exp_def)
   752 
   750 
   753 lemma DERIV_exp [simp]: "DERIV exp x :> exp(x)"
   751 lemma DERIV_exp [simp]: "DERIV exp x :> exp(x)"
   754 apply (simp add: exp_def)
   752 apply (simp add: exp_def)
   755 apply (subst lemma_exp_ext)
   753 apply (subst lemma_exp_ext)
   756 apply (subgoal_tac "DERIV (%u. suminf (%n. inverse (real (fact n)) * u ^ n)) x :> suminf (%n. diffs (%n. inverse (real (fact n))) n * x ^ n) ")
   754 apply (subgoal_tac "DERIV (%u. \<Sum>n. inverse (real (fact n)) * u ^ n) x :> (\<Sum>n. diffs (%n. inverse (real (fact n))) n * x ^ n)")
   757 apply (rule_tac [2] K = "1 + \<bar>x\<bar>" in termdiffs)
   755 apply (rule_tac [2] K = "1 + \<bar>x\<bar>" in termdiffs)
   758 apply (auto intro: exp_converges [THEN sums_summable] simp add: exp_fdiffs, arith)
   756 apply (auto intro: exp_converges [THEN sums_summable] simp add: exp_fdiffs, arith)
   759 done
   757 done
   760 
   758 
   761 lemma lemma_sin_ext:
   759 lemma lemma_sin_ext:
   762      "sin = (%x. suminf(%n. 
   760      "sin = (%x. \<Sum>n. 
   763                    (if even n then 0  
   761                    (if even n then 0  
   764                        else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) *  
   762                        else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) *  
   765                    x ^ n))"
   763                    x ^ n)"
   766 by (auto intro!: ext simp add: sin_def)
   764 by (auto intro!: ext simp add: sin_def)
   767 
   765 
   768 lemma lemma_cos_ext:
   766 lemma lemma_cos_ext:
   769      "cos = (%x. suminf(%n. 
   767      "cos = (%x. \<Sum>n. 
   770                    (if even n then (- 1) ^ (n div 2)/(real (fact n)) else 0) *
   768                    (if even n then (- 1) ^ (n div 2)/(real (fact n)) else 0) *
   771                    x ^ n))"
   769                    x ^ n)"
   772 by (auto intro!: ext simp add: cos_def)
   770 by (auto intro!: ext simp add: cos_def)
   773 
   771 
   774 lemma DERIV_sin [simp]: "DERIV sin x :> cos(x)"
   772 lemma DERIV_sin [simp]: "DERIV sin x :> cos(x)"
   775 apply (simp add: cos_def)
   773 apply (simp add: cos_def)
   776 apply (subst lemma_sin_ext)
   774 apply (subst lemma_sin_ext)
   790 subsection{*Properties of the Exponential Function*}
   788 subsection{*Properties of the Exponential Function*}
   791 
   789 
   792 lemma exp_zero [simp]: "exp 0 = 1"
   790 lemma exp_zero [simp]: "exp 0 = 1"
   793 proof -
   791 proof -
   794   have "(\<Sum>n = 0..<1. inverse (real (fact n)) * 0 ^ n) =
   792   have "(\<Sum>n = 0..<1. inverse (real (fact n)) * 0 ^ n) =
   795         suminf (\<lambda>n. inverse (real (fact n)) * 0 ^ n)"
   793         (\<Sum>n. inverse (real (fact n)) * 0 ^ n)"
   796     by (rule series_zero [rule_format, THEN sums_unique],
   794     by (rule series_zero [rule_format, THEN sums_unique],
   797         case_tac "m", auto)
   795         case_tac "m", auto)
   798   thus ?thesis by (simp add:  exp_def) 
   796   thus ?thesis by (simp add:  exp_def) 
   799 qed
   797 qed
   800 
   798 
  1323   have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
  1321   have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
  1324             (if even k then 0
  1322             (if even k then 0
  1325              else (- 1) ^ ((k - Suc 0) div 2) / real (fact k)) *
  1323              else (- 1) ^ ((k - Suc 0) div 2) / real (fact k)) *
  1326             x ^ k) 
  1324             x ^ k) 
  1327 	sums
  1325 	sums
  1328 	suminf (\<lambda>n. (if even n then 0
  1326 	(\<Sum>n. (if even n then 0
  1329 		     else (- 1) ^ ((n - Suc 0) div 2) / real (fact n)) *
  1327 		     else (- 1) ^ ((n - Suc 0) div 2) / real (fact n)) *
  1330 	            x ^ n)" 
  1328 	            x ^ n)" 
  1331     by (rule sin_converges [THEN sums_summable, THEN sums_group], simp) 
  1329     by (rule sin_converges [THEN sums_summable, THEN sums_group], simp) 
  1332   thus ?thesis by (simp add: mult_ac sin_def)
  1330   thus ?thesis by (simp add: mult_ac sin_def)
  1333 qed
  1331 qed
  1334 
  1332 
  1335 lemma sin_gt_zero: "[|0 < x; x < 2 |] ==> 0 < sin x"
  1333 lemma sin_gt_zero: "[|0 < x; x < 2 |] ==> 0 < sin x"
  1336 apply (subgoal_tac 
  1334 apply (subgoal_tac 
  1337        "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
  1335        "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
  1338               (- 1) ^ k / real (fact (2 * k + 1)) * x ^ (2 * k + 1)) 
  1336               (- 1) ^ k / real (fact (2 * k + 1)) * x ^ (2 * k + 1)) 
  1339      sums suminf (\<lambda>n. (- 1) ^ n / real (fact (2 * n + 1)) * x ^ (2 * n + 1))")
  1337      sums (\<Sum>n. (- 1) ^ n / real (fact (2 * n + 1)) * x ^ (2 * n + 1))")
  1340  prefer 2
  1338  prefer 2
  1341  apply (rule sin_paired [THEN sums_summable, THEN sums_group], simp) 
  1339  apply (rule sin_paired [THEN sums_summable, THEN sums_group], simp) 
  1342 apply (rotate_tac 2)
  1340 apply (rotate_tac 2)
  1343 apply (drule sin_paired [THEN sums_unique, THEN ssubst])
  1341 apply (drule sin_paired [THEN sums_unique, THEN ssubst])
  1344 apply (auto simp del: fact_Suc realpow_Suc)
  1342 apply (auto simp del: fact_Suc realpow_Suc)
  1392 proof -
  1390 proof -
  1393   have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
  1391   have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
  1394             (if even k then (- 1) ^ (k div 2) / real (fact k) else 0) *
  1392             (if even k then (- 1) ^ (k div 2) / real (fact k) else 0) *
  1395             x ^ k) 
  1393             x ^ k) 
  1396         sums
  1394         sums
  1397 	suminf
  1395 	(\<Sum>n. (if even n then (- 1) ^ (n div 2) / real (fact n) else 0) *
  1398 	 (\<lambda>n. (if even n then (- 1) ^ (n div 2) / real (fact n) else 0) *
       
  1399 	      x ^ n)" 
  1396 	      x ^ n)" 
  1400     by (rule cos_converges [THEN sums_summable, THEN sums_group], simp) 
  1397     by (rule cos_converges [THEN sums_summable, THEN sums_group], simp) 
  1401   thus ?thesis by (simp add: mult_ac cos_def)
  1398   thus ?thesis by (simp add: mult_ac cos_def)
  1402 qed
  1399 qed
  1403 
  1400