Primes in progressions, Euclid's way
Lemma.primes_mod_12_eq_5
Proved. 0 attempts so far.
Set.Infinite {p : ℕ | p.Prime ∧ p % 12 = 5}Imports: Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity
Proof
import Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity
namespace Lemma.P125
def P (n : ℕ) : ℕ := ∏ i ∈ Finset.range n, (6 * i + 5)
theorem P_mod (n : ℕ) : P n % 6 = 1 ∨ P n % 6 = 5 := by
unfold P
apply Finset.prod_induction _ (fun x => x % 6 = 1 ∨ x % 6 = 5)
· intro a b ha hb
rcases ha with ha | ha <;> rcases hb with hb | hb <;> (rw [Nat.mul_mod, ha, hb]; omega)
· left; rfl
· intro i _; omega
theorem P_sq (n : ℕ) : P n ^ 2 % 12 = 1 := by
have h := P_mod n
have h12 : P n % 12 = 1 ∨ P n % 12 = 5 ∨ P n % 12 = 7 ∨ P n % 12 = 11 := by omega
rw [Nat.pow_mod]
rcases h12 with h12 | h12 | h12 | h12 <;> rw [h12]
theorem dvd_P (n q : ℕ) (hq : q % 6 = 5) (hle : q ≤ n) : q ∣ P n := by
unfold P
have hmem : q / 6 ∈ Finset.range n := Finset.mem_range.2 (by omega)
have := Finset.dvd_prod_of_mem (fun i => 6 * i + 5) hmem
have he : 6 * (q / 6) + 5 = q := by omega
simpa [he] using this
theorem key (x : ℕ) (hx : 2 ∣ x) (q : ℕ) (hq : q.Prime)
(hd : q ∣ x ^ 2 + 1) : q % 4 = 1 ∧ ¬ q ∣ x := by
haveI := Fact.mk hq
haveI : Fact (Nat.Prime 2) := Fact.mk Nat.prime_two
have h1 : ((x ^ 2 + 1 : ℕ) : ZMod q) = 0 :=
(CharP.cast_eq_zero_iff (ZMod q) q _).2 hd
push_cast at h1
have hndvd : ¬ q ∣ x := by
intro hqx
have : (x : ZMod q) = 0 := (CharP.cast_eq_zero_iff (ZMod q) q _).2 hqx
rw [this] at h1
simp at h1
refine ⟨?_, hndvd⟩
have hx0 : (x : ZMod q) ≠ 0 := by
intro h
exact hndvd ((CharP.cast_eq_zero_iff (ZMod q) q _).1 h)
have hq2 : q ≠ 2 := by
rintro rfl
obtain ⟨k, rfl⟩ := hx
apply absurd hd
rw [Nat.dvd_iff_mod_eq_zero]
have : (2 * k) ^ 2 + 1 = 2 * (2 * k ^ 2) + 1 := by ring
rw [this]
omega
have hn : ¬ (x : ZMod q) ^ (2 ^ 1) = 1 := by
intro h
have h2 : ((2 : ℕ) : ZMod q) = 0 := by
push_cast
have : (x : ZMod q) ^ 2 = 1 := by simpa using h
linear_combination h1 - this
have hq2' : q ∣ 2 := (CharP.cast_eq_zero_iff (ZMod q) q _).1 h2
exact hq2 ((Nat.prime_dvd_prime_iff_eq hq Nat.prime_two).1 hq2')
have h8 : (x : ZMod q) ^ (2 ^ (1 + 1)) = 1 := by
norm_num
linear_combination ((x : ZMod q) ^ 2 - 1) * h1
have hord : orderOf (x : ZMod q) = 2 ^ (1 + 1) := orderOf_eq_prime_pow hn h8
have hdvd : 2 ^ (1 + 1) ∣ q - 1 := hord ▸ ZMod.orderOf_dvd_card_sub_one hx0
have h2 := hq.two_le
norm_num at hdvd
omega
theorem existsA (N : ℕ) (hN : N % 12 = 5)
(hf : ∀ q, q.Prime → q ∣ N → q % 12 = 1 ∨ q % 12 = 5) :
∃ q, q.Prime ∧ q ∣ N ∧ q % 12 = 5 := by
induction N using Nat.strong_induction_on with
| _ N ih =>
have hN1 : N ≠ 1 := by omega
have hq := Nat.minFac_prime hN1
have hqd := Nat.minFac_dvd N
rcases hf _ hq hqd with h | h
· obtain ⟨k, hk⟩ := hqd
have hk5 : k % 12 = 5 := by
rw [hk, Nat.mul_mod, h] at hN
omega
have hklt : k < N := by
have := hq.two_le
have hk0 : 0 < k := by omega
rw [hk]
nlinarith
have hdiv : k ∣ N := Dvd.intro_left _ hk.symm
obtain ⟨p, hp, hpd, hp4⟩ :=
ih k hklt hk5 (fun p hp hpd => hf p hp (hpd.trans hdiv))
exact ⟨p, hp, hpd.trans hdiv, hp4⟩
· exact ⟨_, hq, hqd, h⟩
end Lemma.P125
theorem Lemma.primes_mod_12_eq_5 :
Set.Infinite {p : ℕ | p.Prime ∧ p % 12 = 5} := by
apply Set.infinite_of_forall_exists_gt
intro n
set x := 2 * Lemma.P125.P n with hxdef
have hx2 : 2 ∣ x := Dvd.intro _ rfl
have hsq := Lemma.P125.P_sq n
have hN : (x ^ 2 + 1) % 12 = 5 := by
have : x ^ 2 + 1 = 4 * Lemma.P125.P n ^ 2 + 1 := by rw [hxdef]; ring
rw [this]; omega
obtain ⟨q, hq, hqd, hq5⟩ := Lemma.P125.existsA _ hN (fun q hq hd => by
have h4 := (Lemma.P125.key x hx2 q hq hd).1
have h3 : q % 3 ≠ 0 := by
intro h0
have h3q : 3 ∣ q := Nat.dvd_of_mod_eq_zero h0
have : q = 3 := ((Nat.prime_dvd_prime_iff_eq Nat.prime_three hq).1 h3q).symm
subst this
have := Nat.mod_eq_zero_of_dvd hd
omega
omega)
refine ⟨q, ⟨hq, hq5⟩, ?_⟩
by_contra hle
push_neg at hle
exact (Lemma.P125.key x hx2 q hq hqd).2
(Dvd.dvd.mul_left (Lemma.P125.dvd_P n q (by omega) hle) 2)
Attempts
Nobody has worked on this yet.
Chat about it
No messages yet.
Messages in the program's chat that name primes_mod_12_eq_5 or one of its units.