Primes in progressions, Euclid's way
Lemma.primes_mod_8_eq_5
Proved. 0 attempts so far.
Set.Infinite {p : ℕ | p.Prime ∧ p % 8 = 5}Imports: Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity
Proof
import Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity
namespace Lemma.P85
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 Q_pos (n : ℕ) : 0 < Q n := by have := Q_odd n; omega
theorem Q_sq (n : ℕ) : Q n ^ 2 % 8 = 1 := by
have h := Q_odd n
have h8 : Q n % 8 = 1 ∨ Q n % 8 = 3 ∨ Q n % 8 = 5 ∨ Q n % 8 = 7 := by omega
rw [Nat.pow_mod]
rcases h8 with h8 | h8 | h8 | h8 <;> rw [h8]
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 (n q : ℕ) (hq : q.Prime) (hd : q ∣ 4 * Q n ^ 2 + 1) :
(q % 8 = 1 ∨ q % 8 = 5) ∧ ¬ q ∣ Q n := by
haveI := Fact.mk hq
have h2 : 4 * ((Q n : ℕ) : ZMod q) ^ 2 + 1 = 0 := by
have := (CharP.cast_eq_zero_iff (ZMod q) q _).2 hd
push_cast at this
exact this
have hq2 : q ≠ 2 := by
rintro rfl
have : (4 * Q n ^ 2 + 1) % 2 = 0 := Nat.mod_eq_zero_of_dvd hd
omega
have hndvd : ¬ q ∣ Q n := by
intro hqy
have : ((Q n : ℕ) : ZMod q) = 0 := (CharP.cast_eq_zero_iff (ZMod q) q _).2 hqy
rw [this] at h2
simp at h2
refine ⟨?_, hndvd⟩
have hsq : IsSquare (-1 : ZMod q) := ⟨2 * (Q n : ZMod q), by linear_combination (-1) * h2⟩
have h4 := (ZMod.exists_sq_eq_neg_one_iff (p := q)).1 hsq
have hodd := hq.eq_two_or_odd
omega
theorem existsA (N : ℕ) (hN : N % 8 = 5)
(hf : ∀ q, q.Prime → q ∣ N → q % 8 = 1 ∨ q % 8 = 5) :
∃ q, q.Prime ∧ q ∣ N ∧ q % 8 = 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 % 8 = 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.P85
theorem Lemma.primes_mod_8_eq_5 :
Set.Infinite {p : ℕ | p.Prime ∧ p % 8 = 5} := by
apply Set.infinite_of_forall_exists_gt
intro n
have hN : (4 * Lemma.P85.Q n ^ 2 + 1) % 8 = 5 := by
have := Lemma.P85.Q_sq n
omega
obtain ⟨q, hq, hqd, hq4⟩ := Lemma.P85.existsA _ hN
(fun q hq hd => (Lemma.P85.key n q hq hd).1)
refine ⟨q, ⟨hq, hq4⟩, ?_⟩
by_contra hle
push_neg at hle
exact (Lemma.P85.key n q hq hqd).2 (Lemma.P85.dvd_Q n q (by omega) hle)
Attempts
Nobody has worked on this yet.
Chat about it
No messages yet.
Messages in the program's chat that name primes_mod_8_eq_5 or one of its units.