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 lemma times_SSO: \forall n.(S(S O))*(S n) = S(S((S(S O))*n)).
29 intro.simplify.rewrite < plus_n_Sm.reflexivity.
32 theorem fact1: \forall n.
33 fact ((S(S O))*n) \le (exp (S(S O)) ((S(S O))*n))*(fact n)*(fact n).
35 [rewrite < times_n_O.apply le_n
39 rewrite < assoc_times.
41 apply (trans_le ? (((S(S O))*(S n1))*((S(S O))*(S n1))*(fact (((S(S O))*n1)))))
46 |rewrite > assoc_times.
47 rewrite > assoc_times.
48 rewrite > assoc_times in ⊢ (? ? %).
50 rewrite > assoc_times in ⊢ (? ? %).
52 rewrite < assoc_times.
53 rewrite < assoc_times.
54 rewrite < sym_times in ⊢ (? (? (? % ?) ?) ?).
55 rewrite > assoc_times.
56 rewrite > assoc_times.
58 rewrite > assoc_times in ⊢ (? ? %).
60 rewrite > sym_times in ⊢ (? ? %).
61 rewrite > assoc_times in ⊢ (? ? %).
62 rewrite > assoc_times in ⊢ (? ? %).
64 rewrite < assoc_times in ⊢ (? ? %).
65 rewrite < assoc_times in ⊢ (? ? %).
66 rewrite < sym_times in ⊢ (? ? (? (? % ?) ?)).
67 rewrite > assoc_times in ⊢ (? ? %).
68 rewrite > assoc_times in ⊢ (? ? %).
70 rewrite > sym_times in ⊢ (? ? (? ? %)).
71 rewrite > sym_times in ⊢ (? ? %).
77 theorem lt_O_fact: \forall n. O < fact n.
79 [simplify.apply lt_O_S
81 rewrite > (times_n_O O).
89 theorem fact2: \forall n.O < n \to
90 (exp (S(S O)) ((S(S O))*n))*(fact n)*(fact n) < fact (S((S(S O))*n)).
92 [simplify.apply le_S.apply le_n
96 rewrite < assoc_times.
98 rewrite < times_SSO in ⊢ (? ? %).
99 apply (trans_lt ? (((S(S O))*S n1)*((S(S O))*S n1*(S ((S(S O))*n1))!)))
100 [rewrite > assoc_times in ⊢ (? ? %).
102 rewrite > assoc_times.
103 rewrite > assoc_times.
104 rewrite > assoc_times.
107 rewrite > assoc_times.
108 rewrite > sym_times in ⊢ (? ? %).
109 rewrite > assoc_times in ⊢ (? ? %).
110 rewrite > assoc_times in ⊢ (? ? %).
113 rewrite > assoc_times.
114 rewrite > assoc_times.
116 rewrite < assoc_times.
117 rewrite < assoc_times.
118 rewrite > sym_times in ⊢ (? (? (? % ?) ?) ?).
119 rewrite > assoc_times.
120 rewrite > assoc_times.
121 rewrite > sym_times in ⊢ (? ? %).
123 rewrite < assoc_times.
125 rewrite < assoc_times.
128 [rewrite > (times_n_O O) in ⊢ (? % ?).
130 [rewrite > (times_n_O O) in ⊢ (? % ?).
143 (* a slightly better result *)
144 theorem fact3: \forall n.O < n \to
145 (exp (S(S O)) ((S(S O))*n))*(exp (fact n) (S(S O))) \le (S(S O))*n*fact ((S(S O))*n).
149 |rewrite > times_SSO.
152 change in ⊢ (? (? % ?) ?) with ((S(S O))*((S(S O))*(exp (S(S O)) ((S(S O))*n1)))).
153 rewrite > assoc_times.
154 rewrite > assoc_times in ⊢ (? (? ? %) ?).
155 rewrite < assoc_times in ⊢ (? (? ? (? ? %)) ?).
156 rewrite < sym_times in ⊢ (? (? ? (? ? (? % ?))) ?).
157 rewrite > assoc_times in ⊢ (? (? ? (? ? %)) ?).
158 apply (trans_le ? (((S(S O))*((S(S O))*((S n1)\sup((S(S O)))*((S(S O))*n1*((S(S O))*n1)!))))))
166 rewrite > assoc_times in ⊢ (? ? %).
168 rewrite < assoc_times.
169 change in ⊢ (? (? (? ? %) ?) ?) with ((S n1)*((S n1)*(S O))).
170 rewrite < assoc_times in ⊢ (? (? % ?) ?).
171 rewrite < times_n_SO.
172 rewrite > sym_times in ⊢ (? (? (? % ?) ?) ?).
173 rewrite < assoc_times in ⊢ (? ? %).
174 rewrite < assoc_times in ⊢ (? ? (? % ?)).
177 apply le_S.apply le_n
183 theorem stirling: \forall n,k.k \le n \to
184 log (fact n) < n*log n - n + k*log n.
188 elim (lt_O_to_or_eq_S m)
192 apply (le_to_lt_to_lt ? (log ((exp (S(S O)) ((S(S O))*a))*(fact a)*(fact a))))
193 [apply monotonic_log.
195 |rewrite > assoc_times in ⊢ (? (? %) ?).
197 apply (le_to_lt_to_lt ? ((S(S O))*a+S(log a!+log a!)))
200 |rewrite < plus_n_Sm.
201 rewrite > plus_n_O in ⊢ (? (? (? ? (? ? %))) ?).
203 (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)).
204 apply (trans_lt ? (S ((S(S O))*a+(S(S O))*(a*log a-a+k*log a))))