From: Andrea Asperti Date: Mon, 6 Dec 2010 10:45:07 +0000 (+0000) Subject: exp and factorial X-Git-Tag: make_still_working~2661 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=ba7ab956f87c7d483df0dc622f256c6c9d475c7d;p=helm.git exp and factorial --- diff --git a/matita/matita/lib/arithmetics/exp.ma b/matita/matita/lib/arithmetics/exp.ma new file mode 100644 index 000000000..1c7adf69b --- /dev/null +++ b/matita/matita/lib/arithmetics/exp.ma @@ -0,0 +1,140 @@ +(* + ||M|| This file is part of HELM, an Hypertextual, Electronic + ||A|| Library of Mathematics, developed at the Computer Science + ||T|| Department of the University of Bologna, Italy. + ||I|| + ||T|| + ||A|| This file is distributed under the terms of the + \ / GNU General Public License Version 2 + \ / + V_______________________________________________________________ *) + +include "arithmetics/div_and_mod.ma". + +let rec exp n m on m ≝ + match m with + [ O ⇒ 1 + | S p ⇒ (exp n p) * n]. + +interpretation "natural exponent" 'exp a b = (exp a b). + +theorem exp_plus_times : ∀n,p,q:nat. + n^(p + q) = n^p * n^q. +#n #p #q elim p normalize // +qed. + +theorem exp_n_O : ∀n:nat. 1 = n^O. +// +qed. + +theorem exp_n_1 : ∀n:nat. n = n^1. +#n normalize // +qed. + +theorem exp_1_n : ∀n:nat. 1 = 1^n. +#n (elim n) normalize // +qed. + +theorem exp_2: ∀n. n^2 = n*n. +#n normalize // +qed. + +theorem exp_exp_times : ∀n,p,q:nat. + (n^p)^q = n^(p * q). +#n #p #q (elim q) normalize +(* [applyS exp_n_O funziona ma non lo trova *) +// H normalize @le_times // + |cut (pred (2*(S n)) = S(S(pred(2*n)))) + [>S_pred // @(le_times 1 ? 1) //] #H1 + cut (2^(pred (2*(S n))) = 2^(pred(2*n))*2*2) + [>H1 >H1 //] #H2 >H2 + @(transitive_le ? ((2^(pred (2*n))) * n! * n! *(2*(S n))*(2*(S n)))) + [@le_times[@le_times //]// + (* we generalize to hide the computational content *) + |normalize in match ((S n)!) generalize in match (S n) + #Sn generalize in match 2 #two // + ] + ] +qed. + +theorem fact_to_exp: ∀n. + (2*n)! ≤ (2^(pred (2*n))) * n! * n!. +#n (cases n) [normalize // |#n @fact_to_exp1 //] +qed. + +theorem exp_to_fact1: ∀n.O < n → + 2^(2*n)*n!*n! < (S(2*n))!. +#n #posn (elim posn) [normalize //] +#n #posn #Hind (cut (∀i.2*(S i) = S(S(2*i)))) [//] #H +cut (2^(2*(S n)) = 2^(2*n)*2*2) [>H //] #H1 >H1 +@(le_to_lt_to_lt ? (2^(2*n)*n!*n!*(2*(S n))*(2*(S n)))) + [normalize in match ((S n)!) generalize in match (S n) #Sn + generalize in match 2 #two // + |cut ((S(2*(S n)))! = (S(2*n))!*(S(S(2*n)))*(S(S(S(2*n))))) + [>H //] #H2 >H2 @lt_to_le_to_lt_times + [@lt_to_le_to_lt_times //|>H // | //] + ] +qed. + +(* a slightly better result +theorem fact3: \forall n.O < n \to +(exp 2 (2*n))*(exp (fact n) 2) \le 2*n*fact (2*n). +intros. +elim H + [simplify.apply le_n + |rewrite > times_SSO. + rewrite > factS. + rewrite < times_exp. + change in ⊢ (? (? % ?) ?) with ((S(S O))*((S(S O))*(exp (S(S O)) ((S(S O))*n1)))). + rewrite > assoc_times. + rewrite > assoc_times in ⊢ (? (? ? %) ?). + rewrite < assoc_times in ⊢ (? (? ? (? ? %)) ?). + rewrite < sym_times in ⊢ (? (? ? (? ? (? % ?))) ?). + rewrite > assoc_times in ⊢ (? (? ? (? ? %)) ?). + apply (trans_le ? (((S(S O))*((S(S O))*((S n1)\sup((S(S O)))*((S(S O))*n1*((S(S O))*n1)!)))))) + [apply le_times_r. + apply le_times_r. + apply le_times_r. + assumption + |rewrite > factS. + rewrite > factS. + rewrite < times_SSO. + rewrite > assoc_times in ⊢ (? ? %). + apply le_times_r. + rewrite < assoc_times. + change in ⊢ (? (? (? ? %) ?) ?) with ((S n1)*((S n1)*(S O))). + rewrite < assoc_times in ⊢ (? (? % ?) ?). + rewrite < times_n_SO. + rewrite > sym_times in ⊢ (? (? (? % ?) ?) ?). + rewrite < assoc_times in ⊢ (? ? %). + rewrite < assoc_times in ⊢ (? ? (? % ?)). + apply le_times_r. + apply le_times_l. + apply le_S.apply le_n + ] + ] +qed. + +theorem le_fact_10: fact (2*5) \le (exp 2 ((2*5)-2))*(fact 5)*(fact 5). +simplify in \vdash (? (? %) ?). +rewrite > factS in \vdash (? % ?). +rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash(? % ?). +rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash (? % ?). +rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash (? % ?). +rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash (? % ?). +apply le_times_l. +apply leb_true_to_le.reflexivity. +qed. + +theorem ab_times_cd: \forall a,b,c,d.(a*b)*(c*d)=(a*c)*(b*d). +intros. +rewrite > assoc_times. +rewrite > assoc_times. +apply eq_f. +rewrite < assoc_times. +rewrite < assoc_times. +rewrite > sym_times in \vdash (? ? (? % ?) ?). +reflexivity. +qed. + +(* an even better result *) +theorem lt_SSSSO_to_fact: \forall n.4 times_SSO. + change in \vdash (? ? (? (? (? ? %) ?) ?)) with (2*n1 - O); + rewrite < minus_n_O. + rewrite > factS. + rewrite > factS. + rewrite < assoc_times. + rewrite > factS. + apply (trans_le ? ((2*(S n1))*(2*(S n1))*(fact (2*n1)))) + [apply le_times_l. + rewrite > times_SSO. + apply le_times_r. + apply le_n_Sn + |apply (trans_le ? (2*S n1*(2*S n1)*(2\sup(2*n1-2)*n1!*n1!))) + [apply le_times_r.assumption + |rewrite > assoc_times. + rewrite > ab_times_cd in \vdash (? (? ? %) ?). + rewrite < assoc_times. + apply le_times_l. + rewrite < assoc_times in \vdash (? (? ? %) ?). + rewrite > ab_times_cd. + apply le_times_l. + rewrite < exp_S. + rewrite < exp_S. + apply le_exp + [apply lt_O_S + |rewrite > eq_minus_S_pred. + rewrite < S_pred + [rewrite > eq_minus_S_pred. + rewrite < S_pred + [rewrite < minus_n_O. + apply le_n + |elim H1;simplify + [apply lt_O_S + |apply lt_O_S + ] + ] + |elim H1;simplify + [apply lt_O_S + |rewrite < plus_n_Sm. + rewrite < minus_n_O. + apply lt_O_S + ] + ] + ] + ] + ] + ] +qed. *)