Primes in progressions, Euclid's way
Lemma.primes_mod_12_eq_7
Proved. 0 attempts so far.
Set.Infinite {p : ℕ | p.Prime ∧ p % 12 = 7}Imports: Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity
Proof
import Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity
namespace Lemma.P127
def Q (n : ℕ) : ℕ := ∏ i ∈ Finset.range n, (2 * i + 1)
theorem Q_odd (n : ℕ) : Q n % 2 = 1 := by
unfold Q
apply Finset.prod_induction _ (fun x => x % 2 = 1)
· intro a b ha hb; rw [Nat.mul_mod, ha, hb]
· rfl
· intro i _; omega
theorem dvd_Q (n q : ℕ) (hq : q % 2 = 1) (hle : q ≤ n) : q ∣ Q n := by
unfold Q
have hmem : q / 2 ∈ Finset.range n := Finset.mem_range.2 (by omega)
have := Finset.dvd_prod_of_mem (fun i => 2 * i + 1) hmem
have he : 2 * (q / 2) + 1 = q := by omega
simpa [he] using this
theorem key (x : ℕ) (hx : 6 ∣ x) (q : ℕ) (hq : q.Prime)
(hd : q ∣ x ^ 2 + x + 1) : q % 6 = 1 ∧ ¬ q ∣ x := by
haveI := Fact.mk hq
haveI : Fact (Nat.Prime 3) := Fact.mk Nat.prime_three
have h1 : ((x ^ 2 + x + 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 hx1 : (x : ZMod q) ≠ 1 := by
intro h
rw [h] at h1
have h3 : ((3 : ℕ) : ZMod q) = 0 := by push_cast; linear_combination h1
have hq3 : q ∣ 3 := (CharP.cast_eq_zero_iff (ZMod q) q _).1 h3
have : q = 3 := (Nat.prime_dvd_prime_iff_eq hq Nat.prime_three).1 hq3
exact hndvd (this ▸ (Dvd.dvd.trans (by norm_num : 3 ∣ 6) hx))
have hx3 : (x : ZMod q) ^ 3 = 1 := by
linear_combination ((x : ZMod q) - 1) * h1
have hord : orderOf (x : ZMod q) = 3 := orderOf_eq_prime hx3 hx1
have hdvd : 3 ∣ q - 1 := hord ▸ ZMod.orderOf_dvd_card_sub_one hx0
have hq2 : q ≠ 2 := by
rintro rfl
obtain ⟨k, rfl⟩ := hx
apply absurd hd
rw [Nat.dvd_iff_mod_eq_zero]
have : (6 * k) ^ 2 + 6 * k + 1 = 2 * (18 * k ^ 2 + 3 * k) + 1 := by ring
rw [this]
omega
have h2 := hq.two_le
rcases Nat.even_or_odd q with he | ho
· exact absurd ((Nat.prime_dvd_prime_iff_eq Nat.prime_two hq).1 (even_iff_two_dvd.1 he)).symm hq2
· obtain ⟨k, hk⟩ := ho
omega
theorem existsA (N : ℕ) (hN : N % 12 = 7)
(hf : ∀ q, q.Prime → q ∣ N → q % 12 = 1 ∨ q % 12 = 7) :
∃ q, q.Prime ∧ q ∣ N ∧ q % 12 = 7 := 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 = 7 := 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.P127
theorem Lemma.primes_mod_12_eq_7 :
Set.Infinite {p : ℕ | p.Prime ∧ p % 12 = 7} := by
apply Set.infinite_of_forall_exists_gt
intro n
set x := 6 * Lemma.P127.Q n with hxdef
have hx6 : 6 ∣ x := Dvd.intro _ rfl
have hodd := Lemma.P127.Q_odd n
obtain ⟨k, hk⟩ : ∃ k, x = 12 * k + 6 := ⟨Lemma.P127.Q n / 2, by omega⟩
have hN : (x ^ 2 + x + 1) % 12 = 7 := by
have : x ^ 2 + x + 1 = 12 * (12 * k ^ 2 + 13 * k + 3) + 7 := by rw [hk]; ring
rw [this]; omega
obtain ⟨q, hq, hqd, hq7⟩ := Lemma.P127.existsA _ hN (fun q hq hd => by
have := (Lemma.P127.key x hx6 q hq hd).1
have h2 : q % 2 = 1 := by
rcases hq.eq_two_or_odd with h | h
· omega
· exact h
omega)
refine ⟨q, ⟨hq, hq7⟩, ?_⟩
by_contra hle
push_neg at hle
exact (Lemma.P127.key x hx6 q hq hqd).2
(Dvd.dvd.mul_left (Lemma.P127.dvd_Q n q (by omega) hle) 6)
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_7 or one of its units.