Lemma Park

Primes in progressions, Euclid's way

Lemma.primes_mod_8_eq_7

Proved. 0 attempts so far.

Set.Infinite {p : ℕ | p.Prime ∧ p % 8 = 7}

Imports: Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity

Proof
import Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity

namespace Lemma.P87

theorem key (y : ℕ) (hy : 2 ∣ y) (hy0 : 0 < y) (q : ℕ) (hq : q.Prime)
    (hd : q ∣ 2 * y ^ 2 - 1) : (q % 8 = 1 ∨ q % 8 = 7) ∧ ¬ q ∣ y := by
  haveI := Fact.mk hq
  have h1 : ((2 * y ^ 2 - 1 : ℕ) : ZMod q) = 0 :=
    (CharP.cast_eq_zero_iff (ZMod q) q _).2 hd
  have h5 : 1 ≤ 2 * y ^ 2 := by
    have : 1 ≤ y ^ 2 := Nat.one_le_pow _ _ hy0
    omega
  have h2 : (2 : ZMod q) * (y : ZMod q) ^ 2 = 1 := by
    rw [Nat.cast_sub h5] at h1
    push_cast at h1
    linear_combination h1
  have hndvd : ¬ q ∣ y := by
    intro hqy
    have : (y : ZMod q) = 0 := (CharP.cast_eq_zero_iff (ZMod q) q _).2 hqy
    rw [this] at h2
    simp at h2
  refine ⟨?_, hndvd⟩
  have hq2 : q ≠ 2 := by
    rintro rfl
    exact hndvd hy
  have hsq : IsSquare (2 : ZMod q) := ⟨2 * y, by linear_combination (-2) * h2⟩
  exact (ZMod.exists_sq_eq_two_iff hq2).1 hsq

theorem exists7 (N : ℕ) (hN : N % 8 = 7)
    (hf : ∀ q, q.Prime → q ∣ N → q % 8 = 1 ∨ q % 8 = 7) :
    ∃ q, q.Prime ∧ q ∣ N ∧ q % 8 = 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 % 8 = 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.P87

theorem Lemma.primes_mod_8_eq_7 :
    Set.Infinite {p : ℕ | p.Prime ∧ p % 8 = 7} := by
  apply Set.infinite_of_forall_exists_gt
  intro n
  have hy2 : 2 ∣ (n + 3).factorial := Nat.dvd_factorial (by norm_num) (by omega)
  have hy0 : 0 < (n + 3).factorial := Nat.factorial_pos _
  have hN : (2 * (n + 3).factorial ^ 2 - 1) % 8 = 7 := by
    obtain ⟨k, hk⟩ := hy2
    have hz : (n + 3).factorial ^ 2 = 4 * k ^ 2 := by rw [hk]; ring
    have : 1 ≤ (n + 3).factorial ^ 2 := Nat.one_le_pow _ _ hy0
    rw [hz] at this ⊢
    omega
  obtain ⟨q, hq, hqd, hq4⟩ := Lemma.P87.exists7 _ hN
    (fun q hq hd => (Lemma.P87.key _ hy2 hy0 q hq hd).1)
  refine ⟨q, ⟨hq, hq4⟩, ?_⟩
  by_contra hle
  push_neg at hle
  exact (Lemma.P87.key _ hy2 hy0 q hq hqd).2 (Nat.dvd_factorial hq.pos (by omega))

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_7 or one of its units.