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 (**************************************************************************)
16 include "nat/factorial.ma".
18 theorem factS: \forall n. fact (S n) = (S n)*(fact n).
19 intro.simplify.reflexivity.
22 theorem exp_S: \forall n,m. exp m (S n) = m*exp m n.
26 theorem lt_O_to_fact1: \forall n.O<n \to
27 fact (2*n) \le (exp 2 (pred (2*n)))*(fact n)*(fact n).
33 rewrite < assoc_times.
35 apply (trans_le ? ((2*(S n1))*(2*(S n1))*(fact (2*n1))))
40 |rewrite > assoc_times.
41 rewrite > assoc_times.
42 rewrite > assoc_times in ⊢ (? ? %).
43 change in ⊢ (? ? (? (? ? %) ?)) with (S(2*n1)).
45 rewrite > assoc_times in ⊢ (? ? %).
47 rewrite < assoc_times.
48 rewrite < assoc_times.
49 rewrite < sym_times in ⊢ (? (? (? % ?) ?) ?).
50 rewrite > assoc_times.
51 rewrite > assoc_times.
52 rewrite > S_pred in ⊢ (? ? (? (? ? %) ?))
54 rewrite > assoc_times in ⊢ (? ? %).
56 rewrite > sym_times in ⊢ (? ? %).
57 rewrite > assoc_times in ⊢ (? ? %).
58 rewrite > assoc_times in ⊢ (? ? %).
60 rewrite < assoc_times in ⊢ (? ? %).
61 rewrite < assoc_times in ⊢ (? ? %).
62 rewrite < sym_times in ⊢ (? ? (? (? % ?) ?)).
63 rewrite > assoc_times in ⊢ (? ? %).
64 rewrite > assoc_times in ⊢ (? ? %).
66 rewrite > sym_times in ⊢ (? ? (? ? %)).
67 rewrite > sym_times in ⊢ (? ? %).
69 |unfold.rewrite > times_n_SO in ⊢ (? % ?).
79 theorem fact1: \forall n.
80 fact (2*n) \le (exp 2 (pred (2*n)))*(fact n)*(fact n).
88 theorem lt_O_fact: \forall n. O < fact n.
90 [simplify.apply lt_O_S
92 rewrite > (times_n_O O).
100 theorem fact2: \forall n.O < n \to
101 (exp (S(S O)) ((S(S O))*n))*(fact n)*(fact n) < fact (S((S(S O))*n)).
103 [simplify.apply le_S.apply le_n
104 |rewrite > times_SSO.
107 rewrite < assoc_times.
109 rewrite < times_SSO in ⊢ (? ? %).
110 apply (trans_lt ? (((S(S O))*S n1)*((S(S O))*S n1*(S ((S(S O))*n1))!)))
111 [rewrite > assoc_times in ⊢ (? ? %).
113 rewrite > assoc_times.
114 rewrite > assoc_times.
115 rewrite > assoc_times.
118 rewrite > assoc_times.
119 rewrite > sym_times in ⊢ (? ? %).
120 rewrite > assoc_times in ⊢ (? ? %).
121 rewrite > assoc_times in ⊢ (? ? %).
124 rewrite > assoc_times.
125 rewrite > assoc_times.
127 rewrite < assoc_times.
128 rewrite < assoc_times.
129 rewrite > sym_times in ⊢ (? (? (? % ?) ?) ?).
130 rewrite > assoc_times.
131 rewrite > assoc_times.
132 rewrite > sym_times in ⊢ (? ? %).
134 rewrite < assoc_times.
136 rewrite < assoc_times.
139 [rewrite > (times_n_O O) in ⊢ (? % ?).
141 [rewrite > (times_n_O O) in ⊢ (? % ?).
154 (* a slightly better result *)
155 theorem fact3: \forall n.O < n \to
156 (exp (S(S O)) ((S(S O))*n))*(exp (fact n) (S(S O))) \le (S(S O))*n*fact ((S(S O))*n).
160 |rewrite > times_SSO.
163 change in ⊢ (? (? % ?) ?) with ((S(S O))*((S(S O))*(exp (S(S O)) ((S(S O))*n1)))).
164 rewrite > assoc_times.
165 rewrite > assoc_times in ⊢ (? (? ? %) ?).
166 rewrite < assoc_times in ⊢ (? (? ? (? ? %)) ?).
167 rewrite < sym_times in ⊢ (? (? ? (? ? (? % ?))) ?).
168 rewrite > assoc_times in ⊢ (? (? ? (? ? %)) ?).
169 apply (trans_le ? (((S(S O))*((S(S O))*((S n1)\sup((S(S O)))*((S(S O))*n1*((S(S O))*n1)!))))))
177 rewrite > assoc_times in ⊢ (? ? %).
179 rewrite < assoc_times.
180 change in ⊢ (? (? (? ? %) ?) ?) with ((S n1)*((S n1)*(S O))).
181 rewrite < assoc_times in ⊢ (? (? % ?) ?).
182 rewrite < times_n_SO.
183 rewrite > sym_times in ⊢ (? (? (? % ?) ?) ?).
184 rewrite < assoc_times in ⊢ (? ? %).
185 rewrite < assoc_times in ⊢ (? ? (? % ?)).
188 apply le_S.apply le_n
193 theorem le_fact_10: fact (2*5) \le (exp 2 ((2*5)-2))*(fact 5)*(fact 5).
194 simplify in \vdash (? (? %) ?).
195 rewrite > factS in \vdash (? % ?).
196 rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash(? % ?).
197 rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash (? % ?).
198 rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash (? % ?).
199 rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash (? % ?).
201 apply leb_true_to_le.reflexivity.
204 theorem ab_times_cd: \forall a,b,c,d.(a*b)*(c*d)=(a*c)*(b*d).
206 rewrite > assoc_times.
207 rewrite > assoc_times.
209 rewrite < assoc_times.
210 rewrite < assoc_times.
211 rewrite > sym_times in \vdash (? ? (? % ?) ?).
215 (* an even better result *)
216 theorem lt_SSSSO_to_fact: \forall n.4<n \to
217 fact (2*n) \le (exp 2 ((2*n)-2))*(fact n)*(fact n).
220 |rewrite > times_SSO.
221 change in \vdash (? ? (? (? (? ? %) ?) ?)) with (2*n1 - O);
225 rewrite < assoc_times.
227 apply (trans_le ? ((2*(S n1))*(2*(S n1))*(fact (2*n1))))
232 |apply (trans_le ? (2*S n1*(2*S n1)*(2\sup(2*n1-2)*n1!*n1!)))
233 [apply le_times_r.assumption
234 |rewrite > assoc_times.
235 rewrite > ab_times_cd in \vdash (? (? ? %) ?).
236 rewrite < assoc_times.
238 rewrite < assoc_times in \vdash (? (? ? %) ?).
239 rewrite > ab_times_cd.
245 |rewrite > eq_minus_S_pred.
247 [rewrite > eq_minus_S_pred.
249 [rewrite < minus_n_O.
258 |rewrite < plus_n_Sm.
271 theorem stirling: \forall n,k.k \le n \to
272 log (fact n) < n*log n - n + k*log n.
276 elim (lt_O_to_or_eq_S m)
280 apply (le_to_lt_to_lt ? (log ((exp (S(S O)) ((S(S O))*a))*(fact a)*(fact a))))
281 [apply monotonic_log.
283 |rewrite > assoc_times in ⊢ (? (? %) ?).
285 apply (le_to_lt_to_lt ? ((S(S O))*a+S(log a!+log a!)))
288 |rewrite < plus_n_Sm.
289 rewrite > plus_n_O in ⊢ (? (? (? ? (? ? %))) ?).
291 (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)).
292 apply (trans_lt ? (S ((S(S O))*a+(S(S O))*(a*log a-a+k*log a))))