(************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* R] : nat->R := [i:nat]``(pow (-1) i)*(Un i)``. Definition positivity_seq [Un:nat->R] : Prop := (n:nat)``0<=(Un n)``. Lemma CV_ALT_step0 : (Un:nat->R) (Un_decreasing Un) -> (Un_growing [N:nat](sum_f_R0 (tg_alt Un) (S (mult (2) N)))). Intros; Unfold Un_growing; Intro. Cut (mult (S (S O)) (S n)) = (S (S (mult (2) n))). Intro; Rewrite H0. Do 4 Rewrite tech5; Repeat Rewrite Rplus_assoc; Apply Rle_compatibility. Pattern 1 (tg_alt Un (S (mult (S (S O)) n))); Rewrite <- Rplus_Or. Apply Rle_compatibility. Unfold tg_alt; Rewrite <- H0; Rewrite pow_1_odd; Rewrite pow_1_even; Rewrite Rmult_1l. Apply Rle_anti_compatibility with ``(Un (S (mult (S (S O)) (S n))))``. Rewrite Rplus_Or; Replace ``(Un (S (mult (S (S O)) (S n))))+((Un (mult (S (S O)) (S n)))+ -1*(Un (S (mult (S (S O)) (S n)))))`` with ``(Un (mult (S (S O)) (S n)))``; [Idtac | Ring]. Apply H. Cut (n:nat) (S n)=(plus n (1)); [Intro | Intro; Ring]. Rewrite (H0 n); Rewrite (H0 (S (mult (2) n))); Rewrite (H0 (mult (2) n)); Ring. Qed. Lemma CV_ALT_step1 : (Un:nat->R) (Un_decreasing Un) -> (Un_decreasing [N:nat](sum_f_R0 (tg_alt Un) (mult (2) N))). Intros; Unfold Un_decreasing; Intro. Cut (mult (S (S O)) (S n)) = (S (S (mult (2) n))). Intro; Rewrite H0; Do 2 Rewrite tech5; Repeat Rewrite Rplus_assoc. Pattern 2 (sum_f_R0 (tg_alt Un) (mult (S (S O)) n)); Rewrite <- Rplus_Or. Apply Rle_compatibility. Unfold tg_alt; Rewrite <- H0; Rewrite pow_1_odd; Rewrite pow_1_even; Rewrite Rmult_1l. Apply Rle_anti_compatibility with ``(Un (S (mult (S (S O)) n)))``. Rewrite Rplus_Or; Replace ``(Un (S (mult (S (S O)) n)))+( -1*(Un (S (mult (S (S O)) n)))+(Un (mult (S (S O)) (S n))))`` with ``(Un (mult (S (S O)) (S n)))``; [Idtac | Ring]. Rewrite H0; Apply H. Cut (n:nat) (S n)=(plus n (1)); [Intro | Intro; Ring]. Rewrite (H0 n); Rewrite (H0 (S (mult (2) n))); Rewrite (H0 (mult (2) n)); Ring. Qed. (**********) Lemma CV_ALT_step2 : (Un:nat->R;N:nat) (Un_decreasing Un) -> (positivity_seq Un) -> (Rle (sum_f_R0 [i:nat](tg_alt Un (S i)) (S (mult (2) N))) R0). Intros; Induction N. Simpl; Unfold tg_alt; Simpl; Rewrite Rmult_1r. Replace ``-1* -1*(Un (S (S O)))`` with (Un (S (S O))); [Idtac | Ring]. Apply Rle_anti_compatibility with ``(Un (S O))``; Rewrite Rplus_Or. Replace ``(Un (S O))+ (-1*(Un (S O))+(Un (S (S O))))`` with (Un (S (S O))); [Apply H | Ring]. Cut (S (mult (2) (S N))) = (S (S (S (mult (2) N)))). Intro; Rewrite H1; Do 2 Rewrite tech5. Apply Rle_trans with (sum_f_R0 [i:nat](tg_alt Un (S i)) (S (mult (S (S O)) N))). Pattern 2 (sum_f_R0 [i:nat](tg_alt Un (S i)) (S (mult (S (S O)) N))); Rewrite <- Rplus_Or. Rewrite Rplus_assoc; Apply Rle_compatibility. Unfold tg_alt; Rewrite <- H1. Rewrite pow_1_odd. Cut (S (S (mult (2) (S N)))) = (mult (2) (S (S N))). Intro; Rewrite H2; Rewrite pow_1_even; Rewrite Rmult_1l; Rewrite <- H2. Apply Rle_anti_compatibility with ``(Un (S (mult (S (S O)) (S N))))``. Rewrite Rplus_Or; Replace ``(Un (S (mult (S (S O)) (S N))))+( -1*(Un (S (mult (S (S O)) (S N))))+(Un (S (S (mult (S (S O)) (S N))))))`` with ``(Un (S (S (mult (S (S O)) (S N)))))``; [Idtac | Ring]. Apply H. Apply INR_eq; Rewrite mult_INR; Repeat Rewrite S_INR; Rewrite mult_INR; Repeat Rewrite S_INR; Ring. Apply HrecN. Apply INR_eq; Repeat Rewrite S_INR; Do 2 Rewrite mult_INR; Repeat Rewrite S_INR; Ring. Qed. (* A more general inequality *) Lemma CV_ALT_step3 : (Un:nat->R;N:nat) (Un_decreasing Un) -> (positivity_seq Un) -> (Rle (sum_f_R0 [i:nat](tg_alt Un (S i)) N) R0). Intros; Induction N. Simpl; Unfold tg_alt; Simpl; Rewrite Rmult_1r. Apply Rle_anti_compatibility with (Un (S O)). Rewrite Rplus_Or; Replace ``(Un (S O))+ -1*(Un (S O))`` with R0; [Apply H0 | Ring]. Assert H1 := (even_odd_cor N). Elim H1; Intros. Elim H2; Intro. Rewrite H3; Apply CV_ALT_step2; Assumption. Rewrite H3; Rewrite tech5. Apply Rle_trans with (sum_f_R0 [i:nat](tg_alt Un (S i)) (S (mult (S (S O)) x))). Pattern 2 (sum_f_R0 [i:nat](tg_alt Un (S i)) (S (mult (S (S O)) x))); Rewrite <- Rplus_Or. Apply Rle_compatibility. Unfold tg_alt; Simpl. Replace (plus x (plus x O)) with (mult (2) x); [Idtac | Ring]. Rewrite pow_1_even. Replace `` -1*( -1*( -1*1))*(Un (S (S (S (mult (S (S O)) x)))))`` with ``-(Un (S (S (S (mult (S (S O)) x)))))``; [Idtac | Ring]. Apply Rle_anti_compatibility with (Un (S (S (S (mult (S (S O)) x))))). Rewrite Rplus_Or; Rewrite Rplus_Ropp_r. Apply H0. Apply CV_ALT_step2; Assumption. Qed. (**********) Lemma CV_ALT_step4 : (Un:nat->R) (Un_decreasing Un) -> (positivity_seq Un) -> (has_ub [N:nat](sum_f_R0 (tg_alt Un) (S (mult (2) N)))). Intros; Unfold has_ub; Unfold bound. Exists ``(Un O)``. Unfold is_upper_bound; Intros; Elim H1; Intros. Rewrite H2; Rewrite decomp_sum. Replace (tg_alt Un O) with ``(Un O)``. Pattern 2 ``(Un O)``; Rewrite <- Rplus_Or. Apply Rle_compatibility. Apply CV_ALT_step3; Assumption. Unfold tg_alt; Simpl; Ring. Apply lt_O_Sn. Qed. (* This lemma gives an interesting result about alternated series *) Lemma CV_ALT : (Un:nat->R) (Un_decreasing Un) -> (positivity_seq Un) -> (Un_cv Un R0) -> (sigTT R [l:R](Un_cv [N:nat](sum_f_R0 (tg_alt Un) N) l)). Intros. Assert H2 := (CV_ALT_step0 ? H). Assert H3 := (CV_ALT_step4 ? H H0). Assert X := (growing_cv ? H2 H3). Elim X; Intros. Apply existTT with x. Unfold Un_cv; Unfold R_dist; Unfold Un_cv in H1; Unfold R_dist in H1; Unfold Un_cv in p; Unfold R_dist in p. Intros; Cut ``0R) (Un_decreasing Un) -> (Un_cv Un R0) -> (sigTT R [l:R](Un_cv [N:nat](sum_f_R0 (tg_alt Un) N) l)). Intros; Apply CV_ALT. Assumption. Unfold positivity_seq; Apply decreasing_ineq; Assumption. Assumption. Qed. Theorem alternated_series_ineq : (Un:nat->R;l:R;N:nat) (Un_decreasing Un) -> (Un_cv Un R0) -> (Un_cv [N:nat](sum_f_R0 (tg_alt Un) N) l) -> ``(sum_f_R0 (tg_alt Un) (S (mult (S (S O)) N)))<=l<=(sum_f_R0 (tg_alt Un) (mult (S (S O)) N))``. Intros. Cut (Un_cv [N:nat](sum_f_R0 (tg_alt Un) (mult (2) N)) l). Cut (Un_cv [N:nat](sum_f_R0 (tg_alt Un) (S (mult (2) N))) l). Intros; Split. Apply (growing_ineq [N:nat](sum_f_R0 (tg_alt Un) (S (mult (2) N)))). Apply CV_ALT_step0; Assumption. Assumption. Apply (decreasing_ineq [N:nat](sum_f_R0 (tg_alt Un) (mult (2) N))). Apply CV_ALT_step1; Assumption. Assumption. Unfold Un_cv; Unfold R_dist; Unfold Un_cv in H1; Unfold R_dist in H1; Intros. Elim (H1 eps H2); Intros. Exists x; Intros. Apply H3. Unfold ge; Apply le_trans with (mult (2) n). Apply le_trans with n. Assumption. Assert H5 := (mult_O_le n (2)). Elim H5; Intro. Cut ~(O)=(2); [Intro; Elim H7; Symmetry; Assumption | Discriminate]. Assumption. Apply le_n_Sn. Unfold Un_cv; Unfold R_dist; Unfold Un_cv in H1; Unfold R_dist in H1; Intros. Elim (H1 eps H2); Intros. Exists x; Intros. Apply H3. Unfold ge; Apply le_trans with n. Assumption. Assert H5 := (mult_O_le n (2)). Elim H5; Intro. Cut ~(O)=(2); [Intro; Elim H7; Symmetry; Assumption | Discriminate]. Assumption. Qed. (************************************) (* Application : construction of PI *) (************************************) Definition PI_tg := [n:nat]``/(INR (plus (mult (S (S O)) n) (S O)))``. Lemma PI_tg_pos : (n:nat)``0<=(PI_tg n)``. Intro; Unfold PI_tg; Left; Apply Rlt_Rinv; Apply lt_INR_0; Replace (plus (mult (2) n) (1)) with (S (mult (2) n)); [Apply lt_O_Sn | Ring]. Qed. Lemma PI_tg_decreasing : (Un_decreasing PI_tg). Unfold PI_tg Un_decreasing; Intro. Apply Rle_monotony_contra with ``(INR (plus (mult (S (S O)) n) (S O)))``. Apply lt_INR_0. Replace (plus (mult (2) n) (1)) with (S (mult (2) n)); [Apply lt_O_Sn | Ring]. Rewrite <- Rinv_r_sym. Apply Rle_monotony_contra with ``(INR (plus (mult (S (S O)) (S n)) (S O)))``. Apply lt_INR_0. Replace (plus (mult (2) (S n)) (1)) with (S (mult (2) (S n))); [Apply lt_O_Sn | Ring]. Rewrite (Rmult_sym ``(INR (plus (mult (S (S O)) (S n)) (S O)))``); Rewrite Rmult_assoc; Rewrite <- Rinv_l_sym. Do 2 Rewrite Rmult_1r; Apply le_INR. Replace (plus (mult (2) (S n)) (1)) with (S (S (plus (mult (2) n) (1)))). Apply le_trans with (S (plus (mult (2) n) (1))); Apply le_n_Sn. Apply INR_eq; Do 2 Rewrite S_INR; Do 2 Rewrite plus_INR; Do 2 Rewrite mult_INR; Repeat Rewrite S_INR; Ring. Apply not_O_INR; Discriminate. Apply not_O_INR; Replace (plus (mult (2) n) (1)) with (S (mult (2) n)); [Discriminate | Ring]. Qed. Lemma PI_tg_cv : (Un_cv PI_tg R0). Unfold Un_cv; Unfold R_dist; Intros. Cut ``0<2*eps``; [Intro | Apply Rmult_lt_pos; [Sup0 | Assumption]]. Assert H1 := (archimed ``/(2*eps)``). Cut (Zle `0` ``(up (/(2*eps)))``). Intro; Assert H3 := (IZN ``(up (/(2*eps)))`` H2). Elim H3; Intros N H4. Cut (lt O N). Intro; Exists N; Intros. Cut (lt O n). Intro; Unfold Rminus; Rewrite Ropp_O; Rewrite Rplus_Or; Rewrite Rabsolu_right. Unfold PI_tg; Apply Rlt_trans with ``/(INR (mult (S (S O)) n))``. Apply Rlt_monotony_contra with ``(INR (mult (S (S O)) n))``. Apply lt_INR_0. Replace (mult (2) n) with (plus n n); [Idtac | Ring]. Apply lt_le_trans with n. Assumption. Apply le_plus_l. Rewrite <- Rinv_r_sym. Apply Rlt_monotony_contra with ``(INR (plus (mult (S (S O)) n) (S O)))``. Apply lt_INR_0. Replace (plus (mult (2) n) (1)) with (S (mult (2) n)); [Apply lt_O_Sn | Ring]. Rewrite (Rmult_sym ``(INR (plus (mult (S (S O)) n) (S O)))``). Rewrite Rmult_assoc; Rewrite <- Rinv_l_sym. Do 2 Rewrite Rmult_1r; Apply lt_INR. Replace (plus (mult (2) n) (1)) with (S (mult (2) n)); [Apply lt_n_Sn | Ring]. Apply not_O_INR; Replace (plus (mult (2) n) (1)) with (S (mult (2) n)); [Discriminate | Ring]. Replace n with (S (pred n)). Apply not_O_INR; Discriminate. Symmetry; Apply S_pred with O. Assumption. Apply Rle_lt_trans with ``/(INR (mult (S (S O)) N))``. Apply Rle_monotony_contra with ``(INR (mult (S (S O)) N))``. Rewrite mult_INR; Apply Rmult_lt_pos; [Simpl; Sup0 | Apply lt_INR_0; Assumption]. Rewrite <- Rinv_r_sym. Apply Rle_monotony_contra with ``(INR (mult (S (S O)) n))``. Rewrite mult_INR; Apply Rmult_lt_pos; [Simpl; Sup0 | Apply lt_INR_0; Assumption]. Rewrite (Rmult_sym (INR (mult (S (S O)) n))); Rewrite Rmult_assoc; Rewrite <- Rinv_l_sym. Do 2 Rewrite Rmult_1r; Apply le_INR. Apply mult_le; Assumption. Replace n with (S (pred n)). Apply not_O_INR; Discriminate. Symmetry; Apply S_pred with O. Assumption. Replace N with (S (pred N)). Apply not_O_INR; Discriminate. Symmetry; Apply S_pred with O. Assumption. Rewrite mult_INR. Rewrite Rinv_Rmult. Replace (INR (S (S O))) with ``2``; [Idtac | Reflexivity]. Apply Rlt_monotony_contra with ``2``. Sup0. Rewrite <- Rmult_assoc; Rewrite <- Rinv_r_sym; [Idtac | DiscrR]. Rewrite Rmult_1l; Apply Rlt_monotony_contra with (INR N). Apply lt_INR_0; Assumption. Rewrite <- Rinv_r_sym. Apply Rlt_monotony_contra with ``/(2*eps)``. Apply Rlt_Rinv; Assumption. Rewrite Rmult_1r; Replace ``/(2*eps)*((INR N)*(2*eps))`` with ``(INR N)*((2*eps)*/(2*eps))``; [Idtac | Ring]. Rewrite <- Rinv_r_sym. Rewrite Rmult_1r; Replace (INR N) with (IZR (INZ N)). Rewrite <- H4. Elim H1; Intros; Assumption. Symmetry; Apply INR_IZR_INZ. Apply prod_neq_R0; [DiscrR | Red; Intro; Rewrite H8 in H; Elim (Rlt_antirefl ? H)]. Apply not_O_INR. Red; Intro; Rewrite H8 in H5; Elim (lt_n_n ? H5). Replace (INR (S (S O))) with ``2``; [DiscrR | Reflexivity]. Apply not_O_INR. Red; Intro; Rewrite H8 in H5; Elim (lt_n_n ? H5). Apply Rle_sym1; Apply PI_tg_pos. Apply lt_le_trans with N; Assumption. Elim H1; Intros H5 _. Assert H6 := (lt_eq_lt_dec O N). Elim H6; Intro. Elim a; Intro. Assumption. Rewrite <- b in H4. Rewrite H4 in H5. Simpl in H5. Cut ``0 a end)). (* We can get an approximation of PI with the following inequality *) Lemma PI_ineq : (N:nat) ``(sum_f_R0 (tg_alt PI_tg) (S (mult (S (S O)) N)))<=PI/4<=(sum_f_R0 (tg_alt PI_tg) (mult (S (S O)) N))``. Intro; Apply alternated_series_ineq. Apply PI_tg_decreasing. Apply PI_tg_cv. Unfold PI; Case exist_PI; Intro. Replace ``(4*x)/4`` with x. Trivial. Unfold Rdiv; Rewrite (Rmult_sym ``4``); Rewrite Rmult_assoc; Rewrite <- Rinv_r_sym; [Rewrite Rmult_1r; Reflexivity | DiscrR]. Qed. Lemma PI_RGT_0 : ``0