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 (**************************************************************************)
16 include "datatypes/constructors.ma".
17 include "nat/minimization.ma".
18 include "nat/relevant_equations.ma".
19 include "nat/primes.ma".
20 include "nat/iteration2.ma".
21 include "nat/div_and_mod_diseq.ma".
23 definition log \def \lambda p,n.
24 max n (\lambda x.leb (exp p x) n).
26 theorem le_exp_log: \forall p,n. O < n \to
27 exp p (log p n) \le n.
31 apply (f_max_true (\lambda x.leb (exp p x) n)).
32 apply (ex_intro ? ? O).
35 |apply le_to_leb_true.simplify.assumption
39 theorem log_SO: \forall n. S O < n \to log n (S O) = O.
41 apply sym_eq.apply le_n_O_to_eq.
42 apply (le_exp_to_le n)
44 |simplify in ⊢ (? ? %).
50 theorem lt_to_log_O: \forall n,m. O < m \to m < n \to log n m = O.
52 apply sym_eq.apply le_n_O_to_eq.
54 apply (lt_exp_to_lt n)
55 [apply (le_to_lt_to_lt ? m);assumption
56 |simplify in ⊢ (? ? %).
58 apply (le_to_lt_to_lt ? m)
59 [apply le_exp_log.assumption
65 theorem lt_log_n_n: \forall p, n. S O < p \to O < n \to log p n < n.
68 [elim (le_to_or_lt_eq ? ? Hcut)
70 |absurd (exp p n \le n)
71 [rewrite < H2 in ⊢ (? (? ? %) ?).
79 |unfold log.apply le_max_n
83 theorem lt_O_log: \forall p,n. O < n \to p \le n \to O < log p n.
88 apply (leb_false_to_not_le ? ? ? H1).
89 rewrite > (exp_n_SO p).
90 apply (lt_max_to_false ? ? ? H2).
94 theorem le_log_n_n: \forall p,n. S O < p \to log p n \le n.
100 [assumption|apply lt_O_S]
104 theorem lt_exp_log: \forall p,n. S O < p \to n < exp p (S (log p n)).
106 [simplify.rewrite < times_n_SO.apply lt_to_le.assumption
108 apply leb_false_to_not_le.
109 apply (lt_max_to_false ? (S n1) (S (log p (S n1))))
110 [apply le_S_S.apply le_n
112 [assumption|apply lt_O_S]
117 theorem log_times1: \forall p,n,m. S O < p \to O < n \to O < m \to
118 log p (n*m) \le S(log p n+log p m).
120 unfold in ⊢ (? (% ? ?) ?).
121 apply f_false_to_le_max
122 [apply (ex_intro ? ? O).
125 |apply le_to_leb_true.
127 rewrite > times_n_SO.
128 apply le_times;assumption
131 apply lt_to_leb_false.
132 apply (lt_to_le_to_lt ? ((exp p (S(log p n)))*(exp p (S(log p m)))))
133 [apply lt_times;apply lt_exp_log;assumption
134 |rewrite < exp_plus_times.
136 [apply lt_to_le.assumption
145 theorem log_times: \forall p,n,m.S O < p \to log p (n*m) \le S(log p n+log p m).
150 [rewrite < times_n_O.
161 theorem log_times_l: \forall p,n,m.O < n \to O < m \to S O < p \to
162 log p n+log p m \le log p (n*m) .
164 unfold log in ⊢ (? ? (% ? ?)).
177 rewrite < times_n_SO.
182 |apply (trans_le ? (S n1 + S n2))
183 [apply le_plus;apply le_log_n_n;assumption
187 change in ⊢ (? % ?) with ((S n1)+n2).
190 change with (n1 < n1*S n2).
191 rewrite > times_n_SO in ⊢ (? % ?).
194 |apply le_S_S.assumption
199 |apply le_to_leb_true.
200 rewrite > exp_plus_times.
201 apply le_times;apply le_exp_log;assumption
205 theorem log_exp: \forall p,n,m.S O < p \to O < m \to
206 log p ((exp p n)*m)=n+log p m.
208 unfold log in ⊢ (? ? (% ? ?) ?).
209 apply max_spec_to_max.
219 rewrite > assoc_times.
220 apply (trans_le ? ((S(S O))*(p\sup n1*m)))
221 [apply le_S_times_SSO
222 [rewrite > (times_n_O O) in ⊢ (? % ?).
238 apply le_to_leb_true.
239 rewrite > exp_plus_times.
246 apply lt_to_leb_false.
247 apply (lt_to_le_to_lt ? ((exp p n)*(exp p (S(log p m)))))
249 [apply lt_O_exp.apply lt_to_le.assumption
250 |apply lt_exp_log.assumption
252 |rewrite < exp_plus_times.
254 [apply lt_to_le.assumption
255 |rewrite < plus_n_Sm.
262 theorem eq_log_exp: \forall p,n.S O < p \to
265 rewrite > times_n_SO in ⊢ (? ? (? ? %) ?).
268 [rewrite < plus_n_O.reflexivity
276 theorem log_exp1: \forall p,n,m.S O < p \to
277 log p (exp n m) \le m*S(log p n).
279 [simplify in ⊢ (? (? ? %) ?).
285 apply (trans_le ? (S (log p n+log p (n\sup n1))))
286 [apply log_times.assumption
294 theorem log_exp2: \forall p,n,m.S O < p \to O < n \to
295 m*(log p n) \le log p (exp n m).
298 apply (lt_exp_to_lt p)
300 |rewrite > sym_times.
301 rewrite < exp_exp_times.
302 apply (le_to_lt_to_lt ? (exp n m))
305 |simplify.apply le_times
317 lemma le_log_plus: \forall p,n.S O < p \to log p n \leq log p (S n).
318 intros;apply (bool_elim ? (leb (p*(exp p n)) (S n)))
319 [simplify;intro;rewrite > H1;simplify;apply (trans_le ? n)
320 [apply le_log_n_n;assumption
322 |intro;unfold log;simplify;rewrite > H1;simplify;apply le_max_f_max_g;
323 intros;apply le_to_leb_true;constructor 2;apply leb_true_to_le;assumption]
326 theorem le_log: \forall p,n,m. S O < p \to n \le m \to
330 |apply (trans_le ? ? ? H3);apply le_log_plus;assumption]
333 theorem log_div: \forall p,n,m. S O < p \to O < m \to m \le n \to
334 log p (n/m) \le log p n -log p m.
336 apply le_plus_to_minus_r.
337 apply (trans_le ? (log p ((n/m)*m)))
339 [apply le_times_to_le_div
341 |rewrite < times_n_SO.
349 |rewrite > (div_mod n m) in ⊢ (? ? %)
357 theorem log_n_n: \forall n. S O < n \to log n n = S O.
359 rewrite > exp_n_SO in ⊢ (? ? (? ? %) ?).
360 rewrite > times_n_SO in ⊢ (? ? (? ? %) ?).
371 theorem log_i_SSOn: \forall n,i. S O < n \to n < i \to i \le ((S(S O))*n) \to
372 log i ((S(S O))*n) = S O.
374 apply antisymmetric_le
375 [apply not_lt_to_le.intro.
376 apply (lt_to_not_le ((S(S O)) * n) (exp i (S(S O))))
379 [apply (le_to_lt_to_lt ? n);assumption
382 |apply (trans_le ? (exp i (log i ((S(S O))*n))))
384 [apply (ltn_to_ltO ? ? H1)
388 rewrite > (times_n_O O) in ⊢ (? % ?).
391 |apply lt_to_le.assumption
395 |apply (trans_le ? (log i i))
396 [rewrite < (log_n_n i) in ⊢ (? % ?)
398 [apply (trans_lt ? n);assumption
401 |apply (trans_lt ? n);assumption
404 [apply (trans_lt ? n);assumption
411 theorem exp_n_O: \forall n. O < n \to exp O n = O.
412 intros.apply (lt_O_n_elim ? H).intros.
413 simplify.reflexivity.
417 theorem tech1: \forall n,i.O < n \to
418 (exp (S n) (S(S i)))/(exp n (S i)) \le ((exp n i) + (exp (S n) (S i)))/(exp n i).
420 simplify in ⊢ (? (? ? %) ?).
421 rewrite < eq_div_div_div_times
423 [apply lt_O_exp.assumption
425 apply lt_times_to_lt_div.
426 change in ⊢ (? % ?) with ((exp (S n) (S i)) + n*(exp (S n) (S i))).
429 |apply (trans_le ? ((n)\sup(i)*(S n)\sup(S i)/(n)\sup(S i)))
430 [apply le_times_div_div_times.
431 apply lt_O_exp.assumption
432 |apply le_times_to_le_div2
433 [apply lt_O_exp.assumption
436 theorem tech1: \forall a,b,n,m.O < m \to
437 n/m \le b \to (a*n)/m \le a*b.
439 apply le_times_to_le_div2
443 theorem tech2: \forall n,m. O < n \to
444 (exp (S n) m) / (exp n m) \le (n + m)/n.
447 [rewrite < plus_n_O.simplify.
448 rewrite > div_n_n.apply le_n
449 |apply le_times_to_le_div
451 |apply (trans_le ? (n*(S n)\sup(S n1)/(n)\sup(S n1)))
452 [apply le_times_div_div_times.
454 |simplify in ⊢ (? (? ? %) ?).
455 rewrite > sym_times in ⊢ (? (? ? %) ?).
456 rewrite < eq_div_div_div_times
457 [apply le_times_to_le_div2
462 theorem le_log_sigma_p:\forall n,m,p. O < m \to S O < p \to
463 log p (exp n m) \le sigma_p n (\lambda i.true) (\lambda i. (m / i)).
470 |rewrite > true_to_sigma_p_Sn
471 [apply (trans_le ? (m/n1+(log p (exp n1 m))))