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_times_l: \forall p,n,m.O < n \to O < m \to S O < p \to
163 log p n+log p m \le log p (n*m) .
165 unfold log in ⊢ (? ? (% ? ?)).
178 rewrite < times_n_SO.
183 |apply (trans_le ? (S n1 + S n2))
184 [apply le_plus;apply le_log_n_n;assumption
188 change in ⊢ (? % ?) with ((S n1)+n2).
191 change with (n1 < n1*S n2).
192 rewrite > times_n_SO in ⊢ (? % ?).
195 |apply le_S_S.assumption
200 |apply le_to_leb_true.
201 rewrite > exp_plus_times.
202 apply le_times;apply le_exp_log;assumption
206 theorem log_exp: \forall p,n,m.S O < p \to O < m \to
207 log p ((exp p n)*m)=n+log p m.
209 unfold log in ⊢ (? ? (% ? ?) ?).
210 apply max_spec_to_max.
220 rewrite > assoc_times.
221 apply (trans_le ? ((S(S O))*(p\sup n1*m)))
222 [apply le_S_times_SSO
223 [rewrite > (times_n_O O) in ⊢ (? % ?).
239 apply le_to_leb_true.
240 rewrite > exp_plus_times.
247 apply lt_to_leb_false.
248 apply (lt_to_le_to_lt ? ((exp p n)*(exp p (S(log p m)))))
250 [apply lt_O_exp.apply lt_to_le.assumption
251 |apply lt_exp_log.assumption
253 |rewrite < exp_plus_times.
255 [apply lt_to_le.assumption
256 |rewrite < plus_n_Sm.
263 theorem eq_log_exp: \forall p,n.S O < p \to
266 rewrite > times_n_SO in ⊢ (? ? (? ? %) ?).
269 [rewrite < plus_n_O.reflexivity
277 theorem log_exp1: \forall p,n,m.S O < p \to
278 log p (exp n m) \le m*S(log p n).
280 [simplify in ⊢ (? (? ? %) ?).
286 apply (trans_le ? (S (log p n+log p (n\sup n1))))
287 [apply log_times.assumption
295 theorem log_exp2: \forall p,n,m.S O < p \to O < n \to
296 m*(log p n) \le log p (exp n m).
299 apply (lt_exp_to_lt p)
301 |rewrite > sym_times.
302 rewrite < exp_exp_times.
303 apply (le_to_lt_to_lt ? (exp n m))
306 |simplify.apply le_times
318 lemma le_log_plus: \forall p,n.S O < p \to log p n \leq log p (S n).
319 intros;apply (bool_elim ? (leb (p*(exp p n)) (S n)))
320 [simplify;intro;rewrite > H1;simplify;apply (trans_le ? n)
321 [apply le_log_n_n;assumption
323 |intro;unfold log;simplify;rewrite > H1;simplify;apply le_max_f_max_g;
324 intros;apply le_to_leb_true;constructor 2;apply leb_true_to_le;assumption]
327 theorem le_log: \forall p,n,m. S O < p \to n \le m \to
331 |apply (trans_le ? ? ? H3);apply le_log_plus;assumption]
334 theorem log_div: \forall p,n,m. S O < p \to O < m \to m \le n \to
335 log p (n/m) \le log p n -log p m.
337 apply le_plus_to_minus_r.
338 apply (trans_le ? (log p ((n/m)*m)))
340 [apply le_times_to_le_div
342 |rewrite < times_n_SO.
350 |rewrite > (div_mod n m) in ⊢ (? ? %)
358 theorem log_n_n: \forall n. S O < n \to log n n = S O.
360 rewrite > exp_n_SO in ⊢ (? ? (? ? %) ?).
361 rewrite > times_n_SO in ⊢ (? ? (? ? %) ?).
372 theorem log_i_SSOn: \forall n,i. S O < n \to n < i \to i \le ((S(S O))*n) \to
373 log i ((S(S O))*n) = S O.
375 apply antisymmetric_le
376 [apply not_lt_to_le.intro.
377 apply (lt_to_not_le ((S(S O)) * n) (exp i (S(S O))))
380 [apply (le_to_lt_to_lt ? n);assumption
383 |apply (trans_le ? (exp i (log i ((S(S O))*n))))
385 [apply (ltn_to_ltO ? ? H1)
389 rewrite > (times_n_O O) in ⊢ (? % ?).
392 |apply lt_to_le.assumption
396 |apply (trans_le ? (log i i))
397 [rewrite < (log_n_n i) in ⊢ (? % ?)
399 [apply (trans_lt ? n);assumption
402 |apply (trans_lt ? n);assumption
405 [apply (trans_lt ? n);assumption
412 theorem exp_n_O: \forall n. O < n \to exp O n = O.
413 intros.apply (lt_O_n_elim ? H).intros.
414 simplify.reflexivity.
418 theorem tech1: \forall n,i.O < n \to
419 (exp (S n) (S(S i)))/(exp n (S i)) \le ((exp n i) + (exp (S n) (S i)))/(exp n i).
421 simplify in ⊢ (? (? ? %) ?).
422 rewrite < eq_div_div_div_times
424 [apply lt_O_exp.assumption
426 apply lt_times_to_lt_div.
427 change in ⊢ (? % ?) with ((exp (S n) (S i)) + n*(exp (S n) (S i))).
430 |apply (trans_le ? ((n)\sup(i)*(S n)\sup(S i)/(n)\sup(S i)))
431 [apply le_times_div_div_times.
432 apply lt_O_exp.assumption
433 |apply le_times_to_le_div2
434 [apply lt_O_exp.assumption
437 theorem tech1: \forall a,b,n,m.O < m \to
438 n/m \le b \to (a*n)/m \le a*b.
440 apply le_times_to_le_div2
444 theorem tech2: \forall n,m. O < n \to
445 (exp (S n) m) / (exp n m) \le (n + m)/n.
448 [rewrite < plus_n_O.simplify.
449 rewrite > div_n_n.apply le_n
450 |apply le_times_to_le_div
452 |apply (trans_le ? (n*(S n)\sup(S n1)/(n)\sup(S n1)))
453 [apply le_times_div_div_times.
455 |simplify in ⊢ (? (? ? %) ?).
456 rewrite > sym_times in ⊢ (? (? ? %) ?).
457 rewrite < eq_div_div_div_times
458 [apply le_times_to_le_div2
463 theorem le_log_sigma_p:\forall n,m,p. O < m \to S O < p \to
464 log p (exp n m) \le sigma_p n (\lambda i.true) (\lambda i. (m / i)).
471 |rewrite > true_to_sigma_p_Sn
472 [apply (trans_le ? (m/n1+(log p (exp n1 m))))