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 include "nat/sqrt.ma".
16 include "nat/chebyshev_teta.ma".
17 include "nat/chebyshev.ma".
20 definition bertrand \def \lambda n.
21 \exists p.n < p \land p \le 2*n \land (prime p).
23 definition not_bertrand \def \lambda n.
24 \forall p.n < p \to p \le 2*n \to \not (prime p).
26 lemma not_not_bertrand_to_bertrand1: \forall n.
27 \lnot (not_bertrand n) \to \forall x. n \le x \to x \le 2*n \to
28 (\forall p.x < p \to p \le 2*n \to \not (prime p))
29 \to \exists p.n < p \land p \le x \land (prime p).
31 [apply False_ind.apply H.assumption
32 |apply (bool_elim ? (primeb (S n1)));intro
33 [apply (ex_intro ? ? (S n1)).
36 [apply le_S_S.assumption
39 |apply primeb_true_to_prime.assumption
44 apply (ex_intro ? ? a).
48 |apply le_S.assumption
52 |apply lt_to_le.assumption
53 |elim (le_to_or_lt_eq ? ? H7)
56 apply primeb_false_to_not_prime.
64 theorem not_not_bertrand_to_bertrand: \forall n.
65 \lnot (not_bertrand n) \to bertrand n.
66 unfold bertrand.intros.
67 apply (not_not_bertrand_to_bertrand1 ? ? (2*n))
69 |apply le_times_n.apply le_n_Sn
71 |intros.apply False_ind.
72 apply (lt_to_not_le ? ? H1 H2)
77 theorem divides_pi_p_to_divides: \forall p,n,b,g.prime p \to
78 divides p (pi_p n b g) \to \exists i. (i < n \and (b i = true \and
83 apply (le_to_not_lt p 1)
90 |apply (bool_elim ? (b n1));intro
91 [rewrite > (true_to_pi_p_Sn ? ? ? H3) in H2.
92 elim (divides_times_to_divides ? ? ? H1 H2)
93 [apply (ex_intro ? ? n1).
100 apply (ex_intro ? ? a).
102 [apply lt_to_le.apply le_S_S.assumption
106 |rewrite > (false_to_pi_p_Sn ? ? ? H3) in H2.
109 apply (ex_intro ? ? a).
111 [apply lt_to_le.apply le_S_S.assumption
118 theorem divides_B: \forall n,p.prime p \to p \divides (B n) \to
119 p \le n \land \exists i.mod (n /(exp p (S i))) 2 \neq O.
122 elim (divides_pi_p_to_divides ? ? ? ? H H1).
125 elim (divides_pi_p_to_divides ? ? ? ? H H5).clear H5.
130 [rewrite > Hcut.apply le_S_S_to_le.assumption
131 |apply (ex_intro ? ? a1).
134 change in H7:(? ? %) with (exp a ((n/(exp a (S a1))) \mod 2)).
138 [apply divides_to_le[apply lt_O_S|assumption]
139 |apply lt_to_not_le.elim H.assumption
142 |apply (divides_exp_to_eq ? ? ? H ? H7).
143 apply primeb_true_to_prime.
149 definition k \def \lambda n,p.
150 sigma_p (log p n) (λi:nat.true) (λi:nat.((n/(exp p (S i))\mod 2))).
152 theorem le_k: \forall n,p. k n p \le log p n.
153 intros.unfold k.elim (log p n)
155 |rewrite > true_to_sigma_p_Sn
156 [rewrite > plus_n_SO.
157 rewrite > sym_plus in ⊢ (? ? %).
170 \lambda n. pi_p (S n) primeb (\lambda p.(exp p (k n p))).
172 theorem eq_B_B1: \forall n. B n = B1 n.
173 intros.unfold B.unfold B1.
181 definition B_split1 \def \lambda n.
182 pi_p (S n) primeb (\lambda p.(exp p (bool_to_nat (leb (k n p) 1)* (k n p)))).
184 definition B_split2 \def \lambda n.
185 pi_p (S n) primeb (\lambda p.(exp p (bool_to_nat (leb 2 (k n p))* (k n p)))).
187 theorem eq_B1_times_B_split1_B_split2: \forall n.
188 B1 n = B_split1 n * B_split2 n.
189 intro.unfold B1.unfold B_split1.unfold B_split2.
190 rewrite < times_pi_p.
193 |intros.apply (bool_elim ? (leb (k n x) 1));intro
194 [rewrite > (lt_to_leb_false 2 (k n x))
195 [simplify.rewrite < plus_n_O.
196 rewrite < times_n_SO.reflexivity
197 |apply le_S_S.apply leb_true_to_le.assumption
199 |rewrite > (le_to_leb_true 2 (k n x))
200 [simplify.rewrite < plus_n_O.
201 rewrite < plus_n_O.reflexivity
202 |apply not_le_to_lt.apply leb_false_to_not_le.assumption
208 lemma lt_div_to_times: \forall n,m,q. O < q \to n/q < m \to n < q*m.
212 intro.apply (lt_to_not_le ? ? H1).
213 apply le_times_to_le_div;assumption
214 |apply (ltn_to_ltO ? ? H1)
218 lemma lt_to_div_O:\forall n,m. n < m \to n / m = O.
220 apply (div_mod_spec_to_eq n m (n/m) (n \mod m) O n)
221 [apply div_mod_spec_div_mod.
222 apply (ltn_to_ltO ? ? H)
223 |apply div_mod_spec_intro
230 (* the value of n could be smaller *)
231 lemma k1: \forall n,p. 18 \le n \to p \le n \to 2*n/ 3 < p\to k (2*n) p = O.
235 |rewrite > true_to_sigma_p_Sn
240 cut (2*n/p = 2) as H4
241 [rewrite > H4.reflexivity
242 |apply lt_to_le_times_to_lt_S_to_div
243 [apply (ltn_to_ltO ? ? H2)
244 |rewrite < sym_times.
247 |rewrite > sym_times in ⊢ (? ? %).
248 apply lt_div_to_times
254 |cut (2*n/(p)\sup(S (S n2)) = O) as H4
255 [rewrite > H4.reflexivity
257 apply (le_to_lt_to_lt ? (exp ((2*n)/3) 2))
258 [apply (le_times_to_le (exp 3 2))
259 [apply leb_true_to_le.reflexivity
260 |rewrite > sym_times in ⊢ (? ? %).
262 apply (trans_le ? (exp n 2))
263 [rewrite < assoc_times.
264 rewrite > exp_SSO in ⊢ (? ? %).
267 |apply monotonic_exp1.
268 apply (le_plus_to_le 3).
269 change in ⊢ (? ? %) with ((S(2*n/3))*3).
270 apply (trans_le ? (2*n))
271 [simplify in ⊢ (? ? %).
274 apply (trans_le ? 18 ? ? H).
275 apply leb_true_to_le.reflexivity
282 |apply (lt_to_le_to_lt ? (exp p 2))
288 [apply (ltn_to_ltO ? ? H2)
289 |apply le_S_S.apply le_S_S.apply le_O_n
300 theorem le_B_split1_teta:\forall n.18 \le n \to not_bertrand n \to
301 B_split1 (2*n) \le teta (2 * n / 3).
302 intros.unfold B_split1.unfold teta.
303 apply (trans_le ? (pi_p (S (2*n)) primeb (λp:nat.(p)\sup(bool_to_nat (eqb (k (2*n) p) 1)))))
304 [apply le_pi_p.intros.
306 [apply prime_to_lt_O.apply primeb_true_to_prime.assumption
307 |apply (bool_elim ? (leb (k (2*n) i) 1));intro
308 [elim (le_to_or_lt_eq ? ? (leb_true_to_le ? ? H4))
309 [lapply (le_S_S_to_le ? ? H5) as H6.
310 apply (le_n_O_elim ? H6).
313 |rewrite > (eq_to_eqb_true ? ? H5).
314 rewrite > H5.apply le_n
319 |apply (trans_le ? (pi_p (S (2*n/3)) primeb (λp:nat.(p)\sup(bool_to_nat (eqb (k (2*n) p) 1)))))
320 [apply (eq_ind ? ? ? (le_n ?)).
321 apply or_false_eq_SO_to_eq_pi_p
323 apply le_times_to_le_div2
325 |rewrite > sym_times in ⊢ (? ? %).
327 apply leb_true_to_le.reflexivity
330 unfold not_bertrand in H1.
331 elim (decidable_le (S n) i)
333 apply not_prime_to_primeb_false.
336 |apply le_S_S_to_le.assumption
343 apply not_le_to_lt.assumption
348 |apply le_pi_p.intros.
349 elim (eqb (k (2*n) i) 1)
350 [rewrite < exp_n_SO.apply le_n
351 |simplify.apply prime_to_lt_O.
352 apply primeb_true_to_prime.
359 theorem le_B_split2_exp: \forall n. exp 2 7 \le n \to
360 B_split2 (2*n) \le exp (2*n) (pred(sqrt(2*n)/2)).
361 intros.unfold B_split2.
363 [apply (trans_le ? (pi_p (S (sqrt (2*n))) primeb
364 (λp:nat.(p)\sup(bool_to_nat (leb 2 (k (2*n) p))*k (2*n) p))))
365 [apply (eq_ind ? ? ? (le_n ?)).
366 apply or_false_eq_SO_to_eq_pi_p
370 apply (bool_elim ? (leb 2 (k (2*n) i)));intro
372 apply (lt_to_not_le ? ? H1).unfold sqrt.
374 [apply le_S_S_to_le.assumption
375 |apply le_to_leb_true.
377 apply not_lt_to_le.intro.
378 apply (le_to_not_lt 2 (log i (2*n)))
379 [apply (trans_le ? (k (2*n) i))
380 [apply leb_true_to_le.assumption
383 |apply le_S_S.unfold log.apply f_false_to_le_max
384 [apply (ex_intro ? ? O).split
386 |apply le_to_leb_true.simplify.
392 |intros.apply lt_to_leb_false.
393 apply (lt_to_le_to_lt ? (exp i 2))
396 [apply (ltn_to_ltO ? ? H1)
406 |apply (trans_le ? (pi_p (S (sqrt (2*n))) primeb (λp:nat.2*n)))
407 [apply le_pi_p.intros.
408 apply (trans_le ? (exp i (log i (2*n))))
410 [apply prime_to_lt_O.
411 apply primeb_true_to_prime.
413 |apply (bool_elim ? (leb 2 (k (2*n) i)));intro
414 [simplify in ⊢ (? (? % ?) ?).
416 rewrite < times_n_SO.
422 rewrite > (times_n_O O) in ⊢ (? % ?).
428 |apply (trans_le ? (exp (2*n) (prim(sqrt (2*n)))))
430 apply (eq_ind ? ? ? (le_n ?)).
433 [rewrite > (times_n_O O) in ⊢ (? % ?).
441 [apply (trans_le ? (2*(exp 2 7)))
442 [apply leb_true_to_le.reflexivity
443 |apply le_times_r.assumption
445 |apply le_to_leb_true.
446 apply (trans_le ? (2*(exp 2 7)))
447 [apply leb_true_to_le.reflexivity
448 |apply le_times_r.assumption
455 |apply (lt_to_le_to_lt ? ? ? ? H).
456 apply leb_true_to_le.reflexivity
460 theorem not_bertrand_to_le_B:
461 \forall n.exp 2 7 \le n \to not_bertrand n \to
462 B (2*n) \le (exp 2 (2*(2 * n / 3)))*(exp (2*n) (pred(sqrt(2*n)/2))).
465 rewrite > eq_B1_times_B_split1_B_split2.
467 [apply (trans_le ? (teta ((2*n)/3)))
468 [apply le_B_split1_teta
469 [apply (trans_le ? ? ? ? H).
470 apply leb_true_to_le.reflexivity
475 |apply le_B_split2_exp.
481 theorem not_bertrand_to_le1:
482 \forall n.18 \le n \to not_bertrand n \to
483 exp 2 (2*n) \le (exp 2 (2*(2 * n / 3)))*(exp (2*n) (S(sqrt(2*n)))).
486 theorem le_times_div_m_m: \forall n,m. O < m \to n/m*m \le n.
488 rewrite > (div_mod n m) in ⊢ (? ? %)
494 theorem not_bertrand_to_le1:
495 \forall n.exp 2 7 \le n \to not_bertrand n \to
496 (exp 2 (2*n / 3)) \le (exp (2*n) (sqrt(2*n)/2)).
498 apply (le_times_to_le (exp 2 (2*(2 * n / 3))))
499 [apply lt_O_exp.apply lt_O_S
500 |rewrite < exp_plus_times.
501 apply (trans_le ? (exp 2 (2*n)))
505 change in ⊢ (? % ?) with (3*(2*n/3)).
507 apply le_times_div_m_m.
511 rewrite < distr_times_plus.
513 apply (trans_le ? ((2*n + n)/3))
514 [apply le_plus_div.apply lt_O_S
516 change in ⊢ (? (? % ?) ?) with (3*n).
518 rewrite > lt_O_to_div_times
524 |apply (trans_le ? (2*n*B(2*n)))
526 apply (trans_le ? ? ? ? H).
527 apply leb_true_to_le.reflexivity
528 |rewrite > S_pred in ⊢ (? ? (? ? (? ? %)))
530 rewrite < assoc_times.
531 rewrite < sym_times in ⊢ (? ? (? % ?)).
532 rewrite > assoc_times in ⊢ (? ? %).
534 apply not_bertrand_to_le_B;assumption
535 |apply le_times_to_le_div
537 |apply (trans_le ? (sqrt (exp 2 8)))
538 [apply leb_true_to_le.reflexivity
539 |apply monotonic_sqrt.
540 change in ⊢ (? % ?) with (2*(exp 2 7)).
551 theorem not_bertrand_to_le2:
552 \forall n.exp 2 7 \le n \to not_bertrand n \to
553 2*n / 3 \le (sqrt(2*n)/2)*S(log 2 (2*n)).
555 rewrite < (eq_log_exp 2)
556 [apply (trans_le ? (log 2 ((exp (2*n) (sqrt(2*n)/2)))))
559 |apply not_bertrand_to_le1;assumption
568 theorem tech1: \forall a,b,c,d.O < b \to O < d \to
569 (a/b)*(c/d) \le (a*c)/(b*d).
571 apply le_times_to_le_div
572 [rewrite > (times_n_O O).
573 apply lt_times;assumption
574 |rewrite > assoc_times.
575 rewrite < assoc_times in ⊢ (? (? ? %) ?).
576 rewrite < sym_times in ⊢ (? (? ? (? % ?)) ?).
577 rewrite > assoc_times.
578 rewrite < assoc_times.
580 rewrite > sym_times;apply le_times_div_m_m;assumption
584 theorem tech: \forall n. 2*(S(log 2 (2*n))) \le sqrt (2*n) \to
585 (sqrt(2*n)/2)*S(log 2 (2*n)) \le 2*n / 4.
587 cut (4*(S(log 2 (2*n))) \le 2* sqrt(2*n))
588 [rewrite > sym_times.
589 apply le_times_to_le_div
591 |rewrite < assoc_times.
592 apply (trans_le ? (2*sqrt(2*n)*(sqrt (2*n)/2)))
593 [apply le_times_l.assumption
594 |apply (trans_le ? ((2*sqrt(2*n)*(sqrt(2*n))/2)))
595 [apply le_times_div_div_times.
597 |rewrite > assoc_times.
599 rewrite > lt_O_to_div_times.
605 |change in ⊢ (? (? % ?) ?) with (2*2).
606 rewrite > assoc_times.
612 theorem lt_div_S_div: \forall n,m. O < m \to exp m 2 \le n \to
615 apply lt_times_to_lt_div.
616 apply (lt_to_le_to_lt ? (S(n/m)*m))
617 [apply lt_div_S.assumption
618 |rewrite > sym_times in ⊢ (? ? %). simplify.
619 rewrite > sym_times in ⊢ (? ? (? ? %)).
621 apply le_times_to_le_div
629 theorem exp_plus_SSO: \forall a,b. exp (a+b) 2 = (exp a 2) + 2*a*b + (exp b 2).
632 rewrite > distr_times_plus.
633 rewrite > times_plus_l.
635 rewrite > assoc_plus.
636 rewrite > assoc_plus.
638 rewrite > times_plus_l.
640 rewrite < assoc_plus.
642 rewrite > plus_n_O in ⊢ (? ? (? (? ? %) ?) ?).
643 rewrite > assoc_times.
644 apply eq_f2;reflexivity.
647 theorem tech3: \forall n. (exp 2 8) \le n \to 2*(S(log 2 (2*n))) \le sqrt (2*n).
649 lapply (le_log 2 ? ? (le_n ?) H) as H1.
650 rewrite > exp_n_SO in ⊢ (? (? ? (? (? ? (? % ?)))) ?).
657 apply (trans_le ? (2*log 2 n))
658 [rewrite < times_SSO_n.
661 [apply leb_true_to_le.reflexivity
662 |rewrite < (eq_log_exp 2)
667 |apply (trans_le ? ? ? ? (le_exp_log 2 ? ? )).
668 apply le_times_SSO_n_exp_SSO_n.
669 apply (lt_to_le_to_lt ? ? ? ? H).
670 apply leb_true_to_le.reflexivity
672 |apply le_to_leb_true.
673 rewrite > assoc_times.
676 rewrite > assoc_times.
678 rewrite > exp_plus_SSO.
679 rewrite > distr_times_plus.
680 rewrite > distr_times_plus.
681 rewrite > assoc_plus.
682 apply (trans_le ? (4*exp (log 2 n) 2))
683 [change in ⊢ (? ? (? % ?)) with (2*2).
684 rewrite > assoc_times in ⊢ (? ? %).
685 rewrite < times_SSO_n in ⊢ (? ? %).
687 rewrite < times_SSO_n in ⊢ (? ? %).
689 [rewrite > sym_times in ⊢ (? (? ? %) ?).
690 rewrite < assoc_times.
691 rewrite < assoc_times.
692 change in ⊢ (? (? % ?) ?) with 8.
695 (* strange things here *)
696 rewrite < (eq_log_exp 2)
700 |apply (trans_le ? (log 2 n))
701 [change in ⊢ (? % ?) with 8.
702 rewrite < (eq_log_exp 2)
706 |rewrite > exp_n_SO in ⊢ (? % ?).
709 [apply (lt_to_le_to_lt ? ? ? ? H).
710 apply leb_true_to_le.reflexivity
711 |apply (lt_to_le_to_lt ? ? ? ? H).
712 apply leb_true_to_le.reflexivity
718 |change in ⊢ (? (? % ?) ?) with (exp 2 2).
719 apply (trans_le ? ? ? ? (le_exp_log 2 ? ?))
720 [apply le_times_exp_n_SSO_exp_SSO_n
722 |change in ⊢ (? % ?) with 8.
723 rewrite < (eq_log_exp 2)
728 |apply (lt_to_le_to_lt ? ? ? ? H).
729 apply leb_true_to_le.reflexivity
734 |apply (lt_to_le_to_lt ? ? ? ? H).
735 apply leb_true_to_le.reflexivity
739 theorem le_to_bertrand:
740 \forall n. (exp 2 8) \le n \to bertrand n.
742 apply not_not_bertrand_to_bertrand.unfold.intro.
743 absurd (2*n / 3 \le (sqrt(2*n)/2)*S(log 2 (2*n)))
744 [apply not_bertrand_to_le2
745 [apply (trans_le ? ? ? ? H).
753 apply (le_to_lt_to_lt ? ? ? ? (lt_div_S_div ? ? ? ?))
754 [apply tech.apply tech3.assumption
756 |apply (trans_le ? (2*exp 2 8))
757 [apply leb_true_to_le.reflexivity
758 |apply le_times_r.assumption
765 theorem mod_exp: eqb (mod (exp 2 8) 13) O = false.