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/primes.ma".
16 include "nat/lt_arith.ma".
18 (* upper bound by Bertrand's conjecture. *)
19 (* Too difficult to prove.
20 let rec nth_prime n \def
22 [ O \Rightarrow (S(S O))
24 let previous_prime \def S (nth_prime p) in
25 min_aux previous_prime ((S(S O))*previous_prime) primeb].
27 theorem example8 : nth_prime (S(S O)) = (S(S(S(S(S O))))).
28 normalize.reflexivity.
31 theorem example9 : nth_prime (S(S(S O))) = (S(S(S(S(S(S(S O))))))).
32 normalize.reflexivity.
35 theorem example10 : nth_prime (S(S(S(S O)))) = (S(S(S(S(S(S(S(S(S(S(S O))))))))))).
36 normalize.reflexivity.
39 theorem smallest_factor_fact: \forall n:nat.
40 n < smallest_factor (S n!).
42 apply not_le_to_lt.unfold Not.
44 apply (not_divides_S_fact n (smallest_factor(S n!))).
45 apply lt_SO_smallest_factor.
46 unfold lt.apply le_S_S.apply le_SO_fact.
48 apply divides_smallest_factor_n.
49 unfold lt.apply le_S_S.apply le_O_n.
52 theorem ex_prime: \forall n. (S O) \le n \to \exists m.
53 n < m \land m \le S n! \land (prime m).
56 apply (ex_intro nat ? (S(S O))).
57 split.split.apply (le_n (S(S O))).
58 apply (le_n (S(S O))).apply (primeb_to_Prop (S(S O))).
59 apply (ex_intro nat ? (smallest_factor (S (S n1)!))).
61 apply smallest_factor_fact.
62 apply le_smallest_factor_n.
63 (* Andrea: ancora hint non lo trova *)
64 apply prime_smallest_factor_n.unfold lt.
65 apply le_S.apply le_SSO_fact.
66 unfold lt.apply le_S_S.assumption.
69 let rec nth_prime n \def
71 [ O \Rightarrow (S(S O))
73 let previous_prime \def (nth_prime p) in
74 let upper_bound \def S previous_prime! in
75 min_aux upper_bound (S previous_prime) primeb].
78 theorem example11 : nth_prime (S(S O)) = (S(S(S(S(S O))))).
79 normalize.reflexivity.
82 theorem example12: nth_prime (S(S(S O))) = (S(S(S(S(S(S(S O))))))).
83 normalize.reflexivity.
86 theorem example13 : nth_prime (S(S(S(S O)))) = (S(S(S(S(S(S(S(S(S(S(S O))))))))))).
87 normalize.reflexivity.
90 alias num (instance 0) = "natural number".
91 theorem example14 : nth_prime 18 = 67.
92 normalize.reflexivity.
96 theorem prime_nth_prime : \forall n:nat.prime (nth_prime n).
98 apply (nat_case n).simplify.
99 apply (primeb_to_Prop (S(S O))).
102 (let previous_prime \def (nth_prime m) in
103 let upper_bound \def S previous_prime! in
104 prime (min_aux upper_bound (S previous_prime) primeb)).
105 apply primeb_true_to_prime.
106 apply f_min_aux_true.
107 apply (ex_intro nat ? (smallest_factor (S (nth_prime m)!))).
109 apply smallest_factor_fact.
111 [2: apply le_smallest_factor_n
113 | apply (le_plus_n_r (S (nth_prime m)) (S (fact (nth_prime m))))
115 apply prime_to_primeb_true.
116 apply prime_smallest_factor_n.unfold lt.
117 apply le_S_S.apply le_SO_fact.
120 (* properties of nth_prime *)
121 theorem increasing_nth_prime: increasing nth_prime.
125 (let previous_prime \def (nth_prime n) in
126 let upper_bound \def S previous_prime! in
127 (S previous_prime) \le min_aux upper_bound (S previous_prime) primeb).
132 variant lt_nth_prime_n_nth_prime_Sn :\forall n:nat.
133 (nth_prime n) < (nth_prime (S n)) \def increasing_nth_prime.
135 theorem injective_nth_prime: injective nat nat nth_prime.
136 apply increasing_to_injective.
137 apply increasing_nth_prime.
140 theorem lt_SO_nth_prime_n : \forall n:nat. (S O) \lt nth_prime n.
141 intros. elim n.unfold lt.apply le_n.
142 apply (trans_lt ? (nth_prime n1)).
143 assumption.apply lt_nth_prime_n_nth_prime_Sn.
146 theorem lt_O_nth_prime_n : \forall n:nat. O \lt nth_prime n.
147 intros.apply (trans_lt O (S O)).
148 unfold lt. apply le_n.apply lt_SO_nth_prime_n.
151 theorem lt_n_nth_prime_n : \forall n:nat. n \lt nth_prime n.
154 [apply lt_O_nth_prime_n
155 |apply (lt_to_le_to_lt ? (S (nth_prime n1)))
156 [unfold.apply le_S_S.assumption
157 |apply lt_nth_prime_n_nth_prime_Sn
162 theorem ex_m_le_n_nth_prime_m:
163 \forall n: nat. nth_prime O \le n \to
164 \exists m. nth_prime m \le n \land n < nth_prime (S m).
166 apply increasing_to_le2.
167 exact lt_nth_prime_n_nth_prime_Sn.assumption.
170 theorem lt_nth_prime_to_not_prime: \forall n,m. nth_prime n < m \to m < nth_prime (S n)
173 apply primeb_false_to_not_prime.
174 letin previous_prime \def (nth_prime n).
175 letin upper_bound \def (S previous_prime!).
176 apply (lt_min_aux_to_false primeb (S previous_prime) upper_bound m).
179 apply (transitive_le (S m) (nth_prime (S n)) (min_aux (S (fact (nth_prime n))) (S (nth_prime n)) primeb) ? ?);
181 |apply (le_n (min_aux (S (fact (nth_prime n))) (S (nth_prime n)) primeb)).
185 (* nth_prime enumerates all primes *)
186 theorem prime_to_nth_prime : \forall p:nat. prime p \to
187 \exists i. nth_prime i = p.
189 cut (\exists m. nth_prime m \le p \land p < nth_prime (S m)).
191 cut (nth_prime a < p \lor nth_prime a = p).
195 apply (lt_nth_prime_to_not_prime a).assumption.assumption.
196 apply (ex_intro nat ? a).assumption.
197 apply le_to_or_lt_eq.assumption.
198 apply ex_m_le_n_nth_prime_m.
199 simplify.unfold prime in H.elim H.assumption.