436 |
436 |
437 |
437 |
438 subsection{*Exponential Function*} |
438 subsection{*Exponential Function*} |
439 |
439 |
440 definition |
440 definition |
441 exp :: "real => real" where |
441 exp :: "'a \<Rightarrow> 'a::{recpower,real_normed_field,banach}" where |
442 "exp x = (\<Sum>n. inverse(real (fact n)) * (x ^ n))" |
442 "exp x = (\<Sum>n. x ^ n /# real (fact n))" |
443 |
443 |
444 definition |
444 definition |
445 sin :: "real => real" where |
445 sin :: "real => real" where |
446 "sin x = (\<Sum>n. (if even(n) then 0 else |
446 "sin x = (\<Sum>n. (if even(n) then 0 else |
447 ((- 1) ^ ((n - Suc 0) div 2))/(real (fact n))) * x ^ n)" |
447 ((- 1) ^ ((n - Suc 0) div 2))/(real (fact n))) * x ^ n)" |
448 |
448 |
449 definition |
449 definition |
450 cos :: "real => real" where |
450 cos :: "real => real" where |
451 "cos x = (\<Sum>n. (if even(n) then ((- 1) ^ (n div 2))/(real (fact n)) |
451 "cos x = (\<Sum>n. (if even(n) then ((- 1) ^ (n div 2))/(real (fact n)) |
452 else 0) * x ^ n)" |
452 else 0) * x ^ n)" |
453 |
453 |
|
454 lemma summable_exp_generic: |
|
455 fixes x :: "'a::{real_normed_algebra_1,recpower,banach}" |
|
456 defines S_def: "S \<equiv> \<lambda>n. x ^ n /# real (fact n)" |
|
457 shows "summable S" |
|
458 proof - |
|
459 have S_Suc: "\<And>n. S (Suc n) = (x * S n) /# real (Suc n)" |
|
460 unfolding S_def by (simp add: power_Suc del: mult_Suc) |
|
461 obtain r :: real where r0: "0 < r" and r1: "r < 1" |
|
462 using dense [OF zero_less_one] by fast |
|
463 obtain N :: nat where N: "norm x < real N * r" |
|
464 using reals_Archimedean3 [OF r0] by fast |
|
465 from r1 show ?thesis |
|
466 proof (rule ratio_test [rule_format]) |
|
467 fix n :: nat |
|
468 assume n: "N \<le> n" |
|
469 have "norm x \<le> real N * r" |
|
470 using N by (rule order_less_imp_le) |
|
471 also have "real N * r \<le> real (Suc n) * r" |
|
472 using r0 n by (simp add: mult_right_mono) |
|
473 finally have "norm x * norm (S n) \<le> real (Suc n) * r * norm (S n)" |
|
474 using norm_ge_zero by (rule mult_right_mono) |
|
475 hence "norm (x * S n) \<le> real (Suc n) * r * norm (S n)" |
|
476 by (rule order_trans [OF norm_mult_ineq]) |
|
477 hence "norm (x * S n) / real (Suc n) \<le> r * norm (S n)" |
|
478 by (simp add: pos_divide_le_eq mult_ac) |
|
479 thus "norm (S (Suc n)) \<le> r * norm (S n)" |
|
480 by (simp add: S_Suc norm_scaleR inverse_eq_divide) |
|
481 qed |
|
482 qed |
|
483 |
|
484 lemma summable_norm_exp: |
|
485 fixes x :: "'a::{real_normed_algebra_1,recpower,banach}" |
|
486 shows "summable (\<lambda>n. norm (x ^ n /# real (fact n)))" |
|
487 proof (rule summable_norm_comparison_test [OF exI, rule_format]) |
|
488 show "summable (\<lambda>n. norm x ^ n /# real (fact n))" |
|
489 by (rule summable_exp_generic) |
|
490 next |
|
491 fix n show "norm (x ^ n /# real (fact n)) \<le> norm x ^ n /# real (fact n)" |
|
492 by (simp add: norm_scaleR norm_power_ineq) |
|
493 qed |
|
494 |
454 lemma summable_exp: "summable (%n. inverse (real (fact n)) * x ^ n)" |
495 lemma summable_exp: "summable (%n. inverse (real (fact n)) * x ^ n)" |
455 apply (cut_tac 'a = real in zero_less_one [THEN dense], safe) |
496 by (insert summable_exp_generic [where x=x], simp) |
456 apply (cut_tac x = r in reals_Archimedean3, auto) |
|
457 apply (drule_tac x = "\<bar>x\<bar>" in spec, safe) |
|
458 apply (rule_tac N = n and c = r in ratio_test) |
|
459 apply (safe, simp add: abs_mult mult_assoc [symmetric] del: fact_Suc) |
|
460 apply (rule mult_right_mono) |
|
461 apply (rule_tac b1 = "\<bar>x\<bar>" in mult_commute [THEN ssubst]) |
|
462 apply (subst fact_Suc) |
|
463 apply (subst real_of_nat_mult) |
|
464 apply (auto) |
|
465 apply (simp add: mult_assoc [symmetric] positive_imp_inverse_positive) |
|
466 apply (rule order_less_imp_le) |
|
467 apply (rule_tac z1 = "real (Suc na)" in real_mult_less_iff1 [THEN iffD1]) |
|
468 apply (auto simp add: mult_assoc) |
|
469 apply (erule order_less_trans) |
|
470 apply (auto simp add: mult_less_cancel_left mult_ac) |
|
471 done |
|
472 |
497 |
473 lemma summable_sin: |
498 lemma summable_sin: |
474 "summable (%n. |
499 "summable (%n. |
475 (if even n then 0 |
500 (if even n then 0 |
476 else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) * |
501 else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) * |
580 lemma lemma_sin_minus: |
608 lemma lemma_sin_minus: |
581 "- sin x = (\<Sum>n. - ((if even n then 0 |
609 "- sin x = (\<Sum>n. - ((if even n then 0 |
582 else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) * x ^ n))" |
610 else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) * x ^ n))" |
583 by (auto intro!: sums_unique sums_minus sin_converges) |
611 by (auto intro!: sums_unique sums_minus sin_converges) |
584 |
612 |
585 lemma lemma_exp_ext: "exp = (%x. \<Sum>n. inverse (real (fact n)) * x ^ n)" |
613 lemma lemma_exp_ext: "exp = (\<lambda>x. \<Sum>n. x ^ n /# real (fact n))" |
586 by (auto intro!: ext simp add: exp_def) |
614 by (auto intro!: ext simp add: exp_def) |
587 |
615 |
588 lemma DERIV_exp [simp]: "DERIV exp x :> exp(x)" |
616 lemma DERIV_exp [simp]: "DERIV exp x :> exp(x)" |
589 apply (simp add: exp_def) |
617 apply (simp add: exp_def) |
590 apply (subst lemma_exp_ext) |
618 apply (subst lemma_exp_ext) |
591 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)") |
619 apply (subgoal_tac "DERIV (\<lambda>u. \<Sum>n. of_real (inverse (real (fact n))) * u ^ n) x :> (\<Sum>n. diffs (\<lambda>n. of_real (inverse (real (fact n)))) n * x ^ n)") |
592 apply (rule_tac [2] K = "1 + \<bar>x\<bar>" in termdiffs) |
620 apply (rule_tac [2] K = "of_real (1 + norm x)" in termdiffs) |
593 apply (auto intro: exp_converges [THEN sums_summable] simp add: exp_fdiffs) |
621 apply (simp_all only: diffs_of_real scaleR_conv_of_real exp_fdiffs) |
|
622 apply (rule exp_converges [THEN sums_summable, unfolded scaleR_conv_of_real])+ |
|
623 apply (simp del: of_real_add) |
594 done |
624 done |
595 |
625 |
596 lemma lemma_sin_ext: |
626 lemma lemma_sin_ext: |
597 "sin = (%x. \<Sum>n. |
627 "sin = (%x. \<Sum>n. |
598 (if even n then 0 |
628 (if even n then 0 |
633 |
663 |
634 subsection{*Properties of the Exponential Function*} |
664 subsection{*Properties of the Exponential Function*} |
635 |
665 |
636 lemma exp_zero [simp]: "exp 0 = 1" |
666 lemma exp_zero [simp]: "exp 0 = 1" |
637 proof - |
667 proof - |
638 have "(\<Sum>n = 0..<1. inverse (real (fact n)) * 0 ^ n) = |
668 have "(\<Sum>n = 0..<1. (0::'a) ^ n /# real (fact n)) = |
639 (\<Sum>n. inverse (real (fact n)) * 0 ^ n)" |
669 (\<Sum>n. 0 ^ n /# real (fact n))" |
640 by (rule series_zero [rule_format, THEN sums_unique], |
670 by (rule sums_unique [OF series_zero], simp add: power_0_left) |
641 case_tac "m", auto) |
671 thus ?thesis by (simp add: exp_def) |
642 thus ?thesis by (simp add: exp_def) |
672 qed |
643 qed |
673 |
644 |
674 lemma setsum_head2: |
645 lemma exp_ge_add_one_self_aux: "0 \<le> x ==> (1 + x) \<le> exp(x)" |
675 "m \<le> n \<Longrightarrow> setsum f {m..n} = f m + setsum f {Suc m..n}" |
|
676 by (simp add: setsum_head atLeastSucAtMost_greaterThanAtMost) |
|
677 |
|
678 lemma setsum_cl_ivl_Suc2: |
|
679 "(\<Sum>i=m..Suc n. f i) = (if Suc n < m then 0 else f m + (\<Sum>i=m..n. f (Suc i)))" |
|
680 by (simp add: setsum_head2 setsum_shift_bounds_cl_Suc_ivl |
|
681 del: setsum_cl_ivl_Suc) |
|
682 |
|
683 lemma exp_series_add: |
|
684 fixes x y :: "'a::{real_field,recpower}" |
|
685 defines S_def: "S \<equiv> \<lambda>x n. x ^ n /# real (fact n)" |
|
686 shows "S (x + y) n = (\<Sum>i=0..n. S x i * S y (n - i))" |
|
687 proof (induct n) |
|
688 case 0 |
|
689 show ?case |
|
690 unfolding S_def by simp |
|
691 next |
|
692 case (Suc n) |
|
693 have S_Suc: "\<And>x n. S x (Suc n) = (x * S x n) /# real (Suc n)" |
|
694 unfolding S_def by (simp add: power_Suc del: mult_Suc) |
|
695 hence times_S: "\<And>x n. x * S x n = real (Suc n) *# S x (Suc n)" |
|
696 by simp |
|
697 |
|
698 have "real (Suc n) *# S (x + y) (Suc n) = (x + y) * S (x + y) n" |
|
699 by (simp only: times_S) |
|
700 also have "\<dots> = (x + y) * (\<Sum>i=0..n. S x i * S y (n-i))" |
|
701 by (simp only: Suc) |
|
702 also have "\<dots> = x * (\<Sum>i=0..n. S x i * S y (n-i)) |
|
703 + y * (\<Sum>i=0..n. S x i * S y (n-i))" |
|
704 by (rule left_distrib) |
|
705 also have "\<dots> = (\<Sum>i=0..n. (x * S x i) * S y (n-i)) |
|
706 + (\<Sum>i=0..n. S x i * (y * S y (n-i)))" |
|
707 by (simp only: setsum_right_distrib mult_ac) |
|
708 also have "\<dots> = (\<Sum>i=0..n. real (Suc i) *# (S x (Suc i) * S y (n-i))) |
|
709 + (\<Sum>i=0..n. real (Suc n-i) *# (S x i * S y (Suc n-i)))" |
|
710 by (simp add: times_S Suc_diff_le) |
|
711 also have "(\<Sum>i=0..n. real (Suc i) *# (S x (Suc i) * S y (n-i))) = |
|
712 (\<Sum>i=0..Suc n. real i *# (S x i * S y (Suc n-i)))" |
|
713 by (subst setsum_cl_ivl_Suc2, simp) |
|
714 also have "(\<Sum>i=0..n. real (Suc n-i) *# (S x i * S y (Suc n-i))) = |
|
715 (\<Sum>i=0..Suc n. real (Suc n-i) *# (S x i * S y (Suc n-i)))" |
|
716 by (subst setsum_cl_ivl_Suc, simp) |
|
717 also have "(\<Sum>i=0..Suc n. real i *# (S x i * S y (Suc n-i))) + |
|
718 (\<Sum>i=0..Suc n. real (Suc n-i) *# (S x i * S y (Suc n-i))) = |
|
719 (\<Sum>i=0..Suc n. real (Suc n) *# (S x i * S y (Suc n-i)))" |
|
720 by (simp only: setsum_addf [symmetric] scaleR_left_distrib [symmetric] |
|
721 real_of_nat_add [symmetric], simp) |
|
722 also have "\<dots> = real (Suc n) *# (\<Sum>i=0..Suc n. S x i * S y (Suc n-i))" |
|
723 by (simp only: additive_scaleR_right.setsum) |
|
724 finally show |
|
725 "S (x + y) (Suc n) = (\<Sum>i=0..Suc n. S x i * S y (Suc n - i))" |
|
726 by (simp add: scaleR_cancel_left del: setsum_cl_ivl_Suc) |
|
727 qed |
|
728 |
|
729 lemma exp_add: "exp (x + y) = exp x * exp y" |
|
730 unfolding exp_def |
|
731 by (simp only: Cauchy_product summable_norm_exp exp_series_add) |
|
732 |
|
733 lemma exp_ge_add_one_self_aux: "0 \<le> (x::real) ==> (1 + x) \<le> exp(x)" |
646 apply (drule order_le_imp_less_or_eq, auto) |
734 apply (drule order_le_imp_less_or_eq, auto) |
647 apply (simp add: exp_def) |
735 apply (simp add: exp_def) |
648 apply (rule real_le_trans) |
736 apply (rule real_le_trans) |
649 apply (rule_tac [2] n = 2 and f = "(%n. inverse (real (fact n)) * x ^ n)" in series_pos_le) |
737 apply (rule_tac [2] n = 2 and f = "(%n. inverse (real (fact n)) * x ^ n)" in series_pos_le) |
650 apply (auto intro: summable_exp simp add: numeral_2_eq_2 zero_le_power zero_le_mult_iff) |
738 apply (auto intro: summable_exp simp add: numeral_2_eq_2 zero_le_power zero_le_mult_iff) |
651 done |
739 done |
652 |
740 |
653 lemma exp_gt_one [simp]: "0 < x ==> 1 < exp x" |
741 lemma exp_gt_one [simp]: "0 < (x::real) ==> 1 < exp x" |
654 apply (rule order_less_le_trans) |
742 apply (rule order_less_le_trans) |
655 apply (rule_tac [2] exp_ge_add_one_self_aux, auto) |
743 apply (rule_tac [2] exp_ge_add_one_self_aux, auto) |
656 done |
744 done |
657 |
745 |
658 lemma DERIV_exp_add_const: "DERIV (%x. exp (x + y)) x :> exp(x + y)" |
746 lemma DERIV_exp_add_const: "DERIV (%x. exp (x + y)) x :> exp(x + y)" |
672 lemma DERIV_exp_exp_zero [simp]: "DERIV (%x. exp (x + y) * exp (- x)) x :> 0" |
760 lemma DERIV_exp_exp_zero [simp]: "DERIV (%x. exp (x + y) * exp (- x)) x :> 0" |
673 proof - |
761 proof - |
674 have "DERIV (\<lambda>x. exp (x + y) * exp (- x)) x |
762 have "DERIV (\<lambda>x. exp (x + y) * exp (- x)) x |
675 :> exp (x + y) * exp (- x) + - exp (- x) * exp (x + y)" |
763 :> exp (x + y) * exp (- x) + - exp (- x) * exp (x + y)" |
676 by (fast intro: DERIV_exp_add_const DERIV_exp_minus DERIV_mult) |
764 by (fast intro: DERIV_exp_add_const DERIV_exp_minus DERIV_mult) |
677 thus ?thesis by simp |
765 thus ?thesis by (simp add: mult_commute) |
678 qed |
766 qed |
679 |
767 |
680 lemma exp_add_mult_minus [simp]: "exp(x + y)*exp(-x) = exp(y)" |
768 lemma exp_add_mult_minus [simp]: "exp(x + y)*exp(-x) = exp(y::real)" |
681 proof - |
769 proof - |
682 have "\<forall>x. DERIV (%x. exp (x + y) * exp (- x)) x :> 0" by simp |
770 have "\<forall>x. DERIV (%x. exp (x + y) * exp (- x)) x :> 0" by simp |
683 hence "exp (x + y) * exp (- x) = exp (0 + y) * exp (- 0)" |
771 hence "exp (x + y) * exp (- x) = exp (0 + y) * exp (- 0)" |
684 by (rule DERIV_isconst_all) |
772 by (rule DERIV_isconst_all) |
685 thus ?thesis by simp |
773 thus ?thesis by simp |
686 qed |
774 qed |
687 |
775 |
688 lemma exp_mult_minus [simp]: "exp x * exp(-x) = 1" |
776 lemma exp_mult_minus [simp]: "exp x * exp(-x) = 1" |
689 proof - |
777 by (simp add: exp_add [symmetric]) |
690 have "exp (x + 0) * exp (- x) = exp 0" by (rule exp_add_mult_minus) |
|
691 thus ?thesis by simp |
|
692 qed |
|
693 |
778 |
694 lemma exp_mult_minus2 [simp]: "exp(-x)*exp(x) = 1" |
779 lemma exp_mult_minus2 [simp]: "exp(-x)*exp(x) = 1" |
695 by (simp add: mult_commute) |
780 by (simp add: mult_commute) |
696 |
781 |
697 |
782 |
698 lemma exp_minus: "exp(-x) = inverse(exp(x))" |
783 lemma exp_minus: "exp(-x) = inverse(exp(x))" |
699 by (auto intro: inverse_unique [symmetric]) |
784 by (auto intro: inverse_unique [symmetric]) |
700 |
785 |
701 lemma exp_add: "exp(x + y) = exp(x) * exp(y)" |
|
702 proof - |
|
703 have "exp x * exp y = exp x * (exp (x + y) * exp (- x))" by simp |
|
704 thus ?thesis by (simp (no_asm_simp) add: mult_ac) |
|
705 qed |
|
706 |
|
707 text{*Proof: because every exponential can be seen as a square.*} |
786 text{*Proof: because every exponential can be seen as a square.*} |
708 lemma exp_ge_zero [simp]: "0 \<le> exp x" |
787 lemma exp_ge_zero [simp]: "0 \<le> exp (x::real)" |
709 apply (rule_tac t = x in real_sum_of_halves [THEN subst]) |
788 apply (rule_tac t = x in real_sum_of_halves [THEN subst]) |
710 apply (subst exp_add, auto) |
789 apply (subst exp_add, auto) |
711 done |
790 done |
712 |
791 |
713 lemma exp_not_eq_zero [simp]: "exp x \<noteq> 0" |
792 lemma exp_not_eq_zero [simp]: "exp x \<noteq> 0" |
714 apply (cut_tac x = x in exp_mult_minus2) |
793 apply (cut_tac x = x in exp_mult_minus2) |
715 apply (auto simp del: exp_mult_minus2) |
794 apply (auto simp del: exp_mult_minus2) |
716 done |
795 done |
717 |
796 |
718 lemma exp_gt_zero [simp]: "0 < exp x" |
797 lemma exp_gt_zero [simp]: "0 < exp (x::real)" |
719 by (simp add: order_less_le) |
798 by (simp add: order_less_le) |
720 |
799 |
721 lemma inv_exp_gt_zero [simp]: "0 < inverse(exp x)" |
800 lemma inv_exp_gt_zero [simp]: "0 < inverse(exp x::real)" |
722 by (auto intro: positive_imp_inverse_positive) |
801 by (auto intro: positive_imp_inverse_positive) |
723 |
802 |
724 lemma abs_exp_cancel [simp]: "\<bar>exp x\<bar> = exp x" |
803 lemma abs_exp_cancel [simp]: "\<bar>exp x::real\<bar> = exp x" |
725 by auto |
804 by auto |
726 |
805 |
727 lemma exp_real_of_nat_mult: "exp(real n * x) = exp(x) ^ n" |
806 lemma exp_real_of_nat_mult: "exp(real n * x) = exp(x) ^ n" |
728 apply (induct "n") |
807 apply (induct "n") |
729 apply (auto simp add: real_of_nat_Suc right_distrib exp_add mult_commute) |
808 apply (auto simp add: real_of_nat_Suc right_distrib exp_add mult_commute) |
745 thus ?thesis |
825 thus ?thesis |
746 by (simp add: divide_inverse [symmetric] pos_less_divide_eq |
826 by (simp add: divide_inverse [symmetric] pos_less_divide_eq |
747 del: divide_self_if) |
827 del: divide_self_if) |
748 qed |
828 qed |
749 |
829 |
750 lemma exp_less_cancel: "exp x < exp y ==> x < y" |
830 lemma exp_less_cancel: "exp (x::real) < exp y ==> x < y" |
751 apply (simp add: linorder_not_le [symmetric]) |
831 apply (simp add: linorder_not_le [symmetric]) |
752 apply (auto simp add: order_le_less exp_less_mono) |
832 apply (auto simp add: order_le_less exp_less_mono) |
753 done |
833 done |
754 |
834 |
755 lemma exp_less_cancel_iff [iff]: "(exp(x) < exp(y)) = (x < y)" |
835 lemma exp_less_cancel_iff [iff]: "(exp(x::real) < exp(y)) = (x < y)" |
756 by (auto intro: exp_less_mono exp_less_cancel) |
836 by (auto intro: exp_less_mono exp_less_cancel) |
757 |
837 |
758 lemma exp_le_cancel_iff [iff]: "(exp(x) \<le> exp(y)) = (x \<le> y)" |
838 lemma exp_le_cancel_iff [iff]: "(exp(x::real) \<le> exp(y)) = (x \<le> y)" |
759 by (auto simp add: linorder_not_less [symmetric]) |
839 by (auto simp add: linorder_not_less [symmetric]) |
760 |
840 |
761 lemma exp_inj_iff [iff]: "(exp x = exp y) = (x = y)" |
841 lemma exp_inj_iff [iff]: "(exp (x::real) = exp y) = (x = y)" |
762 by (simp add: order_eq_iff) |
842 by (simp add: order_eq_iff) |
763 |
843 |
764 lemma lemma_exp_total: "1 \<le> y ==> \<exists>x. 0 \<le> x & x \<le> y - 1 & exp(x) = y" |
844 lemma lemma_exp_total: "1 \<le> y ==> \<exists>x. 0 \<le> x & x \<le> y - 1 & exp(x::real) = y" |
765 apply (rule IVT) |
845 apply (rule IVT) |
766 apply (auto intro: isCont_exp simp add: le_diff_eq) |
846 apply (auto intro: isCont_exp simp add: le_diff_eq) |
767 apply (subgoal_tac "1 + (y - 1) \<le> exp (y - 1)") |
847 apply (subgoal_tac "1 + (y - 1) \<le> exp (y - 1)") |
768 apply simp |
848 apply simp |
769 apply (rule exp_ge_add_one_self_aux, simp) |
849 apply (rule exp_ge_add_one_self_aux, simp) |
770 done |
850 done |
771 |
851 |
772 lemma exp_total: "0 < y ==> \<exists>x. exp x = y" |
852 lemma exp_total: "0 < (y::real) ==> \<exists>x. exp x = y" |
773 apply (rule_tac x = 1 and y = y in linorder_cases) |
853 apply (rule_tac x = 1 and y = y in linorder_cases) |
774 apply (drule order_less_imp_le [THEN lemma_exp_total]) |
854 apply (drule order_less_imp_le [THEN lemma_exp_total]) |
775 apply (rule_tac [2] x = 0 in exI) |
855 apply (rule_tac [2] x = 0 in exI) |
776 apply (frule_tac [3] real_inverse_gt_one) |
856 apply (frule_tac [3] real_inverse_gt_one) |
777 apply (drule_tac [4] order_less_imp_le [THEN lemma_exp_total], auto) |
857 apply (drule_tac [4] order_less_imp_le [THEN lemma_exp_total], auto) |