1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| A.Asperti, C.Sacerdoti Coen, *)
8 (* ||A|| E.Tassi, S.Zacchiroli *)
10 (* \ / Matita is distributed under the terms of the *)
11 (* v GNU Lesser General Public License Version 2.1 *)
13 (**************************************************************************)
15 set "baseuri" "cic:/matita/nat/factorial2".
18 include "nat/factorial.ma".
20 theorem factS: \forall n. fact (S n) = (S n)*(fact n).
21 intro.simplify.reflexivity.
24 theorem exp_S: \forall n,m. exp m (S n) = m*exp m n.
28 theorem lt_O_to_fact1: \forall n.O<n \to
29 fact (2*n) \le (exp 2 (pred (2*n)))*(fact n)*(fact n).
35 rewrite < assoc_times.
37 apply (trans_le ? ((2*(S n1))*(2*(S n1))*(fact (2*n1))))
42 |rewrite > assoc_times.
43 rewrite > assoc_times.
44 rewrite > assoc_times in ⊢ (? ? %).
45 change in ⊢ (? ? (? (? ? %) ?)) with (S(2*n1)).
47 rewrite > assoc_times in ⊢ (? ? %).
49 rewrite < assoc_times.
50 rewrite < assoc_times.
51 rewrite < sym_times in ⊢ (? (? (? % ?) ?) ?).
52 rewrite > assoc_times.
53 rewrite > assoc_times.
54 rewrite > S_pred in ⊢ (? ? (? (? ? %) ?))
56 rewrite > assoc_times in ⊢ (? ? %).
58 rewrite > sym_times in ⊢ (? ? %).
59 rewrite > assoc_times in ⊢ (? ? %).
60 rewrite > assoc_times in ⊢ (? ? %).
62 rewrite < assoc_times in ⊢ (? ? %).
63 rewrite < assoc_times in ⊢ (? ? %).
64 rewrite < sym_times in ⊢ (? ? (? (? % ?) ?)).
65 rewrite > assoc_times in ⊢ (? ? %).
66 rewrite > assoc_times in ⊢ (? ? %).
68 rewrite > sym_times in ⊢ (? ? (? ? %)).
69 rewrite > sym_times in ⊢ (? ? %).
71 |unfold.rewrite > times_n_SO in ⊢ (? % ?).
81 theorem fact1: \forall n.
82 fact (2*n) \le (exp 2 (pred (2*n)))*(fact n)*(fact n).
90 theorem lt_O_fact: \forall n. O < fact n.
92 [simplify.apply lt_O_S
94 rewrite > (times_n_O O).
102 theorem fact2: \forall n.O < n \to
103 (exp (S(S O)) ((S(S O))*n))*(fact n)*(fact n) < fact (S((S(S O))*n)).
105 [simplify.apply le_S.apply le_n
106 |rewrite > times_SSO.
109 rewrite < assoc_times.
111 rewrite < times_SSO in ⊢ (? ? %).
112 apply (trans_lt ? (((S(S O))*S n1)*((S(S O))*S n1*(S ((S(S O))*n1))!)))
113 [rewrite > assoc_times in ⊢ (? ? %).
115 rewrite > assoc_times.
116 rewrite > assoc_times.
117 rewrite > assoc_times.
120 rewrite > assoc_times.
121 rewrite > sym_times in ⊢ (? ? %).
122 rewrite > assoc_times in ⊢ (? ? %).
123 rewrite > assoc_times in ⊢ (? ? %).
126 rewrite > assoc_times.
127 rewrite > assoc_times.
129 rewrite < assoc_times.
130 rewrite < assoc_times.
131 rewrite > sym_times in ⊢ (? (? (? % ?) ?) ?).
132 rewrite > assoc_times.
133 rewrite > assoc_times.
134 rewrite > sym_times in ⊢ (? ? %).
136 rewrite < assoc_times.
138 rewrite < assoc_times.
141 [rewrite > (times_n_O O) in ⊢ (? % ?).
143 [rewrite > (times_n_O O) in ⊢ (? % ?).
156 (* a slightly better result *)
157 theorem fact3: \forall n.O < n \to
158 (exp (S(S O)) ((S(S O))*n))*(exp (fact n) (S(S O))) \le (S(S O))*n*fact ((S(S O))*n).
162 |rewrite > times_SSO.
165 change in ⊢ (? (? % ?) ?) with ((S(S O))*((S(S O))*(exp (S(S O)) ((S(S O))*n1)))).
166 rewrite > assoc_times.
167 rewrite > assoc_times in ⊢ (? (? ? %) ?).
168 rewrite < assoc_times in ⊢ (? (? ? (? ? %)) ?).
169 rewrite < sym_times in ⊢ (? (? ? (? ? (? % ?))) ?).
170 rewrite > assoc_times in ⊢ (? (? ? (? ? %)) ?).
171 apply (trans_le ? (((S(S O))*((S(S O))*((S n1)\sup((S(S O)))*((S(S O))*n1*((S(S O))*n1)!))))))
179 rewrite > assoc_times in ⊢ (? ? %).
181 rewrite < assoc_times.
182 change in ⊢ (? (? (? ? %) ?) ?) with ((S n1)*((S n1)*(S O))).
183 rewrite < assoc_times in ⊢ (? (? % ?) ?).
184 rewrite < times_n_SO.
185 rewrite > sym_times in ⊢ (? (? (? % ?) ?) ?).
186 rewrite < assoc_times in ⊢ (? ? %).
187 rewrite < assoc_times in ⊢ (? ? (? % ?)).
190 apply le_S.apply le_n
195 theorem le_fact_10: fact (2*5) \le (exp 2 ((2*5)-2))*(fact 5)*(fact 5).
196 simplify in \vdash (? (? %) ?).
197 rewrite > factS in \vdash (? % ?).
198 rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash(? % ?).
199 rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash (? % ?).
200 rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash (? % ?).
201 rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash (? % ?).
203 apply leb_true_to_le.reflexivity.
206 theorem ab_times_cd: \forall a,b,c,d.(a*b)*(c*d)=(a*c)*(b*d).
208 rewrite > assoc_times.
209 rewrite > assoc_times.
211 rewrite < assoc_times.
212 rewrite < assoc_times.
213 rewrite > sym_times in \vdash (? ? (? % ?) ?).
217 (* an even better result *)
218 theorem lt_SSSSO_to_fact: \forall n.4<n \to
219 fact (2*n) \le (exp 2 ((2*n)-2))*(fact n)*(fact n).
222 |rewrite > times_SSO.
223 change in \vdash (? ? (? (? (? ? %) ?) ?)) with (2*n1 - O);
227 rewrite < assoc_times.
229 apply (trans_le ? ((2*(S n1))*(2*(S n1))*(fact (2*n1))))
234 |apply (trans_le ? (2*S n1*(2*S n1)*(2\sup(2*n1-2)*n1!*n1!)))
235 [apply le_times_r.assumption
236 |rewrite > assoc_times.
237 rewrite > ab_times_cd in \vdash (? (? ? %) ?).
238 rewrite < assoc_times.
240 rewrite < assoc_times in \vdash (? (? ? %) ?).
241 rewrite > ab_times_cd.
247 |rewrite > eq_minus_S_pred.
249 [rewrite > eq_minus_S_pred.
251 [rewrite < minus_n_O.
260 |rewrite < plus_n_Sm.
273 theorem stirling: \forall n,k.k \le n \to
274 log (fact n) < n*log n - n + k*log n.
278 elim (lt_O_to_or_eq_S m)
282 apply (le_to_lt_to_lt ? (log ((exp (S(S O)) ((S(S O))*a))*(fact a)*(fact a))))
283 [apply monotonic_log.
285 |rewrite > assoc_times in ⊢ (? (? %) ?).
287 apply (le_to_lt_to_lt ? ((S(S O))*a+S(log a!+log a!)))
290 |rewrite < plus_n_Sm.
291 rewrite > plus_n_O in ⊢ (? (? (? ? (? ? %))) ?).
293 (S((S(S O))*a+((S(S O))*log a!)) < (S(S O))*a*log ((S(S O))*a)-(S(S O))*a+k*log ((S(S O))*a)).
294 apply (trans_lt ? (S ((S(S O))*a+(S(S O))*(a*log a-a+k*log a))))