@@ -4,29 +4,47 @@ Released under Apache 2.0 license as described in the file LICENSE.
4
4
Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro
5
5
-/
6
6
import Mathlib.Algebra.Associated.Basic
7
- import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
8
- import Mathlib.Algebra.Ring.Int
9
- import Mathlib.Data.Nat.Factorial.Basic
7
+ import Mathlib.Algebra.Ring.Parity
10
8
import Mathlib.Data.Nat.Prime.Defs
11
- import Mathlib.Order.Bounds.Basic
12
9
13
10
/-!
14
- ## Notable Theorems
11
+ # Prime numbers
15
12
16
- - `Nat.exists_infinite_primes`: Euclid's theorem that there exist infinitely many prime numbers.
17
- This also appears as `Nat.not_bddAbove_setOf_prime` and `Nat.infinite_setOf_prime` (the latter
18
- in `Data.Nat.PrimeFin`).
13
+ This file develops the theory of prime numbers: natural numbers `p ≥ 2` whose only divisors are
14
+ `p` and `1`.
19
15
20
16
-/
21
17
22
-
23
18
open Bool Subtype
24
19
25
20
open Nat
26
21
27
22
namespace Nat
28
23
variable {n : ℕ}
29
24
25
+ theorem prime_mul_iff {a b : ℕ} : Nat.Prime (a * b) ↔ a.Prime ∧ b = 1 ∨ b.Prime ∧ a = 1 := by
26
+ simp only [irreducible_mul_iff, ← irreducible_iff_nat_prime, Nat.isUnit_iff]
27
+
28
+ theorem not_prime_mul {a b : ℕ} (a1 : a ≠ 1 ) (b1 : b ≠ 1 ) : ¬Prime (a * b) := by
29
+ simp [prime_mul_iff, _root_.not_or, *]
30
+
31
+ theorem not_prime_mul' {a b n : ℕ} (h : a * b = n) (h₁ : a ≠ 1 ) (h₂ : b ≠ 1 ) : ¬Prime n :=
32
+ h ▸ not_prime_mul h₁ h₂
33
+
34
+ theorem Prime.dvd_iff_eq {p a : ℕ} (hp : p.Prime) (a1 : a ≠ 1 ) : a ∣ p ↔ p = a := by
35
+ refine ⟨?_, by rintro rfl; rfl⟩
36
+ rintro ⟨j, rfl⟩
37
+ rcases prime_mul_iff.mp hp with (⟨_, rfl⟩ | ⟨_, rfl⟩)
38
+ · exact mul_one _
39
+ · exact (a1 rfl).elim
40
+
41
+ theorem Prime.eq_two_or_odd {p : ℕ} (hp : Prime p) : p = 2 ∨ p % 2 = 1 :=
42
+ p.mod_two_eq_zero_or_one.imp_left fun h =>
43
+ ((hp.eq_one_or_self_of_dvd 2 (dvd_of_mod_eq_zero h)).resolve_left (by decide)).symm
44
+
45
+ theorem Prime.eq_two_or_odd' {p : ℕ} (hp : Prime p) : p = 2 ∨ Odd p :=
46
+ Or.imp_right (fun h => ⟨p / 2 , (div_add_mod p 2 ).symm.trans (congr_arg _ h)⟩) hp.eq_two_or_odd
47
+
30
48
section
31
49
32
50
theorem Prime.five_le_of_ne_two_of_ne_three {p : ℕ} (hp : p.Prime) (h_two : p ≠ 2 )
@@ -78,26 +96,6 @@ theorem dvd_of_forall_prime_mul_dvd {a b : ℕ}
78
96
obtain ⟨p, hp⟩ := exists_prime_and_dvd ha
79
97
exact _root_.trans (dvd_mul_left a p) (hdvd p hp.1 hp.2 )
80
98
81
- /-- Euclid's theorem on the **infinitude of primes** .
82
- Here given in the form: for every `n`, there exists a prime number `p ≥ n`. -/
83
- theorem exists_infinite_primes (n : ℕ) : ∃ p, n ≤ p ∧ Prime p :=
84
- let p := minFac (n ! + 1 )
85
- have f1 : n ! + 1 ≠ 1 := ne_of_gt <| succ_lt_succ <| factorial_pos _
86
- have pp : Prime p := minFac_prime f1
87
- have np : n ≤ p :=
88
- le_of_not_ge fun h =>
89
- have h₁ : p ∣ n ! := dvd_factorial (minFac_pos _) h
90
- have h₂ : p ∣ 1 := (Nat.dvd_add_iff_right h₁).2 (minFac_dvd _)
91
- pp.not_dvd_one h₂
92
- ⟨p, np, pp⟩
93
-
94
- /-- A version of `Nat.exists_infinite_primes` using the `BddAbove` predicate. -/
95
- theorem not_bddAbove_setOf_prime : ¬BddAbove { p | Prime p } := by
96
- rw [not_bddAbove_iff]
97
- intro n
98
- obtain ⟨p, hi, hp⟩ := exists_infinite_primes n.succ
99
- exact ⟨p, hp, hi⟩
100
-
101
99
theorem Prime.even_iff {p : ℕ} (hp : Prime p) : Even p ↔ p = 2 := by
102
100
rw [even_iff_two_dvd, prime_dvd_prime_iff_eq prime_two hp, eq_comm]
103
101
@@ -159,18 +157,6 @@ theorem Prime.pow_eq_iff {p a k : ℕ} (hp : p.Prime) : a ^ k = p ↔ a = p ∧
159
157
rw [← h] at hp
160
158
rw [← h, hp.eq_one_of_pow, eq_self_iff_true, _root_.and_true, pow_one]
161
159
162
- theorem pow_minFac {n k : ℕ} (hk : k ≠ 0 ) : (n ^ k).minFac = n.minFac := by
163
- rcases eq_or_ne n 1 with (rfl | hn)
164
- · simp
165
- have hnk : n ^ k ≠ 1 := fun hk' => hn ((pow_eq_one_iff hk).1 hk')
166
- apply (minFac_le_of_dvd (minFac_prime hn).two_le ((minFac_dvd n).pow hk)).antisymm
167
- apply
168
- minFac_le_of_dvd (minFac_prime hnk).two_le
169
- ((minFac_prime hnk).dvd_of_dvd_pow (minFac_dvd _))
170
-
171
- theorem Prime.pow_minFac {p k : ℕ} (hp : p.Prime) (hk : k ≠ 0 ) : (p ^ k).minFac = p := by
172
- rw [Nat.pow_minFac hk, hp.minFac_eq]
173
-
174
160
theorem Prime.mul_eq_prime_sq_iff {x y p : ℕ} (hp : p.Prime) (hx : x ≠ 1 ) (hy : y ≠ 1 ) :
175
161
x * y = p ^ 2 ↔ x = p ∧ y = p := by
176
162
refine ⟨fun h => ?_, fun ⟨h₁, h₂⟩ => h₁.symm ▸ h₂.symm ▸ (sq _).symm⟩
@@ -197,14 +183,6 @@ theorem Prime.mul_eq_prime_sq_iff {x y p : ℕ} (hp : p.Prime) (hx : x ≠ 1) (h
197
183
rw [sq, Nat.mul_right_eq_self_iff (Nat.mul_pos hp.pos hp.pos : 0 < a * a)] at h
198
184
exact h
199
185
200
- theorem Prime.dvd_factorial : ∀ {n p : ℕ} (_ : Prime p), p ∣ n ! ↔ p ≤ n
201
- | 0 , _, hp => iff_of_false hp.not_dvd_one (not_le_of_lt hp.pos)
202
- | n + 1 , p, hp => by
203
- rw [factorial_succ, hp.dvd_mul, Prime.dvd_factorial hp]
204
- exact
205
- ⟨fun h => h.elim (le_of_dvd (succ_pos _)) le_succ_of_le, fun h =>
206
- (_root_.lt_or_eq_of_le h).elim (Or.inr ∘ le_of_lt_succ) fun h => Or.inl <| by rw [h]⟩
207
-
208
186
theorem Prime.coprime_pow_of_not_dvd {p m a : ℕ} (pp : Prime p) (h : ¬p ∣ a) : Coprime a (p ^ m) :=
209
187
(pp.coprime_iff_not_dvd.2 h).symm.pow_right _
210
188
@@ -269,33 +247,4 @@ theorem succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : ℕ} (p_prime : Prime p) {
269
247
exact hpd5.elim (fun h : p ∣ m / p ^ k => Or.inl <| mul_dvd_of_dvd_div hpm h)
270
248
fun h : p ∣ n / p ^ l => Or.inr <| mul_dvd_of_dvd_div hpn h
271
249
272
- theorem prime_iff_prime_int {p : ℕ} : p.Prime ↔ _root_.Prime (p : ℤ) :=
273
- ⟨fun hp =>
274
- ⟨Int.natCast_ne_zero_iff_pos.2 hp.pos, mt Int.isUnit_iff_natAbs_eq.1 hp.ne_one, fun a b h => by
275
- rw [← Int.dvd_natAbs, Int.natCast_dvd_natCast, Int.natAbs_mul, hp.dvd_mul] at h
276
- rwa [← Int.dvd_natAbs, Int.natCast_dvd_natCast, ← Int.dvd_natAbs, Int.natCast_dvd_natCast]⟩,
277
- fun hp =>
278
- Nat.prime_iff.2
279
- ⟨Int.natCast_ne_zero.1 hp.1 ,
280
- (mt Nat.isUnit_iff.1 ) fun h => by simp [h, not_prime_one] at hp, fun a b => by
281
- simpa only [Int.natCast_dvd_natCast, (Int.ofNat_mul _ _).symm] using hp.2 .2 a b⟩⟩
282
-
283
- /-- Two prime powers with positive exponents are equal only when the primes and the
284
- exponents are equal. -/
285
- lemma Prime.pow_inj {p q m n : ℕ} (hp : p.Prime) (hq : q.Prime)
286
- (h : p ^ (m + 1 ) = q ^ (n + 1 )) : p = q ∧ m = n := by
287
- have H := dvd_antisymm (Prime.dvd_of_dvd_pow hp <| h ▸ dvd_pow_self p (succ_ne_zero m))
288
- (Prime.dvd_of_dvd_pow hq <| h.symm ▸ dvd_pow_self q (succ_ne_zero n))
289
- exact ⟨H, succ_inj'.mp <| Nat.pow_right_injective hq.two_le (H ▸ h)⟩
290
-
291
250
end Nat
292
-
293
- namespace Int
294
-
295
- theorem prime_two : Prime (2 : ℤ) :=
296
- Nat.prime_iff_prime_int.mp Nat.prime_two
297
-
298
- theorem prime_three : Prime (3 : ℤ) :=
299
- Nat.prime_iff_prime_int.mp Nat.prime_three
300
-
301
- end Int
0 commit comments