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
201 theorem stirling: \forall n,k.k \le n \to
202 log (fact n) < n*log n - n + k*log n.
206 elim (lt_O_to_or_eq_S m)
210 apply (le_to_lt_to_lt ? (log ((exp (S(S O)) ((S(S O))*a))*(fact a)*(fact a))))
211 [apply monotonic_log.
213 |rewrite > assoc_times in ⊢ (? (? %) ?).
215 apply (le_to_lt_to_lt ? ((S(S O))*a+S(log a!+log a!)))
218 |rewrite < plus_n_Sm.
219 rewrite > plus_n_O in ⊢ (? (? (? ? (? ? %))) ?).
221 (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)).
222 apply (trans_lt ? (S ((S(S O))*a+(S(S O))*(a*log a-a+k*log a))))