1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "nat/neper.ma".
17 definition C \def \lambda n.pi_p (S n) primeb
18 (\lambda p.match (leb (p*p) n) with
20 | false => S (n/p) ]).
22 theorem asdasd : \forall n. exp n (prim n) \leq (A n)*(C n).
23 intro;unfold prim;rewrite < exp_sigma_p;unfold A;unfold C;rewrite < times_pi_p;
25 apply (bool_elim ? (leb (i*i) n));intro
26 [change in \vdash (? ? (? ? %)) with i;
27 rewrite > sym_times;change in \vdash (? ? %) with (exp i (S (log i n)));
28 apply lt_to_le;apply lt_exp_log;apply prime_to_lt_SO;
29 apply primeb_true_to_prime;assumption
30 |change in \vdash (? ? (? ? %)) with (S (n/i));
32 [rewrite > Hcut;rewrite < exp_n_SO;
33 apply lt_to_le;rewrite > sym_times;apply lt_div_S;apply prime_to_lt_O;
34 apply primeb_true_to_prime;assumption
35 |apply antisymmetric_le
36 [apply le_S_S_to_le;apply not_le_to_lt;intro;
37 apply (leb_false_to_not_le ? ? H2);apply (trans_le ? (exp i (log i n)))
38 [rewrite < exp_SSO;apply le_exp;
40 apply primeb_true_to_prime;assumption
42 |apply le_exp_log;apply (trans_le ? i)
43 [apply prime_to_lt_O;apply primeb_true_to_prime;assumption
44 |apply le_S_S_to_le;assumption]]
45 |apply (trans_le ? (log i i))
48 |apply prime_to_lt_SO;apply primeb_true_to_prime;assumption]
50 [apply prime_to_lt_SO;apply primeb_true_to_prime;assumption
51 |apply le_S_S_to_le;assumption]]]]]
54 definition theta_pi \def
55 \lambda n.pi_p (S n) primeb (\lambda p.p).
58 \lambda n. pi_p (S n) (\lambda x. (primeb x) \land (leb (x*x) n)) (\lambda p.p).
61 \lambda n. pi_p (S n) (\lambda x. (primeb x) \land (leb (S n) (x*x))) (\lambda p.S (n/p)).
64 theorem jj : \forall n.C n = C1 n * C2 n.
65 intro;unfold C;unfold C1;unfold C2;
66 cut (\forall m.pi_p (S n) primeb
68 .match leb (p*p) m in bool return λb:bool.nat with
69 [true⇒p|false⇒S (m/p)])
70 =pi_p (S n) (λx:nat.primeb x∧leb (x*x) m) (λp:nat.p)
71 *pi_p (S n) (λx:nat.primeb x∧leb (S m) (x*x)) (λp:nat.S (m/p)))
75 |intro;apply (bool_elim ? (primeb (S n1)))
76 [intros;rewrite > true_to_pi_p_Sn
77 [apply (bool_elim ? (leb ((S n1)*(S n1)) m))
78 [intro;rewrite > true_to_pi_p_Sn in \vdash (? ? ? (? % ?))
79 [rewrite > false_to_pi_p_Sn in \vdash (? ? ? (? ? %))
80 [rewrite > H1;rewrite > H2;rewrite < assoc_times;reflexivity
81 |rewrite > H;lapply (leb_true_to_le ? ? H2);
82 lapply (le_to_not_lt ? ? Hletin);
83 apply (bool_elim ? (leb (S m) (S n1 * S n1)))
84 [intro;apply False_ind;apply Hletin1;
85 apply leb_true_to_le;assumption
87 |rewrite > H2;rewrite > H;reflexivity]
88 |intro;rewrite > false_to_pi_p_Sn in \vdash (? ? ? (? % ?))
89 [rewrite > true_to_pi_p_Sn in \vdash (? ? ? (? ? %))
90 [rewrite > H1;rewrite < assoc_times;
91 rewrite > sym_times in \vdash (? ? (? % ?) ?);
92 rewrite > assoc_times;reflexivity
94 change in \vdash (? ? % ?) with (leb (S m) (S n1* S n1));
95 apply le_to_leb_true;apply not_le_to_lt;
96 apply leb_false_to_not_le;assumption]
97 |rewrite > H;rewrite > H2;reflexivity]]
99 |intros;rewrite > false_to_pi_p_Sn
100 [rewrite > false_to_pi_p_Sn in \vdash (? ? ? (? % ?))
101 [rewrite > false_to_pi_p_Sn in \vdash (? ? ? (? ? %))
102 [rewrite > H1;reflexivity
103 |rewrite > H;elim (leb (S m) (S n1*S n1));simplify;reflexivity]
104 |rewrite > H;elim (leb (S n1*S n1) m);simplify;reflexivity]
108 theorem log_pi_p : \forall n,b,f,g.S O < b \to
109 log b (pi_p n f g) \leq
110 (sigma_p n f (\lambda x.S O)) + (sigma_p n f (\lambda x.log b (g x))).
112 [simplify;rewrite < times_n_SO;apply (leb_elim b (S O))
113 [intro;elim (lt_to_not_le ? ? H);assumption
114 |intro;simplify;apply le_n]
115 |apply (bool_elim ? (f n1))
116 [intro;rewrite > true_to_pi_p_Sn
117 [rewrite > true_to_sigma_p_Sn
118 [rewrite > true_to_sigma_p_Sn
119 [apply (trans_le ? (S ((log b (g n1)) + (log b (pi_p n1 f g)))))
120 [apply log_times;assumption
121 |rewrite > assoc_plus;
122 change in \vdash (? ? %) with (S (sigma_p n1 f (\lambda x.S O)+(log b (g n1)+sigma_p n1 f (\lambda x.log b (g x)))));
123 apply le_S_S;rewrite < assoc_plus;
124 rewrite > sym_plus in \vdash (? ? (? % ?));
125 rewrite > assoc_plus;apply le_plus;
128 |intro;rewrite > false_to_pi_p_Sn
129 [rewrite > false_to_sigma_p_Sn
130 [rewrite > false_to_sigma_p_Sn]]
134 axiom daemon : False.
136 lemma lt_log_to_lt : \forall b,m,n.S O < b \to log b m < log b n \to m < n.
137 intros;apply not_le_to_lt;intro;elim (le_to_not_lt ? ? (le_log ? ? ? H H2));
141 theorem ababbs: \forall n,a,b.S O < b \to O < n \to n < exp b a \to log b n < a.
142 intros;unfold log;apply not_le_to_lt;intro;apply (lt_to_not_le ? ? H2);
143 elim (le_to_or_lt_eq ? ? H3)
144 [apply lt_to_le;apply (lt_log_to_lt b ? ? H);rewrite > eq_log_exp;assumption
145 |apply (trans_le ? (exp b (log b n)))
146 [rewrite < H4;apply le_n
147 |apply le_exp_log;assumption]]
150 theorem exp_exp_to_log : \forall b,n,k.S O < b \to
151 exp b k \leq n \to n < exp b (S k) \to log b n = k.
152 intros;unfold log;lapply (ababbs ? ? ? H ? H2)
153 [apply (trans_le ? ? ? ? H1);apply lt_O_exp
154 |unfold log in Hletin;lapply (le_to_leb_true ? ? H1);
155 lapply (f_m_to_le_max (λx:nat.leb ((b)\sup(x)) n) n ? ? Hletin1)
157 elim (le_to_or_lt_eq ? ? (le_S_S_to_le ? ? Hletin))
162 theorem xxx_log : \forall a,b.S O < b \to O < a \to log b (b*a) = S (log b a).
164 [elim (not_le_Sn_O ? H1);
169 theorem le_log_C2_sigma_p : \forall n,b. S O < b \to
171 (sigma_p (S n) (\lambda x.(primeb x) \land (leb (S n) (x*x))) (\lambda x.S O)) +
172 (prim n + (((sigma_p n (\lambda x.leb (S n) (x*x)) (\lambda i.prim i * S (n!/i)))
173 *(S (log b 3)))/n!)).
175 apply (trans_le ? (sigma_p (S n) (λx:nat.primeb x∧leb (S n) (x*x)) (λx:nat.1)
176 +sigma_p (S n) (λx:nat.primeb x∧leb (S n) (x*x))
177 (λi.log b (S (n/i)))))
178 [apply log_pi_p;assumption
181 |apply (trans_le ? (sigma_p (S n) (λx:nat.primeb x∧leb (S n) (x*x)) (λi:nat.S (log b (n/i)))))
182 [apply le_sigma_p;intros;cut (log b (b*(n/i)) = S (log b (n/i)))
183 [rewrite < Hcut;apply le_log
186 [rewrite < times_SSO_n;change in \vdash (? % ?) with (S O + (n/i));
188 [apply le_times_to_le_div
189 [apply (prime_to_lt_O i (primeb_true_to_prime ? (andb_true_true ? ? H2)));
190 |rewrite < times_n_SO;apply le_S_S_to_le;assumption]
192 |apply (trans_le ? ? ? H4);apply le_times_l;apply le_S;apply le_n]]
193 |rewrite > exp_n_SO in ⊢ (? ? (? ? (? % ?)) ?);
197 |apply le_times_to_le_div;
198 [apply (prime_to_lt_O i (primeb_true_to_prime ? (andb_true_true ? ? H2)));
199 |rewrite < times_n_SO;apply le_S_S_to_le;assumption]]]
200 |change in ⊢ (? (? ? ? (λi:?.%)) ?) with ((S O) + (log b (n/i)));
201 rewrite > (sigma_p_plus_1 ? (\lambda x.S O));
203 [unfold prim;apply le_sigma_p1;intros;elim (leb (S n) (i*i));
204 [rewrite > andb_sym;apply le_n
205 |rewrite > andb_sym;apply le_O_n]
206 |apply sigma_p_log_div;assumption]]]]
209 lemma le_prim_n_stima : \forall n,b. S O < b \to b \leq n \to
210 prim n \leq (S (((S (S (S (S O))))*(S (log b (pred n)))) +
211 ((S (S (S (S O))))*n)))/(log b n).
212 (* la stima del secondo addendo è ottenuta considerando che
213 logreale 2 è sempre <= 1 (si dimostra per casi: b = 2, b > 2) *)
214 intros;apply le_times_to_le_div;
216 [apply (trans_le ? b)
217 [apply lt_to_le;assumption
220 |apply (trans_le ? (log b (exp n (prim n))))
221 [rewrite > sym_times;apply log_exp2
223 |apply (trans_le ? b ? ? H1);apply lt_to_le;assumption]
224 |apply (trans_le ? (log b ((exp (pred n) (S (S (S (S O)))))
225 *(exp (S (S O)) ((S (S (S (S O))))*n)))))
228 |apply le_exp_primr;apply (trans_le ? ? ? H H1)]
229 |apply (trans_le ? (S ((log b (exp (pred n) (S (S (S (S O)))))) +
230 (log b (exp (S (S O)) ((S (S (S (S O))))*n))))))
231 [apply log_times;assumption
232 |apply le_S_S;apply le_plus
233 [apply log_exp1;assumption
235 [rewrite > times_n_SO in \vdash (? (? ? %) ?);
237 [rewrite < plus_n_O;apply le_n
240 |apply (trans_le ? (((S (S (S (S O))))*n)*(S (log (S m) (S (S O))))))
241 [apply log_exp1;apply le_S;assumption
242 |rewrite > times_n_SO in \vdash (? ? %);
243 apply le_times_r;apply le_S_S;
244 rewrite > lt_to_log_O
247 |apply le_S_S;assumption]]]]]]]]
250 theorem le_log_C2_stima : \forall n,b. S O < b \to b*b < n \to
252 (*(sigma_p (S n) (\lambda x.(primeb x) \land (leb (S n) (x*x))) (\lambda x.S O)) +*)
253 ((S (((S (S (S (S O))))*(S (log b (pred n)))) +
254 ((S (S (S (S O))))*n)))/(log b n)) +
255 (((S (((S (S (S (S O))))*(S (log b (pred n)))) +
256 ((S (S (S (S O))))*n)))/(log b n)) +
257 (((sigma_p n (\lambda x.leb (S n) (x*x))
258 (\lambda i.((S (((S (S (S (S O))))*(S (log b (pred i)))) +
259 ((S (S (S (S O))))*i)))/(log b i))* S (n!/i)))
260 *(S (log b (S (S (S O))))))/n!)).intros.
261 apply (trans_le ? ? ? (le_log_C2_sigma_p ? ? ?))
264 [apply (trans_le ? ? ? ? (le_prim_n_stima ? ? ? ?));
265 [unfold prim;apply le_sigma_p1;intros;
266 do 2 rewrite < times_n_SO;elim (primeb i)
267 [elim (leb (S n) (i*i));simplify [apply le_n|apply le_O_n]
268 |simplify;apply le_n]
270 |apply (trans_le ? ? ? ? H1);apply le_S;apply le_times_n;
271 apply lt_to_le;assumption]
273 [apply le_prim_n_stima;
275 |apply (trans_le ? (b*b))
276 [apply le_times_n;apply lt_to_le;assumption
277 |apply lt_to_le;assumption]]
280 |apply le_times_l;apply le_sigma_p;intros;apply le_times_l;
281 apply le_prim_n_stima
283 |apply (le_exp_to_le1 ? ? (S (S O)));
284 [apply le_S;apply le_n
285 |do 2 rewrite > exp_SSO;apply (trans_le ? n)
286 [apply lt_to_le;assumption
287 |apply lt_to_le;apply leb_true_to_le;assumption]]]]]]]
290 lemma log_interval : \forall b,k,n. S O < b \to exp b k \leq n \to n < exp b (S k) \to
293 [simplify in H2;rewrite < times_n_SO in H2;apply lt_to_log_O;assumption
294 |cut (log b n1 < S (S n))
296 [apply antisymmetric_le
297 [apply le_S_S_to_le;assumption
299 |apply (trans_le ? (log b (exp b (S n))))
300 [rewrite > eq_log_exp
303 |apply le_log;assumption]]
304 |apply le_S_S;apply (trans_le ? (log b (pred (exp b (S (S n))))))
307 |apply le_S_S_to_le;apply (trans_le ? ? ? H3);
308 rewrite > minus_n_O in \vdash (? ? (? (? %)));
309 rewrite < (eq_minus_S_pred (exp b (S (S n))) O);
310 rewrite > minus_n_O in \vdash (? % ?);
311 apply minus_le_S_minus_S]
312 |unfold log;apply f_false_to_le_max;
313 [apply (ex_intro ? ? (S n));split
314 [apply (trans_le ? (exp b (S n)));
315 [apply lt_to_le;apply lt_m_exp_nm;assumption
316 |rewrite > minus_n_O in ⊢ (? ? (? %));
317 rewrite < eq_minus_S_pred;apply le_plus_to_minus_r;
319 change in \vdash (? % ?) with (S (O + exp b (S n)));
320 apply lt_minus_to_plus;
321 change in ⊢ (? ? (? % ?)) with (b * (exp b (S n)));
322 rewrite > times_n_SO in \vdash (? ? (? ? %));
323 rewrite > sym_times in \vdash (? ? (? % ?));
324 rewrite < distributive_times_minus;unfold lt;
325 rewrite > times_n_SO in \vdash (? % ?);apply le_times
326 [apply lt_O_exp;apply (trans_le ? ? ? ? H1);
327 apply le_S;apply le_n
328 |apply le_plus_to_minus_r;simplify;assumption]]
329 |apply le_to_leb_true;
330 rewrite > minus_n_O in \vdash (? ? (? %));
331 rewrite < eq_minus_S_pred;apply le_plus_to_minus_r;
332 rewrite > sym_plus;change in \vdash (? % ?) with (S (exp b (S n)));
336 |intros;apply lt_to_leb_false;unfold lt;
337 rewrite > minus_n_O in \vdash (? (? (? %)) ?);
338 rewrite < eq_minus_S_pred;rewrite < minus_Sn_m
339 [rewrite > minus_S_S;rewrite < minus_n_O;apply le_exp;
340 [apply (trans_le ? ? ? ? H1);apply le_S;apply le_n
342 |apply lt_O_exp;apply (trans_le ? ? ? ? H1);apply le_S;apply le_n]]]]]
345 lemma log_strano : \forall b,i.S O < b \to S O < i \to
346 ((S (S (S (S O)))) * log b (pred i)) + (S (S (S (S (S O))))) \leq
348 alias num (instance 0) = "natural number".
349 cut (\forall b,i,k.S O < b \to S O < i \to
350 (exp b k) \leq i-1 \to i-1 < (exp b (S k)) \to
351 ((S (S (S (S O)))) * log b (pred i)) + (S (S (S (S (S O))))) \leq
353 [intros;apply (Hcut ? ? (log b (i-1)) H H1);
354 [apply le_exp_log;rewrite > (minus_n_n 1) in \vdash (? % ?);
355 apply lt_plus_to_lt_minus;
357 |rewrite < eq_minus_plus_plus_minus
358 [rewrite > sym_plus;rewrite > eq_minus_plus_plus_minus;
359 [rewrite < minus_n_n;rewrite < plus_n_O;assumption
361 |apply lt_to_le;assumption]]
362 |apply lt_exp_log;assumption]
363 |intros;rewrite > minus_n_O in ⊢ (? (? (? ? (? ? (? %))) ?) ?);
364 rewrite < eq_minus_S_pred;rewrite > (log_interval ? k)
365 [apply (trans_le ? (3*(exp b k) + 3))
366 [change in \vdash (? (? ? %) ?) with (2+3);
367 rewrite < assoc_plus;apply le_plus_l;
369 [simplify;apply le_S;apply le_n
370 |elim (decidable_eq_nat O n)
371 [rewrite < H5;apply (trans_le ? (3*(exp 2 1)));
373 |apply le_times_r;apply monotonic_exp1;assumption]
374 |rewrite < times_n_Sm;apply (trans_le ? (3*(exp b n) + 4))
375 [rewrite > assoc_plus;rewrite > sym_plus;apply le_plus_l;
377 |rewrite < sym_plus;change in \vdash (? % ?) with (S (3 + (3*(exp b n))));
378 apply lt_minus_to_plus;
379 change in ⊢ (? ? (? (? ? %) ?)) with (b*(exp b n));
380 rewrite > sym_times in \vdash (? ? (? (? ? %) ?));
381 rewrite < assoc_times;
382 rewrite > times_n_SO in ⊢ (? ? (? ? (? ? %)));
383 rewrite < assoc_times;rewrite < distr_times_minus;
384 apply (trans_le ? (3*2*1))
385 [simplify;apply le_S;apply le_S;apply le_n
387 [apply le_times_r;apply (trans_le ? (exp 2 n))
388 [rewrite > exp_n_SO in \vdash (? % ?);apply le_exp
389 [apply le_S;apply le_n
390 |generalize in match H5;cases n
391 [intro;elim H6;reflexivity
392 |intro;apply le_S_S;apply le_O_n]]
393 |apply monotonic_exp1;assumption]
394 |apply le_S_S_to_le;rewrite < minus_Sn_m;
395 [simplify;rewrite < minus_n_O;assumption
396 |apply lt_to_le;assumption]]]]]]
397 |rewrite > times_n_SO in \vdash (? (? ? %) ?);
398 rewrite < distr_times_plus;apply le_times_r;
399 rewrite < plus_n_SO;apply (trans_le ? (S (i-1)))
400 [apply le_S_S;assumption
401 |rewrite < minus_Sn_m
402 [simplify;rewrite < minus_n_O;apply le_n
403 |apply lt_to_le;assumption]]]
409 lemma eq_div_div_times : \forall x,y,z.O < z \to O < y \to x/y = (z*x)/(z*y).
410 intros.rewrite > (div_mod x y) in \vdash (? ? ? %);
411 [rewrite > distr_times_plus;rewrite > sym_times;rewrite > assoc_times;
412 rewrite > sym_times in ⊢ (? ? ? (? (? (? ? %) ?) ?));
413 rewrite > div_plus_times
415 |generalize in match H;cases z;intros
416 [elim (not_le_Sn_O ? H2)
417 |apply lt_times_r;apply lt_mod_m_m;assumption]]
421 alias num (instance 0) = "natural number".
422 lemma le_sigma_p_lemma1 : \forall n,b. S O < b \to b*b < n \to
423 (sigma_p n (\lambda x.leb (S n) (x*x))
424 (\lambda i.((S (((S (S (S (S O))))*(S (log b (pred i)))) +
425 ((S (S (S (S O))))*i)))/(log b i))* S (n!/i)))
426 \leq ((28 * n * n!)/(pred (log b n))).
427 intros.apply (trans_le ? (sigma_p n (\lambda x.leb (S n) (x*x)) (\lambda i. ((7*i)/(log b i))*(S (n!/i)))))
428 [apply le_sigma_p;intros;cut (b \leq i)
429 [cut (1 < i) [|apply (trans_le ? ? ? H Hcut)]
430 apply le_times_l;apply monotonic_div
432 [generalize in match H3;cases i
433 [simplify;intros;destruct H4
434 |intro;apply le_S_S;apply le_O_n]
436 |rewrite > sym_times;simplify in ⊢ (? (? (? % ?)) ?);
437 change in ⊢ (? % ?) with (1 + ((4 + (log b (pred i) * 4)) + 4*i));
438 rewrite > assoc_plus;rewrite < assoc_plus;
439 simplify in \vdash (? (? % ?) ?);rewrite < assoc_plus;
440 apply (trans_le ? (3*i + 4*i))
441 [apply le_minus_to_plus;rewrite > eq_minus_plus_plus_minus
442 [rewrite < minus_n_n;rewrite < plus_n_O;
443 rewrite > sym_plus;rewrite > sym_times;apply log_strano
445 |lapply (leb_true_to_le ? ? H3);apply (trans_le ? ? ? H);
446 apply (le_exp_to_le1 ? ? 2);
447 [apply le_S_S;apply le_O_n
448 |apply lt_to_le;do 2 rewrite > exp_SSO;apply (trans_le ? ? ? H1);
449 apply lt_to_le;assumption]]
451 |rewrite > sym_times in \vdash (? (? % ?) ?);
452 rewrite > sym_times in \vdash (? (? ? %) ?);
453 rewrite < distr_times_plus;rewrite > sym_times;apply le_n]]
454 |apply (le_exp_to_le1 ? ? 2);
455 [apply le_S_S;apply le_O_n
456 |apply lt_to_le;do 2 rewrite > exp_SSO;apply (trans_le ? ? ? H1);
457 apply (trans_le ? ? ? ? (leb_true_to_le ? ? H3));apply le_S;
459 |apply (trans_le ? (sigma_p n (λx:nat.leb (S n) (x*x)) (λi:nat.7*i/log b i*((2*(n!))/i))))
460 [apply le_sigma_p;intros;apply le_times_r;apply (trans_le ? (n!/i + n!/i))
461 [change in \vdash (? % ?) with (1 + n!/i);apply le_plus_l;
462 apply le_times_to_le_div
463 [generalize in match H3;cases i;simplify;intro
465 |apply le_S_S;apply le_O_n]
466 |generalize in match H2;cases n;intro
467 [elim (not_le_Sn_O ? H4)
468 |change in \vdash (? ? %) with ((S n1)*(n1!));apply le_times
469 [apply lt_to_le;assumption
471 |rewrite > plus_n_O in \vdash (? (? ? %) ?);
472 change in \vdash (? % ?) with (2 * (n!/i));
473 apply le_times_div_div_times;
474 generalize in match H3;cases i;simplify;intro
476 |apply le_S_S;apply le_O_n]]
477 |apply (trans_le ? (sigma_p n (\lambda x:nat.leb (S n) (x*x)) (\lambda i.((14*(n!))/log b i))))
478 [apply le_sigma_p;intros;
480 [|apply (le_exp_to_le1 ? ? 2);
481 [apply le_S_S;apply le_O_n
482 |apply lt_to_le;do 2 rewrite > exp_SSO;apply (trans_le ? ? ? H1);
483 apply (trans_le ? ? ? ? (leb_true_to_le ? ? H3));apply le_S;
486 [|apply (trans_le ? ? ? H Hcut)]
487 change in ⊢ (? ? (? % ?)) with ((7*2)*(n!));
488 rewrite > assoc_times in \vdash (? ? (? % ?));
489 apply (trans_le ? ? ? (le_times_div_div_times ? ? ? ?));
490 [apply lt_to_le;assumption
491 |rewrite > (eq_div_div_times ? ? 7)
492 [rewrite > sym_times in ⊢ (? (? (? ? %) ?) ?);
493 rewrite < assoc_times in \vdash (? (? % ?) ?);
494 apply (trans_le ? ? ? (le_div_times_m ? ? ? ? ?))
496 [apply lt_to_le;assumption
498 |unfold lt;rewrite > times_n_SO in \vdash (? % ?);
500 [apply le_S_S;apply le_O_n
501 |apply lt_to_le;assumption]
503 |apply le_S_S;apply le_O_n
504 |apply lt_to_le;assumption]]
505 |apply (trans_le ? (sigma_p (S n) (\lambda x.leb (S n) (x*x))
506 (\lambda i.14*n!/log b i)))
507 [apply (bool_elim ? (leb (S n) (n*n)));intro
508 [rewrite > true_to_sigma_p_Sn
509 [rewrite > sym_plus;rewrite > plus_n_O in \vdash (? % ?);
510 apply le_plus_r;apply le_O_n
512 |rewrite > false_to_sigma_p_Sn
515 |apply (trans_le ? ? ? (le_sigma_p_div_log_div_pred_log ? ? ? ? ?));
517 |apply lt_to_le;assumption
518 |rewrite < assoc_times;
519 rewrite > sym_times in ⊢ (? (? (? % ?) ?) ?);
520 rewrite < assoc_times;apply le_n]]]]]
523 theorem le_log_C2_stima2 : \forall n,b. S O < b \to b*b < n \to
526 ((((28*n*n!)/pred (log b n))
527 *(S (log b (S (S (S O))))))/n!).intros.
528 apply (trans_le ? ? ? (le_log_C2_stima ? ? H H1));
529 rewrite < assoc_plus in \vdash (? % ?);apply le_plus
530 [rewrite > times_SSO_n in \vdash (? % ?);
531 apply (trans_le ? ? ? (le_times_div_div_times ? ? ? ?))
533 [apply (trans_le ? (b*b))
534 [rewrite > times_n_SO;apply le_times;apply lt_to_le;assumption
535 |apply lt_to_le;assumption]
536 |apply (trans_le ? (b*b))
537 [rewrite > times_n_SO in \vdash (? % ?);apply le_times
538 [apply le_n|apply lt_to_le;assumption]
539 |apply lt_to_le;assumption]]
540 |change in \vdash (? ? (? (? % ?) ?)) with (2*7);
543 [apply (trans_le ? (b*b))
544 [rewrite > times_n_SO;apply le_times;apply lt_to_le;assumption
545 |apply lt_to_le;assumption]
546 |apply (trans_le ? (b*b))
547 [rewrite > times_n_SO in \vdash (? % ?);apply le_times
548 [apply le_n|apply lt_to_le;assumption]
549 |apply lt_to_le;assumption]]
550 |rewrite > assoc_times;apply le_times_r;
551 change in \vdash (? (? (? (? ? %) ?)) ?) with (1 + (log b (pred n)));
552 rewrite > distr_times_plus;
553 change in \vdash (? % ?) with (1 + (4*1+4*log b (pred n)+4*n));
554 do 2 rewrite < assoc_plus;simplify in ⊢ (? (? (? % ?) ?) ?);
555 change in ⊢ (? ? %) with ((3+4)*n);rewrite > sym_times in \vdash (? ? %);
556 rewrite > distr_times_plus;
557 rewrite > sym_times in \vdash (? ? (? % ?));
558 rewrite > sym_times in \vdash (? ? (? ? %));
559 apply le_plus_l;rewrite > sym_plus;apply log_strano
561 |apply (trans_le ? ? ? H);apply (trans_le ? (b*b))
562 [rewrite > times_n_SO in \vdash (? % ?);
563 apply le_times_r;apply lt_to_le;assumption
564 |apply lt_to_le;assumption]]]]
567 |apply le_times_l;apply (le_sigma_p_lemma1 ? ? H H1)]]
570 theorem le_log_C2_stima3 : \forall n,b. S O < b \to b*b < n \to
573 ((28*n)*(S (log b (S (S (S O)))))/pred (log b n)).intros.
574 apply (trans_le ? ? ? (le_log_C2_stima2 ? ? H H1));apply le_plus_r;
575 (*apply (trans_le ? ((28*n)*(28*n*n!/pred (log b n)*S (log b 3)/(28*n*n!))))
577 rewrite > (eq_div_div_times ? ? (28*n)) in \vdash (? % ?)
578 [rewrite > sym_times in ⊢ (? (? (? ? %) ?) ?);
579 rewrite < assoc_times;
580 apply le_div_times_m;
581 [apply (trans_le ? (pred (log b (b*b))))
582 [rewrite < exp_SSO;rewrite > eq_log_exp;
585 |rewrite < exp_SSO;rewrite > eq_log_exp;
586 [simplify;rewrite > minus_n_O in \vdash (? ? (? %));
587 rewrite < eq_minus_S_pred;
588 apply le_plus_to_minus_r;simplify;
589 rewrite < (eq_log_exp b 2);
592 |rewrite > exp_SSO;apply lt_to_le;assumption]
595 |unfold lt;rewrite > times_n_SO in \vdash (? % ?);apply le_times
596 [rewrite > times_n_SO in \vdash (? % ?);apply le_times
597 [apply le_S_S;apply le_O_n
598 |apply (trans_le ? ? ? ? H1);apply le_S_S;
599 rewrite > times_n_SO;apply le_times
601 |apply lt_to_le;assumption]]
603 |unfold lt;rewrite > times_n_SO in \vdash (? % ?);apply le_times
604 [apply le_S_S;apply le_O_n
605 |apply (trans_le ? ? ? ? H1);apply le_S_S;
606 rewrite > times_n_SO;apply le_times
608 |apply lt_to_le;assumption]]
612 lemma le_prim_log1: \forall n,b. S O < b \to O < n \to
613 (prim n)*(log b n) \leq
614 log b (A n) + log b (C1 n) + log b (C2 n) + 2.
615 intros.change in \vdash (? ? (? ? %)) with (1+1).
616 rewrite < assoc_plus;rewrite > assoc_plus in ⊢ (? ? (? (? % ?) ?)).
617 rewrite > assoc_plus in ⊢ (? ? (? % ?));
618 apply (trans_le ? (log b (A n) + (log b (C1 n * C2 n)) + 1));
619 [apply (trans_le ? (log b (A n * (C1 n * C2 n))))
620 [apply (trans_le ? (log b (exp n (prim n))))
621 [apply log_exp2;assumption
624 |rewrite < jj;apply asdasd]]
625 |rewrite > sym_plus;simplify;apply log_times;assumption]
626 |apply le_plus_l;apply le_plus_r;rewrite > sym_plus;simplify;apply log_times;
630 lemma le_log_A1 : \forall n,b. S O < b \to S O < n \to
631 log b (A n) \leq 2*(S (log b (pred n))) + (2*(pred n))*(S (log b 2)) + 1.
632 intros.apply (trans_le ? (log b ((exp (pred n) 2)*(exp 2 (2*(pred n))))))
635 |simplify in ⊢ (? ? (? (? % ?) ?));apply le_A_exp4;assumption]
636 |rewrite < sym_plus;apply (trans_le ? (1 + ((log b (exp (pred n) 2)) + (log b (exp 2 (2*(pred n)))))));
637 [change in \vdash (? ? %) with (S (log b ((pred n)\sup(2))+log b ((2)\sup(2*(pred n)))));
638 apply log_times;assumption
639 |apply le_plus_r;apply le_plus;apply log_exp1;assumption]]
642 lemma le_theta_pi_A : \forall n.theta_pi n \leq A n.
643 intro.unfold theta_pi.unfold A.apply le_pi_p.intros.
644 rewrite > exp_n_SO in \vdash (? % ?).
649 [apply (trans_le ? ? ? Hcut);apply le_S_S_to_le;assumption
650 |apply le_S_S_to_le;assumption]]
651 |apply prime_to_lt_O;apply primeb_true_to_prime;assumption]
655 \lambda n.max n (\lambda x.leb (x*x) n).
657 theorem le_sqrt_to_le_times_l : \forall m,n.n \leq sqrt m \to n*n \leq m.
658 intros;apply (trans_le ? (sqrt m * sqrt m))
659 [apply le_times;assumption
660 |apply leb_true_to_le;apply (f_max_true (λx:nat.leb (x*x) m) m);
661 apply (ex_intro ? ? O);split
663 |simplify;reflexivity]]
666 theorem lt_sqrt_to_le_times_l : \forall m,n.n < sqrt m \to n*n < m.
667 intros;apply (trans_le ? (sqrt m * sqrt m))
668 [apply (trans_le ? (S n * S n))
669 [simplify in \vdash (? ? %);apply le_S_S;apply (trans_le ? (n * S n))
670 [apply le_times_r;apply le_S;apply le_n
671 |rewrite > sym_plus;rewrite > plus_n_O in \vdash (? % ?);
672 apply le_plus_r;apply le_O_n]
673 |apply le_times;assumption]
674 |apply le_sqrt_to_le_times_l;apply le_n]
677 theorem le_sqrt_to_le_times_r : \forall m,n.sqrt m < n \to m < n*n.
678 intros;apply not_le_to_lt;intro;
679 apply ((leb_false_to_not_le ? ?
680 (lt_max_to_false (\lambda x.leb (x*x) m) m n H ?))
682 apply (trans_le ? ? ? ? H1);cases n
684 |rewrite > times_n_SO in \vdash (? % ?);rewrite > sym_times;apply le_times
685 [apply le_S_S;apply le_O_n
689 theorem eq_theta_pi_sqrt_C1 : \forall n. theta_pi (sqrt n) = C1 n.
690 intro;unfold theta_pi;unfold C1;rewrite > (false_to_eq_pi_p (S (sqrt n)) (S n))
691 [generalize in match (le_sqrt_to_le_times_l n);elim (sqrt n)
692 [simplify;reflexivity
693 |apply (bool_elim ? (primeb (S n1)))
694 [intro;rewrite > true_to_pi_p_Sn
695 [rewrite > true_to_pi_p_Sn in \vdash (? ? ? %)
698 |apply H;intros;apply H1;apply le_S;assumption]
699 |apply (andb_elim (primeb (S n1)) (leb (S n1 * S n1) n));
700 rewrite > H2;whd;apply le_to_leb_true;apply H1;apply le_n]
702 |intro;rewrite > false_to_pi_p_Sn
703 [rewrite > false_to_pi_p_Sn in \vdash (? ? ? %)
704 [apply H;intros;apply H1;apply le_S;assumption
705 |apply (andb_elim (primeb (S n1)) (leb (S n1 * S n1) n));
706 rewrite > H2;whd;reflexivity]
708 |apply le_S_S;unfold sqrt;apply le_max_n
709 |intros;apply (andb_elim (primeb i) (leb (i*i) n));elim (primeb i);simplify
710 [rewrite > lt_to_leb_false
712 |apply le_sqrt_to_le_times_r;assumption]
716 lemma le_sqrt_n_n : \forall n.sqrt n \leq n.
717 intro.unfold sqrt.apply le_max_n.
720 lemma le_prim_log_stima: \forall n,b. S O < b \to b < sqrt n \to
721 (prim n)*(log b n) \leq
722 2*S (log b (pred n))+2*(pred n)*S (log b 2)
723 +(2*S (log b (pred (sqrt n)))+2*(pred (sqrt n))*S (log b 2))
724 +(14*n/log b n+28*n*S (log b 3)/pred (log b n))
727 [apply (trans_le ? ((2*(S (log b (pred n))) + (2*(pred n))*(S (log b 2)) + 1) +
728 (2*(S (log b (pred (sqrt n)))) + (2*(pred (sqrt n)))*(S (log b 2)) + 1) +
729 ((14*n/(log b n)) + ((28*n)*(S (log b (S (S (S O)))))/pred (log b n))) + 2))
730 [apply (trans_le ? ? ? (le_prim_log1 ? ? H ?))
731 [apply lt_to_le;assumption
732 |apply le_plus_l;apply le_plus
734 [apply le_log_A1;assumption
735 |rewrite < eq_theta_pi_sqrt_C1;apply (trans_le ? (log b (A (sqrt n))))
738 |apply le_theta_pi_A]
741 |apply (trans_le ? ? ? H);apply lt_to_le;assumption]]]
742 |apply le_log_C2_stima3;
744 |apply lt_sqrt_to_le_times_l;assumption]]]
745 |rewrite > assoc_plus in ⊢ (? (? % ?) ?);
746 rewrite > sym_plus in ⊢ (? (? (? ? %) ?) ?);
747 rewrite > assoc_plus in \vdash (? % ?);
748 rewrite > assoc_plus in ⊢ (? (? ? %) ?);
749 rewrite > assoc_plus in ⊢ (? (? % ?) ?);
750 rewrite > assoc_plus in \vdash (? % ?);
751 rewrite < assoc_plus in ⊢ (? (? ? %) ?);
752 rewrite > assoc_plus in ⊢ (? (? ? (? % ?)) ?);
753 rewrite > sym_plus in ⊢ (? (? ? (? (? ? %) ?)) ?);
754 rewrite < assoc_plus in ⊢ (? (? ? (? % ?)) ?);
755 rewrite < assoc_plus in \vdash (? % ?);
756 rewrite < assoc_plus in ⊢ (? (? % ?) ?);
757 rewrite > assoc_plus in \vdash (? % ?);
758 rewrite > sym_plus in ⊢ (? (? ? %) ?);
759 rewrite > assoc_plus in ⊢ (? (? ? %) ?);
760 rewrite > assoc_plus in ⊢ (? (? ? (? % ?)) ?);
761 rewrite > assoc_plus in ⊢ (? (? ? %) ?);
762 rewrite > assoc_plus in ⊢ (? (? ? (? ? %)) ?);
763 simplify in ⊢ (? (? ? (? ? (? ? %))) ?);
764 rewrite < assoc_plus in ⊢ (? (? ? %) ?);
765 rewrite < assoc_plus in ⊢ (? % ?);apply le_plus_l;
766 rewrite > assoc_plus in \vdash (? % ?);
767 rewrite > assoc_plus in ⊢ (? (? ? %) ?);
768 rewrite > sym_plus in ⊢ (? (? ? (? ? %)) ?);
769 rewrite < assoc_plus in ⊢ (? (? ? %) ?);
770 rewrite < assoc_plus in \vdash (? % ?);apply le_plus_l;
771 rewrite > assoc_plus in \vdash (? ? %);apply le_n]
772 |apply (trans_le ? ? ? H);apply lt_to_le;apply (trans_le ? ? ? H1);
776 lemma eq_div_div_div_times: \forall a,b,c. O < b \to O < c \to a/b/c = a/(b*c).
777 intros.rewrite > (div_mod a (b*c)) in \vdash (? ? % ?)
778 [rewrite > (div_mod (a \mod (b*c)) b)
779 [rewrite < assoc_plus;
780 rewrite > sym_times in ⊢ (? ? (? (? (? (? (? ? %) ?) ?) ?) ?) ?);
781 rewrite < assoc_times in ⊢ (? ? (? (? (? (? % ?) ?) ?) ?) ?);
782 rewrite > sym_times in ⊢ (? ? (? (? (? (? % ?) ?) ?) ?) ?);
783 rewrite > sym_times in ⊢ (? ? (? (? (? (? ? %) ?) ?) ?) ?);
784 rewrite < distr_times_plus;rewrite < sym_times in ⊢ (? ? (? (? (? % ?) ?) ?) ?);
785 rewrite > (div_plus_times b)
786 [rewrite > (div_plus_times c)
788 |apply lt_times_to_lt_div;rewrite > sym_times in \vdash (? ? %);
789 apply lt_mod_m_m;unfold lt;rewrite > times_n_SO;apply le_times;assumption]
790 |apply lt_mod_m_m;assumption]
792 |unfold lt;rewrite > times_n_SO;apply le_times;assumption]
795 lemma le_prim_stima: \forall n,b. S O < b \to b < sqrt n \to
797 2*S (log b (pred n))/(log b n) + 2*(pred n)*S (log b 2)/(log b n)
798 +2*S (log b (pred (sqrt n)))/(log b n)+ 2*(pred (sqrt n))*S (log b 2)/(log b n)
799 + 14*n/(log b n * log b n) + 28*n*S (log b 3)/(pred (log b n) * log b n)
804 [apply lt_to_le;apply (trans_le ? ? ? H);apply (trans_le ? (sqrt n))
805 [apply lt_to_le;assumption
807 |apply (trans_le ? (sqrt n))
808 [apply lt_to_le;assumption
809 |apply le_sqrt_n_n]]]
810 apply (trans_le ? ((2*S (log b (pred n))+2*(pred n)*S (log b 2)
811 +(2*S (log b (pred (sqrt n)))+2*(pred (sqrt n))*S (log b 2))
812 +(14*n/log b n+28*n*S (log b 3)/pred (log b n))
814 [apply le_times_to_le_div
816 |rewrite > sym_times;apply le_prim_log_stima;assumption]
817 |apply (trans_le ? ? ? (le_div_plus_S (2*S (log b (pred n))+2*(pred n)*S (log b 2)
818 +(2*S (log b (pred (sqrt n)))+2*(pred (sqrt n))*S (log b 2))
819 +(14*n/log b n+28*n*S (log b 3)/pred (log b n))) 4 (log b n) ?))
821 |rewrite < plus_n_Sm;apply le_S_S;rewrite > assoc_plus in \vdash (? ? %);
822 rewrite > sym_plus in \vdash (? ? (? ? %));
823 rewrite < assoc_plus in \vdash (? ? %);
824 apply le_plus_l;apply (trans_le ? ? ? (le_div_plus_S (2*S (log b (pred n))+2*(pred n)*S (log b 2)
825 +(2*S (log b (pred (sqrt n)))+2*(pred (sqrt n))*S (log b 2))) (14*n/log b n+28*n*S (log b 3)/pred (log b n)) (log b n) ?));
827 |rewrite < plus_n_Sm in \vdash (? ? %);apply le_S_S;
828 change in \vdash (? ? (? ? %)) with (1+3);
829 rewrite < assoc_plus in \vdash (? ? %);
830 rewrite > assoc_plus in ⊢ (? ? (? (? % ?) ?));
831 rewrite > assoc_plus in ⊢ (? ? (? % ?));
832 rewrite > sym_plus in \vdash (? ? %);rewrite < assoc_plus in \vdash (? ? %);
833 rewrite > sym_plus in \vdash (? ? (? % ?));apply le_plus
834 [apply (trans_le ? ? ? (le_div_plus_S (2*S (log b (pred n))+2*pred n*S (log b 2)) (2*S (log b (pred (sqrt n)))+2*pred (sqrt n)*S (log b 2)) (log b n) ?))
836 |rewrite < plus_n_Sm;apply le_S_S;change in \vdash (? ? (? ? %)) with (1+1);
837 rewrite < assoc_plus in \vdash (? ? %);rewrite > assoc_plus in ⊢ (? ? (? (? % ?) ?));
838 rewrite > assoc_plus in ⊢ (? ? (? % ?));
839 rewrite > sym_plus in \vdash (? ? %);
840 rewrite < assoc_plus in \vdash (? ? %);
841 rewrite > sym_plus in \vdash (? ? (? % ?));
843 [rewrite < plus_n_Sm;rewrite < plus_n_O;apply le_div_plus_S;
845 |rewrite < plus_n_Sm;rewrite < plus_n_O;apply le_div_plus_S;
847 |rewrite < plus_n_Sm;rewrite < plus_n_O;apply (trans_le ? ? ? (le_div_plus_S ? ? ? ?));
849 |apply le_S_S;apply le_plus
850 [rewrite > eq_div_div_div_times;
853 |rewrite > eq_div_div_div_times
855 |rewrite > minus_n_O in \vdash (? ? (? %));
856 rewrite < eq_minus_S_pred;apply lt_to_lt_O_minus;
857 apply (trans_le ? (log b (sqrt n * sqrt n)))
865 lemma leq_sqrt_n : \forall n. sqrt n * sqrt n \leq n.
866 intro;unfold sqrt;apply leb_true_to_le;apply f_max_true;apply (ex_intro ? ? O);
869 |simplify;reflexivity]
872 lemma le_sqrt_log_n : \forall n,b. 2 < b \to sqrt n * log b n \leq n.
874 apply (trans_le ? ? ? ? (leq_sqrt_n ?));
875 apply le_times_r;unfold sqrt;
877 [apply le_log_n_n;apply lt_to_le;assumption
878 |apply le_to_leb_true;elim (le_to_or_lt_eq ? ? (le_O_n n))
879 [apply (trans_le ? (exp b (log b n)))
882 |simplify in \vdash (? ? %);
883 elim (le_to_or_lt_eq ? ? (le_O_n n1))
884 [elim (le_to_or_lt_eq ? ? H3)
885 [apply (trans_le ? (3*(n1*n1)));
886 [simplify in \vdash (? % ?);rewrite > sym_times in \vdash (? % ?);
887 simplify in \vdash (? % ?);
888 simplify;rewrite > sym_plus;
889 rewrite > plus_n_Sm;rewrite > sym_plus in \vdash (? (? % ?) ?);
890 rewrite > assoc_plus;apply le_plus_r;
893 apply lt_plus;rewrite > times_n_SO in \vdash (? % ?);
894 apply lt_times_r1;assumption;
898 |rewrite < H4;apply le_times
899 [apply lt_to_le;assumption
900 |apply lt_to_le;simplify;rewrite < times_n_SO;assumption]]
901 |rewrite < H3;simplify;rewrite < times_n_SO;do 2 apply lt_to_le;assumption]]
902 |simplify;apply le_exp_log;assumption]
903 |rewrite < H1;simplify;apply le_n]]
906 (* Bertrand weak, lavori in corso
908 theorem bertrand_weak : \forall n. 9 \leq n \to prim n < prim (4*n).
910 apply (trans_le ? ? ? (le_S_S ? ? (le_prim_stima ? 2 ? ?)))
912 |unfold sqrt;apply f_m_to_le_max
913 [do 6 apply lt_to_le;assumption
914 |apply le_to_leb_true;assumption]
915 |cut (pred ((4*n)/(S (log 2 (4*n)))) \leq prim (4*n))
916 [|apply le_S_S_to_le;rewrite < S_pred
917 [apply le_times_to_le_div2
919 |change in \vdash (? % (? (? (? %)) (? (? ? %)))) with (2*2*n);
920 rewrite > assoc_times in \vdash (? % (? (? (? %)) (? (? ? %))));
921 rewrite > sym_times in \vdash (? ? %);
922 apply le_priml;rewrite > (times_n_O O) in \vdash (? % ?);
925 |apply (trans_le ? ? ? ? H);apply le_S_S;apply le_O_n]]
926 |apply le_times_to_le_div;
928 |rewrite < times_n_SO;apply (trans_le ? (S (S (2 + (log 2 n)))))
929 [apply le_S_S;apply (log_times 2 4 n);apply le_S_S;apply le_n
930 |change in \vdash (? % ?) with (4 + log 2 n);
931 rewrite > S_pred in \vdash (? ? (? ? %));
932 [change in ⊢ (? ? (? ? %)) with (1 + pred n);
933 rewrite > distr_times_plus;apply le_plus_r;elim H
934 [simplify;do 3 apply le_S_S;apply le_O_n
935 |apply (trans_le ? (log 2 (2*n1)))
937 [apply le_S_S;apply le_n
938 |rewrite < times_SSO_n;
939 change in \vdash (? % ?) with (1 + n1);
940 apply le_plus_l;apply (trans_le ? ? ? ? H1);
942 |apply (trans_le ? (S (4*pred n1)))
943 [rewrite > exp_n_SO in ⊢ (? (? ? (? % ?)) ?);
945 [change in \vdash (? ? %) with (1 + (4*pred n1));
948 |apply le_S_S;apply le_n
949 |apply (trans_le ? ? ? ? H1);apply le_S_S;apply le_O_n]
950 |simplify in \vdash (? ? (? ? %));
951 rewrite > minus_n_O in \vdash (? (? (? ? (? %))) ?);
952 rewrite < eq_minus_S_pred;
953 rewrite > distr_times_minus;
954 change in \vdash (? % ?) with (1 + (4*n1 - 4));
955 rewrite > eq_plus_minus_minus_minus
956 [simplify;apply le_minus_m;
958 |rewrite > times_n_SO in \vdash (? % ?);
959 apply le_times_r;apply (trans_le ? ? ? ? H1);
961 |apply (trans_le ? ? ? ? H);apply lt_O_S]]]]]
962 apply (trans_le ? ? ? ? Hcut);