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/log".
17 include "datatypes/constructors.ma".
18 include "nat/minimization.ma".
19 include "nat/relevant_equations.ma".
20 include "nat/primes.ma".
21 include "nat/iteration2.ma".
22 include "nat/div_and_mod_diseq.ma".
24 definition log \def \lambda p,n.
25 max n (\lambda x.leb (exp p x) n).
27 theorem le_exp_log: \forall p,n. O < n \to
28 exp p (log p n) \le n.
32 apply (f_max_true (\lambda x.leb (exp p x) n)).
33 apply (ex_intro ? ? O).
36 |apply le_to_leb_true.simplify.assumption
40 theorem log_SO: \forall n. S O < n \to log n (S O) = O.
42 apply sym_eq.apply le_n_O_to_eq.
43 apply (le_exp_to_le n)
45 |simplify in ⊢ (? ? %).
51 theorem lt_to_log_O: \forall n,m. O < m \to m < n \to log n m = O.
53 apply sym_eq.apply le_n_O_to_eq.
55 apply (lt_exp_to_lt n)
56 [apply (le_to_lt_to_lt ? m);assumption
57 |simplify in ⊢ (? ? %).
59 apply (le_to_lt_to_lt ? m)
60 [apply le_exp_log.assumption
66 theorem lt_log_n_n: \forall p, n. S O < p \to O < n \to log p n < n.
69 [elim (le_to_or_lt_eq ? ? Hcut)
71 |absurd (exp p n \le n)
72 [rewrite < H2 in ⊢ (? (? ? %) ?).
80 |unfold log.apply le_max_n
84 theorem lt_O_log: \forall p,n. O < n \to p \le n \to O < log p n.
89 apply (leb_false_to_not_le ? ? ? H1).
90 rewrite > (exp_n_SO p).
91 apply (lt_max_to_false ? ? ? H2).
95 theorem le_log_n_n: \forall p,n. S O < p \to log p n \le n.
101 [assumption|apply lt_O_S]
105 theorem lt_exp_log: \forall p,n. S O < p \to n < exp p (S (log p n)).
107 [simplify.rewrite < times_n_SO.apply lt_to_le.assumption
109 apply leb_false_to_not_le.
110 apply (lt_max_to_false ? (S n1) (S (log p (S n1))))
111 [apply le_S_S.apply le_n
113 [assumption|apply lt_O_S]
118 theorem log_times1: \forall p,n,m. S O < p \to O < n \to O < m \to
119 log p (n*m) \le S(log p n+log p m).
121 unfold in ⊢ (? (% ? ?) ?).
122 apply f_false_to_le_max
123 [apply (ex_intro ? ? O).
126 |apply le_to_leb_true.
128 rewrite > times_n_SO.
129 apply le_times;assumption
132 apply lt_to_leb_false.
133 apply (lt_to_le_to_lt ? ((exp p (S(log p n)))*(exp p (S(log p m)))))
134 [apply lt_times;apply lt_exp_log;assumption
135 |rewrite < exp_plus_times.
137 [apply lt_to_le.assumption
146 theorem log_times: \forall p,n,m.S O < p \to log p (n*m) \le S(log p n+log p m).
151 [rewrite < times_n_O.
162 theorem log_exp: \forall p,n,m.S O < p \to O < m \to
163 log p ((exp p n)*m)=n+log p m.
165 unfold log in ⊢ (? ? (% ? ?) ?).
166 apply max_spec_to_max.
176 rewrite > assoc_times.
177 apply (trans_le ? ((S(S O))*(p\sup n1*m)))
178 [apply le_S_times_SSO
179 [rewrite > (times_n_O O) in ⊢ (? % ?).
195 apply le_to_leb_true.
196 rewrite > exp_plus_times.
203 apply lt_to_leb_false.
204 apply (lt_to_le_to_lt ? ((exp p n)*(exp p (S(log p m)))))
206 [apply lt_O_exp.apply lt_to_le.assumption
207 |apply lt_exp_log.assumption
209 |rewrite < exp_plus_times.
211 [apply lt_to_le.assumption
212 |rewrite < plus_n_Sm.
219 theorem eq_log_exp: \forall p,n.S O < p \to
222 rewrite > times_n_SO in ⊢ (? ? (? ? %) ?).
225 [rewrite < plus_n_O.reflexivity
233 theorem log_exp1: \forall p,n,m.S O < p \to
234 log p (exp n m) \le m*S(log p n).
236 [simplify in ⊢ (? (? ? %) ?).
242 apply (trans_le ? (S (log p n+log p (n\sup n1))))
243 [apply log_times.assumption
251 theorem log_exp2: \forall p,n,m.S O < p \to O < n \to
252 m*(log p n) \le log p (exp n m).
255 apply (lt_exp_to_lt p)
257 |rewrite > sym_times.
258 rewrite < exp_exp_times.
259 apply (le_to_lt_to_lt ? (exp n m))
262 |simplify.apply le_times
274 lemma le_log_plus: \forall p,n.S O < p \to log p n \leq log p (S n).
275 intros;apply (bool_elim ? (leb (p*(exp p n)) (S n)))
276 [simplify;intro;rewrite > H1;simplify;apply (trans_le ? n)
277 [apply le_log_n_n;assumption
279 |intro;unfold log;simplify;rewrite > H1;simplify;apply le_max_f_max_g;
280 intros;apply le_to_leb_true;constructor 2;apply leb_true_to_le;assumption]
283 theorem le_log: \forall p,n,m. S O < p \to n \le m \to
287 |apply (trans_le ? ? ? H3);apply le_log_plus;assumption]
290 theorem log_n_n: \forall n. S O < n \to log n n = S O.
292 rewrite > exp_n_SO in ⊢ (? ? (? ? %) ?).
293 rewrite > times_n_SO in ⊢ (? ? (? ? %) ?).
304 theorem log_i_SSOn: \forall n,i. S O < n \to n < i \to i \le ((S(S O))*n) \to
305 log i ((S(S O))*n) = S O.
307 apply antisymmetric_le
308 [apply not_lt_to_le.intro.
309 apply (lt_to_not_le ((S(S O)) * n) (exp i (S(S O))))
312 [apply (le_to_lt_to_lt ? n);assumption
315 |apply (trans_le ? (exp i (log i ((S(S O))*n))))
317 [apply (ltn_to_ltO ? ? H1)
321 rewrite > (times_n_O O) in ⊢ (? % ?).
324 |apply lt_to_le.assumption
328 |apply (trans_le ? (log i i))
329 [rewrite < (log_n_n i) in ⊢ (? % ?)
331 [apply (trans_lt ? n);assumption
334 |apply (trans_lt ? n);assumption
337 [apply (trans_lt ? n);assumption
344 theorem exp_n_O: \forall n. O < n \to exp O n = O.
345 intros.apply (lt_O_n_elim ? H).intros.
346 simplify.reflexivity.
350 theorem tech1: \forall n,i.O < n \to
351 (exp (S n) (S(S i)))/(exp n (S i)) \le ((exp n i) + (exp (S n) (S i)))/(exp n i).
353 simplify in ⊢ (? (? ? %) ?).
354 rewrite < eq_div_div_div_times
356 [apply lt_O_exp.assumption
358 apply lt_times_to_lt_div.
359 change in ⊢ (? % ?) with ((exp (S n) (S i)) + n*(exp (S n) (S i))).
362 |apply (trans_le ? ((n)\sup(i)*(S n)\sup(S i)/(n)\sup(S i)))
363 [apply le_times_div_div_times.
364 apply lt_O_exp.assumption
365 |apply le_times_to_le_div2
366 [apply lt_O_exp.assumption
369 theorem tech1: \forall a,b,n,m.O < m \to
370 n/m \le b \to (a*n)/m \le a*b.
372 apply le_times_to_le_div2
376 theorem tech2: \forall n,m. O < n \to
377 (exp (S n) m) / (exp n m) \le (n + m)/n.
380 [rewrite < plus_n_O.simplify.
381 rewrite > div_n_n.apply le_n
382 |apply le_times_to_le_div
384 |apply (trans_le ? (n*(S n)\sup(S n1)/(n)\sup(S n1)))
385 [apply le_times_div_div_times.
387 |simplify in ⊢ (? (? ? %) ?).
388 rewrite > sym_times in ⊢ (? (? ? %) ?).
389 rewrite < eq_div_div_div_times
390 [apply le_times_to_le_div2
395 theorem le_log_sigma_p:\forall n,m,p. O < m \to S O < p \to
396 log p (exp n m) \le sigma_p n (\lambda i.true) (\lambda i. (m / i)).
403 |rewrite > true_to_sigma_p_Sn
404 [apply (trans_le ? (m/n1+(log p (exp n1 m))))