414 by (rule termdiffs_aux [OF 3 4]) |
414 by (rule termdiffs_aux [OF 3 4]) |
415 qed |
415 qed |
416 qed |
416 qed |
417 |
417 |
418 |
418 |
419 subsection{*Exponential Function*} |
419 subsection {* Exponential Function *} |
420 |
420 |
421 definition |
421 definition |
422 exp :: "'a \<Rightarrow> 'a::{recpower,real_normed_field,banach}" where |
422 exp :: "'a \<Rightarrow> 'a::{recpower,real_normed_field,banach}" where |
423 "exp x = (\<Sum>n. x ^ n /\<^sub>R real (fact n))" |
423 "exp x = (\<Sum>n. x ^ n /\<^sub>R real (fact n))" |
424 |
|
425 definition |
|
426 sin :: "real => real" where |
|
427 "sin x = (\<Sum>n. (if even(n) then 0 else |
|
428 (-1 ^ ((n - Suc 0) div 2))/(real (fact n))) * x ^ n)" |
|
429 |
|
430 definition |
|
431 cos :: "real => real" where |
|
432 "cos x = (\<Sum>n. (if even(n) then (-1 ^ (n div 2))/(real (fact n)) |
|
433 else 0) * x ^ n)" |
|
434 |
424 |
435 lemma summable_exp_generic: |
425 lemma summable_exp_generic: |
436 fixes x :: "'a::{real_normed_algebra_1,recpower,banach}" |
426 fixes x :: "'a::{real_normed_algebra_1,recpower,banach}" |
437 defines S_def: "S \<equiv> \<lambda>n. x ^ n /\<^sub>R real (fact n)" |
427 defines S_def: "S \<equiv> \<lambda>n. x ^ n /\<^sub>R real (fact n)" |
438 shows "summable S" |
428 shows "summable S" |
474 qed |
464 qed |
475 |
465 |
476 lemma summable_exp: "summable (%n. inverse (real (fact n)) * x ^ n)" |
466 lemma summable_exp: "summable (%n. inverse (real (fact n)) * x ^ n)" |
477 by (insert summable_exp_generic [where x=x], simp) |
467 by (insert summable_exp_generic [where x=x], simp) |
478 |
468 |
479 lemma summable_sin: |
|
480 "summable (%n. |
|
481 (if even n then 0 |
|
482 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * |
|
483 x ^ n)" |
|
484 apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test) |
|
485 apply (rule_tac [2] summable_exp) |
|
486 apply (rule_tac x = 0 in exI) |
|
487 apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff) |
|
488 done |
|
489 |
|
490 lemma summable_cos: |
|
491 "summable (%n. |
|
492 (if even n then |
|
493 -1 ^ (n div 2)/(real (fact n)) else 0) * x ^ n)" |
|
494 apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test) |
|
495 apply (rule_tac [2] summable_exp) |
|
496 apply (rule_tac x = 0 in exI) |
|
497 apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff) |
|
498 done |
|
499 |
|
500 lemma lemma_STAR_sin: |
|
501 "(if even n then 0 |
|
502 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * 0 ^ n = 0" |
|
503 by (induct "n", auto) |
|
504 |
|
505 lemma lemma_STAR_cos: |
|
506 "0 < n --> |
|
507 -1 ^ (n div 2)/(real (fact n)) * 0 ^ n = 0" |
|
508 by (induct "n", auto) |
|
509 |
|
510 lemma lemma_STAR_cos1: |
|
511 "0 < n --> |
|
512 (-1) ^ (n div 2)/(real (fact n)) * 0 ^ n = 0" |
|
513 by (induct "n", auto) |
|
514 |
|
515 lemma lemma_STAR_cos2: |
|
516 "(\<Sum>n=1..<n. if even n then -1 ^ (n div 2)/(real (fact n)) * 0 ^ n |
|
517 else 0) = 0" |
|
518 apply (induct "n") |
|
519 apply (case_tac [2] "n", auto) |
|
520 done |
|
521 |
|
522 lemma exp_converges: "(\<lambda>n. x ^ n /\<^sub>R real (fact n)) sums exp x" |
469 lemma exp_converges: "(\<lambda>n. x ^ n /\<^sub>R real (fact n)) sums exp x" |
523 unfolding exp_def by (rule summable_exp_generic [THEN summable_sums]) |
470 unfolding exp_def by (rule summable_exp_generic [THEN summable_sums]) |
524 |
471 |
525 lemma sin_converges: |
472 |
526 "(%n. (if even n then 0 |
473 subsection {* Formal Derivatives of Exp, Sin, and Cos Series *} |
527 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * |
|
528 x ^ n) sums sin(x)" |
|
529 unfolding sin_def by (rule summable_sin [THEN summable_sums]) |
|
530 |
|
531 lemma cos_converges: |
|
532 "(%n. (if even n then |
|
533 -1 ^ (n div 2)/(real (fact n)) |
|
534 else 0) * x ^ n) sums cos(x)" |
|
535 unfolding cos_def by (rule summable_cos [THEN summable_sums]) |
|
536 |
|
537 |
|
538 subsection{*Formal Derivatives of Exp, Sin, and Cos Series*} |
|
539 |
474 |
540 lemma exp_fdiffs: |
475 lemma exp_fdiffs: |
541 "diffs (%n. inverse(real (fact n))) = (%n. inverse(real (fact n)))" |
476 "diffs (%n. inverse(real (fact n))) = (%n. inverse(real (fact n)))" |
542 by (simp add: diffs_def mult_assoc [symmetric] real_of_nat_def of_nat_mult |
477 by (simp add: diffs_def mult_assoc [symmetric] real_of_nat_def of_nat_mult |
543 del: mult_Suc of_nat_Suc) |
478 del: mult_Suc of_nat_Suc) |
544 |
479 |
545 lemma diffs_of_real: "diffs (\<lambda>n. of_real (f n)) = (\<lambda>n. of_real (diffs f n))" |
480 lemma diffs_of_real: "diffs (\<lambda>n. of_real (f n)) = (\<lambda>n. of_real (diffs f n))" |
546 by (simp add: diffs_def) |
481 by (simp add: diffs_def) |
547 |
|
548 lemma sin_fdiffs: |
|
549 "diffs(%n. if even n then 0 |
|
550 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) |
|
551 = (%n. if even n then |
|
552 -1 ^ (n div 2)/(real (fact n)) |
|
553 else 0)" |
|
554 by (auto intro!: ext |
|
555 simp add: diffs_def divide_inverse real_of_nat_def of_nat_mult |
|
556 simp del: mult_Suc of_nat_Suc) |
|
557 |
|
558 lemma sin_fdiffs2: |
|
559 "diffs(%n. if even n then 0 |
|
560 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) n |
|
561 = (if even n then |
|
562 -1 ^ (n div 2)/(real (fact n)) |
|
563 else 0)" |
|
564 by (simp only: sin_fdiffs) |
|
565 |
|
566 lemma cos_fdiffs: |
|
567 "diffs(%n. if even n then |
|
568 -1 ^ (n div 2)/(real (fact n)) else 0) |
|
569 = (%n. - (if even n then 0 |
|
570 else -1 ^ ((n - Suc 0)div 2)/(real (fact n))))" |
|
571 by (auto intro!: ext |
|
572 simp add: diffs_def divide_inverse odd_Suc_mult_two_ex real_of_nat_def of_nat_mult |
|
573 simp del: mult_Suc of_nat_Suc) |
|
574 |
|
575 |
|
576 lemma cos_fdiffs2: |
|
577 "diffs(%n. if even n then |
|
578 -1 ^ (n div 2)/(real (fact n)) else 0) n |
|
579 = - (if even n then 0 |
|
580 else -1 ^ ((n - Suc 0)div 2)/(real (fact n)))" |
|
581 by (simp only: cos_fdiffs) |
|
582 |
|
583 text{*Now at last we can get the derivatives of exp, sin and cos*} |
|
584 |
|
585 lemma lemma_sin_minus: |
|
586 "- sin x = (\<Sum>n. - ((if even n then 0 |
|
587 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * x ^ n))" |
|
588 by (auto intro!: sums_unique sums_minus sin_converges) |
|
589 |
482 |
590 lemma lemma_exp_ext: "exp = (\<lambda>x. \<Sum>n. x ^ n /\<^sub>R real (fact n))" |
483 lemma lemma_exp_ext: "exp = (\<lambda>x. \<Sum>n. x ^ n /\<^sub>R real (fact n))" |
591 by (auto intro!: ext simp add: exp_def) |
484 by (auto intro!: ext simp add: exp_def) |
592 |
485 |
593 lemma DERIV_exp [simp]: "DERIV exp x :> exp(x)" |
486 lemma DERIV_exp [simp]: "DERIV exp x :> exp(x)" |
598 apply (simp_all only: diffs_of_real scaleR_conv_of_real exp_fdiffs) |
491 apply (simp_all only: diffs_of_real scaleR_conv_of_real exp_fdiffs) |
599 apply (rule exp_converges [THEN sums_summable, unfolded scaleR_conv_of_real])+ |
492 apply (rule exp_converges [THEN sums_summable, unfolded scaleR_conv_of_real])+ |
600 apply (simp del: of_real_add) |
493 apply (simp del: of_real_add) |
601 done |
494 done |
602 |
495 |
603 lemma lemma_sin_ext: |
|
604 "sin = (%x. \<Sum>n. |
|
605 (if even n then 0 |
|
606 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * |
|
607 x ^ n)" |
|
608 by (auto intro!: ext simp add: sin_def) |
|
609 |
|
610 lemma lemma_cos_ext: |
|
611 "cos = (%x. \<Sum>n. |
|
612 (if even n then -1 ^ (n div 2)/(real (fact n)) else 0) * |
|
613 x ^ n)" |
|
614 by (auto intro!: ext simp add: cos_def) |
|
615 |
|
616 lemma DERIV_sin [simp]: "DERIV sin x :> cos(x)" |
|
617 apply (simp add: cos_def) |
|
618 apply (subst lemma_sin_ext) |
|
619 apply (auto simp add: sin_fdiffs2 [symmetric]) |
|
620 apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs) |
|
621 apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs) |
|
622 done |
|
623 |
|
624 lemma DERIV_cos [simp]: "DERIV cos x :> -sin(x)" |
|
625 apply (subst lemma_cos_ext) |
|
626 apply (auto simp add: lemma_sin_minus cos_fdiffs2 [symmetric] minus_mult_left) |
|
627 apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs) |
|
628 apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs diffs_minus) |
|
629 done |
|
630 |
|
631 lemma isCont_exp [simp]: "isCont exp x" |
496 lemma isCont_exp [simp]: "isCont exp x" |
632 by (rule DERIV_exp [THEN DERIV_isCont]) |
497 by (rule DERIV_exp [THEN DERIV_isCont]) |
633 |
498 |
634 lemma isCont_sin [simp]: "isCont sin x" |
499 |
635 by (rule DERIV_sin [THEN DERIV_isCont]) |
500 subsection {* Properties of the Exponential Function *} |
636 |
|
637 lemma isCont_cos [simp]: "isCont cos x" |
|
638 by (rule DERIV_cos [THEN DERIV_isCont]) |
|
639 |
|
640 |
|
641 subsection{*Properties of the Exponential Function*} |
|
642 |
501 |
643 lemma powser_zero: |
502 lemma powser_zero: |
644 fixes f :: "nat \<Rightarrow> 'a::{real_normed_algebra_1,recpower}" |
503 fixes f :: "nat \<Rightarrow> 'a::{real_normed_algebra_1,recpower}" |
645 shows "(\<Sum>n. f n * 0 ^ n) = f 0" |
504 shows "(\<Sum>n. f n * 0 ^ n) = f 0" |
646 proof - |
505 proof - |
973 apply (erule lemma_DERIV_subst [OF DERIV_exp exp_ln]) |
832 apply (erule lemma_DERIV_subst [OF DERIV_exp exp_ln]) |
974 apply (simp_all add: abs_if isCont_ln) |
833 apply (simp_all add: abs_if isCont_ln) |
975 done |
834 done |
976 |
835 |
977 |
836 |
978 subsection{*Basic Properties of the Trigonometric Functions*} |
837 subsection {* Sine and Cosine *} |
|
838 |
|
839 definition |
|
840 sin :: "real => real" where |
|
841 "sin x = (\<Sum>n. (if even(n) then 0 else |
|
842 (-1 ^ ((n - Suc 0) div 2))/(real (fact n))) * x ^ n)" |
|
843 |
|
844 definition |
|
845 cos :: "real => real" where |
|
846 "cos x = (\<Sum>n. (if even(n) then (-1 ^ (n div 2))/(real (fact n)) |
|
847 else 0) * x ^ n)" |
|
848 |
|
849 lemma summable_sin: |
|
850 "summable (%n. |
|
851 (if even n then 0 |
|
852 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * |
|
853 x ^ n)" |
|
854 apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test) |
|
855 apply (rule_tac [2] summable_exp) |
|
856 apply (rule_tac x = 0 in exI) |
|
857 apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff) |
|
858 done |
|
859 |
|
860 lemma summable_cos: |
|
861 "summable (%n. |
|
862 (if even n then |
|
863 -1 ^ (n div 2)/(real (fact n)) else 0) * x ^ n)" |
|
864 apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test) |
|
865 apply (rule_tac [2] summable_exp) |
|
866 apply (rule_tac x = 0 in exI) |
|
867 apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff) |
|
868 done |
|
869 |
|
870 lemma lemma_STAR_sin: |
|
871 "(if even n then 0 |
|
872 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * 0 ^ n = 0" |
|
873 by (induct "n", auto) |
|
874 |
|
875 lemma lemma_STAR_cos: |
|
876 "0 < n --> |
|
877 -1 ^ (n div 2)/(real (fact n)) * 0 ^ n = 0" |
|
878 by (induct "n", auto) |
|
879 |
|
880 lemma lemma_STAR_cos1: |
|
881 "0 < n --> |
|
882 (-1) ^ (n div 2)/(real (fact n)) * 0 ^ n = 0" |
|
883 by (induct "n", auto) |
|
884 |
|
885 lemma lemma_STAR_cos2: |
|
886 "(\<Sum>n=1..<n. if even n then -1 ^ (n div 2)/(real (fact n)) * 0 ^ n |
|
887 else 0) = 0" |
|
888 apply (induct "n") |
|
889 apply (case_tac [2] "n", auto) |
|
890 done |
|
891 |
|
892 lemma sin_converges: |
|
893 "(%n. (if even n then 0 |
|
894 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * |
|
895 x ^ n) sums sin(x)" |
|
896 unfolding sin_def by (rule summable_sin [THEN summable_sums]) |
|
897 |
|
898 lemma cos_converges: |
|
899 "(%n. (if even n then |
|
900 -1 ^ (n div 2)/(real (fact n)) |
|
901 else 0) * x ^ n) sums cos(x)" |
|
902 unfolding cos_def by (rule summable_cos [THEN summable_sums]) |
|
903 |
|
904 lemma sin_fdiffs: |
|
905 "diffs(%n. if even n then 0 |
|
906 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) |
|
907 = (%n. if even n then |
|
908 -1 ^ (n div 2)/(real (fact n)) |
|
909 else 0)" |
|
910 by (auto intro!: ext |
|
911 simp add: diffs_def divide_inverse real_of_nat_def of_nat_mult |
|
912 simp del: mult_Suc of_nat_Suc) |
|
913 |
|
914 lemma sin_fdiffs2: |
|
915 "diffs(%n. if even n then 0 |
|
916 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) n |
|
917 = (if even n then |
|
918 -1 ^ (n div 2)/(real (fact n)) |
|
919 else 0)" |
|
920 by (simp only: sin_fdiffs) |
|
921 |
|
922 lemma cos_fdiffs: |
|
923 "diffs(%n. if even n then |
|
924 -1 ^ (n div 2)/(real (fact n)) else 0) |
|
925 = (%n. - (if even n then 0 |
|
926 else -1 ^ ((n - Suc 0)div 2)/(real (fact n))))" |
|
927 by (auto intro!: ext |
|
928 simp add: diffs_def divide_inverse odd_Suc_mult_two_ex real_of_nat_def of_nat_mult |
|
929 simp del: mult_Suc of_nat_Suc) |
|
930 |
|
931 |
|
932 lemma cos_fdiffs2: |
|
933 "diffs(%n. if even n then |
|
934 -1 ^ (n div 2)/(real (fact n)) else 0) n |
|
935 = - (if even n then 0 |
|
936 else -1 ^ ((n - Suc 0)div 2)/(real (fact n)))" |
|
937 by (simp only: cos_fdiffs) |
|
938 |
|
939 text{*Now at last we can get the derivatives of exp, sin and cos*} |
|
940 |
|
941 lemma lemma_sin_minus: |
|
942 "- sin x = (\<Sum>n. - ((if even n then 0 |
|
943 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * x ^ n))" |
|
944 by (auto intro!: sums_unique sums_minus sin_converges) |
|
945 |
|
946 lemma lemma_sin_ext: |
|
947 "sin = (%x. \<Sum>n. |
|
948 (if even n then 0 |
|
949 else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * |
|
950 x ^ n)" |
|
951 by (auto intro!: ext simp add: sin_def) |
|
952 |
|
953 lemma lemma_cos_ext: |
|
954 "cos = (%x. \<Sum>n. |
|
955 (if even n then -1 ^ (n div 2)/(real (fact n)) else 0) * |
|
956 x ^ n)" |
|
957 by (auto intro!: ext simp add: cos_def) |
|
958 |
|
959 lemma DERIV_sin [simp]: "DERIV sin x :> cos(x)" |
|
960 apply (simp add: cos_def) |
|
961 apply (subst lemma_sin_ext) |
|
962 apply (auto simp add: sin_fdiffs2 [symmetric]) |
|
963 apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs) |
|
964 apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs) |
|
965 done |
|
966 |
|
967 lemma DERIV_cos [simp]: "DERIV cos x :> -sin(x)" |
|
968 apply (subst lemma_cos_ext) |
|
969 apply (auto simp add: lemma_sin_minus cos_fdiffs2 [symmetric] minus_mult_left) |
|
970 apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs) |
|
971 apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs diffs_minus) |
|
972 done |
|
973 |
|
974 lemma isCont_sin [simp]: "isCont sin x" |
|
975 by (rule DERIV_sin [THEN DERIV_isCont]) |
|
976 |
|
977 lemma isCont_cos [simp]: "isCont cos x" |
|
978 by (rule DERIV_cos [THEN DERIV_isCont]) |
|
979 |
|
980 |
|
981 subsection {* Properties of Sine and Cosine *} |
979 |
982 |
980 lemma sin_zero [simp]: "sin 0 = 0" |
983 lemma sin_zero [simp]: "sin 0 = 0" |
981 unfolding sin_def by (simp add: powser_zero) |
984 unfolding sin_def by (simp add: powser_zero) |
982 |
985 |
983 lemma cos_zero [simp]: "cos 0 = 1" |
986 lemma cos_zero [simp]: "cos 0 = 1" |