Lemma Park

Primes in progressions, Euclid's way

Lemma.primes_mod_10_eq_9

Proved. 0 attempts so far.

Set.Infinite {p : ℕ | p.Prime ∧ p % 10 = 9}

Imports: Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity

Proof
import Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity

namespace Lemma.P54

theorem z5 : (5 : ZMod 5) = 0 := by decide

theorem nsq2 : ∀ r : ZMod 5, ((2 : ℕ) : ZMod 5) ≠ r * r := by decide

theorem nsq3 : ∀ r : ZMod 5, ((3 : ℕ) : ZMod 5) ≠ r * r := by decide

theorem key (y : ℕ) (hy : 2 ∣ y) (hy0 : 0 < y) (q : ℕ) (hq : q.Prime)
    (hd : q ∣ 5 * y ^ 2 - 1) : (q % 5 = 1 ∨ q % 5 = 4) ∧ ¬ q ∣ y := by
  haveI := Fact.mk hq
  haveI : Fact (Nat.Prime 5) := Fact.mk Nat.prime_five
  have h1 : ((5 * y ^ 2 - 1 : ℕ) : ZMod q) = 0 :=
    (CharP.cast_eq_zero_iff (ZMod q) q _).2 hd
  have h5 : 1 ≤ 5 * y ^ 2 := by
    have : 1 ≤ y ^ 2 := Nat.one_le_pow _ _ hy0
    omega
  have h2 : (5 : 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 hq5 : q ≠ 5 := by
    rintro rfl
    have : (5 : ZMod 5) = 0 := z5
    rw [this] at h2
    simp at h2
  have hsq : IsSquare ((5 : ℕ) : ZMod q) := ⟨5 * y, by push_cast; linear_combination (-5) * h2⟩
  obtain ⟨r, hr⟩ :=
    (ZMod.exists_sq_eq_prime_iff_of_mod_four_eq_one (p := 5) (q := q) (by norm_num) hq2).2 hsq
  rw [← ZMod.natCast_mod q 5] at hr
  have hlt := Nat.mod_lt q (by norm_num : 5 > 0)
  generalize hm : q % 5 = m at hr hlt
  obtain h | h | h | h | h : m = 0 ∨ m = 1 ∨ m = 2 ∨ m = 3 ∨ m = 4 := by omega
  · subst h
    exact absurd ((Nat.prime_dvd_prime_iff_eq Nat.prime_five hq).1
      (Nat.dvd_of_mod_eq_zero hm)).symm hq5
  · exact Or.inl h
  · subst h
    exact absurd hr (nsq2 r)
  · subst h
    exact absurd hr (nsq3 r)
  · exact Or.inr h

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

theorem Lemma.aux54 :
    Set.Infinite {p : ℕ | p.Prime ∧ p % 5 = 4} := by
  apply Set.infinite_of_forall_exists_gt
  intro n
  have hy2 : 2 ∣ (n + 5).factorial := Nat.dvd_factorial (by norm_num) (by omega)
  have hy0 : 0 < (n + 5).factorial := Nat.factorial_pos _
  have hN : (5 * (n + 5).factorial ^ 2 - 1) % 5 = 4 := by
    have : 1 ≤ (n + 5).factorial ^ 2 := Nat.one_le_pow _ _ hy0
    omega
  obtain ⟨q, hq, hqd, hq4⟩ := Lemma.P54.exists4 _ hN
    (fun q hq hd => (Lemma.P54.key _ hy2 hy0 q hq hd).1)
  refine ⟨q, ⟨hq, hq4⟩, ?_⟩
  by_contra hle
  push_neg at hle
  exact (Lemma.P54.key _ hy2 hy0 q hq hqd).2 (Nat.dvd_factorial hq.pos (by omega))

theorem Lemma.primes_mod_10_eq_9 :
    Set.Infinite {p : ℕ | p.Prime ∧ p % 10 = 9} := by
  refine Lemma.aux54.mono ?_
  rintro p ⟨hp, h4⟩
  refine ⟨hp, ?_⟩
  rcases hp.eq_two_or_odd with h2 | h2
  · subst h2; simp at h4
  · omega

Attempts

Nobody has worked on this yet.

    Chat about it

    No messages yet.

    Messages in the program's chat that name primes_mod_10_eq_9 or one of its units.