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 alias num (instance 0) = "natural number".
29 lemma times_SSO: \forall n.2*(S n) = S(S(2*n)).
30 intro.simplify.rewrite < plus_n_Sm.reflexivity.
33 theorem lt_O_to_fact1: \forall n.O<n \to
34 fact (2*n) \le (exp 2 (pred (2*n)))*(fact n)*(fact n).
40 rewrite < assoc_times.
42 apply (trans_le ? ((2*(S n1))*(2*(S n1))*(fact (2*n1))))
47 |rewrite > assoc_times.
48 rewrite > assoc_times.
49 rewrite > assoc_times in ⊢ (? ? %).
50 change in ⊢ (? ? (? (? ? %) ?)) with (S(2*n1)).
52 rewrite > assoc_times in ⊢ (? ? %).
54 rewrite < assoc_times.
55 rewrite < assoc_times.
56 rewrite < sym_times in ⊢ (? (? (? % ?) ?) ?).
57 rewrite > assoc_times.
58 rewrite > assoc_times.
59 rewrite > S_pred in ⊢ (? ? (? (? ? %) ?))
61 rewrite > assoc_times in ⊢ (? ? %).
63 rewrite > sym_times in ⊢ (? ? %).
64 rewrite > assoc_times in ⊢ (? ? %).
65 rewrite > assoc_times in ⊢ (? ? %).
67 rewrite < assoc_times in ⊢ (? ? %).
68 rewrite < assoc_times in ⊢ (? ? %).
69 rewrite < sym_times in ⊢ (? ? (? (? % ?) ?)).
70 rewrite > assoc_times in ⊢ (? ? %).
71 rewrite > assoc_times in ⊢ (? ? %).
73 rewrite > sym_times in ⊢ (? ? (? ? %)).
74 rewrite > sym_times in ⊢ (? ? %).
76 |unfold.rewrite > times_n_SO in ⊢ (? % ?).
86 theorem fact1: \forall n.
87 fact (2*n) \le (exp 2 (pred (2*n)))*(fact n)*(fact n).
95 theorem lt_O_fact: \forall n. O < fact n.
97 [simplify.apply lt_O_S
99 rewrite > (times_n_O O).
107 theorem fact2: \forall n.O < n \to
108 (exp (S(S O)) ((S(S O))*n))*(fact n)*(fact n) < fact (S((S(S O))*n)).
110 [simplify.apply le_S.apply le_n
111 |rewrite > times_SSO.
114 rewrite < assoc_times.
116 rewrite < times_SSO in ⊢ (? ? %).
117 apply (trans_lt ? (((S(S O))*S n1)*((S(S O))*S n1*(S ((S(S O))*n1))!)))
118 [rewrite > assoc_times in ⊢ (? ? %).
120 rewrite > assoc_times.
121 rewrite > assoc_times.
122 rewrite > assoc_times.
125 rewrite > assoc_times.
126 rewrite > sym_times in ⊢ (? ? %).
127 rewrite > assoc_times in ⊢ (? ? %).
128 rewrite > assoc_times in ⊢ (? ? %).
131 rewrite > assoc_times.
132 rewrite > assoc_times.
134 rewrite < assoc_times.
135 rewrite < assoc_times.
136 rewrite > sym_times in ⊢ (? (? (? % ?) ?) ?).
137 rewrite > assoc_times.
138 rewrite > assoc_times.
139 rewrite > sym_times in ⊢ (? ? %).
141 rewrite < assoc_times.
143 rewrite < assoc_times.
146 [rewrite > (times_n_O O) in ⊢ (? % ?).
148 [rewrite > (times_n_O O) in ⊢ (? % ?).
161 (* a slightly better result *)
162 theorem fact3: \forall n.O < n \to
163 (exp (S(S O)) ((S(S O))*n))*(exp (fact n) (S(S O))) \le (S(S O))*n*fact ((S(S O))*n).
167 |rewrite > times_SSO.
170 change in ⊢ (? (? % ?) ?) with ((S(S O))*((S(S O))*(exp (S(S O)) ((S(S O))*n1)))).
171 rewrite > assoc_times.
172 rewrite > assoc_times in ⊢ (? (? ? %) ?).
173 rewrite < assoc_times in ⊢ (? (? ? (? ? %)) ?).
174 rewrite < sym_times in ⊢ (? (? ? (? ? (? % ?))) ?).
175 rewrite > assoc_times in ⊢ (? (? ? (? ? %)) ?).
176 apply (trans_le ? (((S(S O))*((S(S O))*((S n1)\sup((S(S O)))*((S(S O))*n1*((S(S O))*n1)!))))))
184 rewrite > assoc_times in ⊢ (? ? %).
186 rewrite < assoc_times.
187 change in ⊢ (? (? (? ? %) ?) ?) with ((S n1)*((S n1)*(S O))).
188 rewrite < assoc_times in ⊢ (? (? % ?) ?).
189 rewrite < times_n_SO.
190 rewrite > sym_times in ⊢ (? (? (? % ?) ?) ?).
191 rewrite < assoc_times in ⊢ (? ? %).
192 rewrite < assoc_times in ⊢ (? ? (? % ?)).
195 apply le_S.apply le_n
200 theorem le_fact_10: fact (2*5) \le (exp 2 ((2*5)-2))*(fact 5)*(fact 5).
201 simplify in \vdash (? (? %) ?).
202 rewrite > factS in \vdash (? % ?).
203 rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash(? % ?).
204 rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash (? % ?).
205 rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash (? % ?).
206 rewrite > factS in \vdash (? % ?).rewrite < assoc_times in \vdash (? % ?).
208 apply leb_true_to_le.reflexivity.
211 theorem ab_times_cd: \forall a,b,c,d.(a*b)*(c*d)=(a*c)*(b*d).
213 rewrite > assoc_times.
214 rewrite > assoc_times.
216 rewrite < assoc_times.
217 rewrite < assoc_times.
218 rewrite > sym_times in \vdash (? ? (? % ?) ?).
222 (* an even better result *)
223 theorem lt_SSSSO_to_fact: \forall n.4<n \to
224 fact (2*n) \le (exp 2 ((2*n)-2))*(fact n)*(fact n).
227 |rewrite > times_SSO.
228 change in \vdash (? ? (? (? (? ? %) ?) ?)) with (2*n1 - O);
232 rewrite < assoc_times.
234 apply (trans_le ? ((2*(S n1))*(2*(S n1))*(fact (2*n1))))
239 |apply (trans_le ? (2*S n1*(2*S n1)*(2\sup(2*n1-2)*n1!*n1!)))
240 [apply le_times_r.assumption
241 |rewrite > assoc_times.
242 rewrite > ab_times_cd in \vdash (? (? ? %) ?).
243 rewrite < assoc_times.
245 rewrite < assoc_times in \vdash (? (? ? %) ?).
246 rewrite > ab_times_cd.
252 |rewrite > eq_minus_S_pred.
254 [rewrite > eq_minus_S_pred.
256 [rewrite < minus_n_O.
265 |rewrite < plus_n_Sm.
278 theorem stirling: \forall n,k.k \le n \to
279 log (fact n) < n*log n - n + k*log n.
283 elim (lt_O_to_or_eq_S m)
287 apply (le_to_lt_to_lt ? (log ((exp (S(S O)) ((S(S O))*a))*(fact a)*(fact a))))
288 [apply monotonic_log.
290 |rewrite > assoc_times in ⊢ (? (? %) ?).
292 apply (le_to_lt_to_lt ? ((S(S O))*a+S(log a!+log a!)))
295 |rewrite < plus_n_Sm.
296 rewrite > plus_n_O in ⊢ (? (? (? ? (? ? %))) ?).
298 (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)).
299 apply (trans_lt ? (S ((S(S O))*a+(S(S O))*(a*log a-a+k*log a))))