Lemma Park

Primes in progressions, Euclid's way

Lemma.primes_mod_9_eq_8

Proved. 0 attempts so far.

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

Imports: Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity

Proof
import Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity

namespace Lemma.P98

open Polynomial

theorem key (q : ℕ) (hq : q.Prime) (hq3 : q ≠ 3) (t : ZMod q)
    (ht : t ^ 3 - 3 * t + 1 = 0) : q % 9 = 1 ∨ q % 9 = 8 := by
  haveI := Fact.mk hq
  haveI : Fact (Nat.Prime 3) := Fact.mk Nat.prime_three
  set p : (ZMod q)[X] := X ^ 2 - C t * X + 1 with hpdef
  have hp : p.natDegree = 2 := by rw [hpdef]; compute_degree!
  have hpu : ¬ IsUnit p := by
    intro h
    have := Polynomial.natDegree_eq_zero_of_isUnit h
    omega
  have hp0 : p ≠ 0 := by
    intro h
    rw [h] at hp
    simp at hp
  obtain ⟨g, hg, hgp⟩ := WfDvdMonoid.exists_irreducible_factor hpu hp0
  haveI := Fact.mk hg
  let K := AdjoinRoot g
  let r : K := AdjoinRoot.root g
  have hr0 : aeval r p = 0 := by
    obtain ⟨c, hc⟩ := hgp
    rw [hc, map_mul, AdjoinRoot.aeval_eq, AdjoinRoot.mk_self, zero_mul]
  set T : K := algebraMap (ZMod q) K t with hTdef
  have hr : r ^ 2 - T * r + 1 = 0 := by
    rw [hpdef] at hr0
    simpa [hTdef] using hr0
  haveI : CharP K q := charP_of_injective_algebraMap (algebraMap (ZMod q) K).injective q
  have hT : T ^ 3 - 3 * T + 1 = 0 := by
    have := congrArg (algebraMap (ZMod q) K) ht
    simpa [hTdef, map_ofNat] using this
  have hTq : T ^ q = T := by rw [hTdef, ← map_pow, ZMod.pow_card]
  have hphi : r ^ 6 + r ^ 3 + 1 = 0 := by
    linear_combination r ^ 3 * hT
      + (r ^ 4 + r ^ 3 * T + r ^ 2 * T ^ 2 - r ^ 2 + r * T + 1) * hr
  have hr9 : r ^ (3 ^ (1 + 1)) = 1 := by
    norm_num
    linear_combination (r ^ 3 - 1) * hphi
  have hr3 : ¬ r ^ (3 ^ 1) = 1 := by
    intro h3
    have h3' : r ^ 3 = 1 := by simpa using h3
    have h33 : ((3 : ℕ) : K) = 0 := by
      push_cast
      linear_combination (-(r ^ 3 + 2)) * h3' + hphi
    have hq3' : q ∣ 3 := (CharP.cast_eq_zero_iff K q 3).1 h33
    exact hq3 ((Nat.prime_dvd_prime_iff_eq hq Nat.prime_three).1 hq3')
  have hrne : r ≠ 0 := by
    intro h0
    rw [h0] at hr
    simp at hr
  have hrq : (r ^ q) ^ 2 - T * r ^ q + 1 = 0 := by
    have : (r ^ 2 - T * r + 1) ^ q = 0 := by rw [hr, zero_pow hq.ne_zero]
    rw [add_pow_char, sub_pow_char, mul_pow, hTq, one_pow] at this
    rw [← this]
    ring
  have hprod : (r ^ q - r) * (r ^ q - (T - r)) = 0 := by linear_combination hrq - hr
  have hord : orderOf r = 3 ^ (1 + 1) := orderOf_eq_prime_pow hr3 hr9
  norm_num at hord
  have hq2 := hq.two_le
  rcases mul_eq_zero.1 hprod with h | h
  · have h' : r ^ (q - 1) = 1 := by
      have e : r ^ q = r ^ (q - 1) * r := by
        rw [← pow_succ]; congr 1; omega
      have : (r ^ (q - 1) - 1) * r = 0 := by linear_combination e.symm.trans (sub_eq_zero.1 h)
      rcases mul_eq_zero.1 this with h2 | h2
      · exact sub_eq_zero.1 h2
      · exact absurd h2 hrne
    have := orderOf_dvd_of_pow_eq_one h'
    rw [hord] at this
    omega
  · have h' : r ^ (q + 1) = 1 := by
      rw [pow_succ, sub_eq_zero.1 h]
      linear_combination -hr
    have := orderOf_dvd_of_pow_eq_one h'
    rw [hord] at this
    omega

theorem exists_factor (N : ℕ) (hN : N % 9 = 8)
    (hall : ∀ q, q.Prime → q ∣ N → q % 9 = 1 ∨ q % 9 = 8) :
    ∃ q, q.Prime ∧ q % 9 = 8 ∧ q ∣ N := 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
    set q := N.minFac with hqdef
    rcases hall q hq hqd with h1 | h6
    · obtain ⟨m, hm⟩ := hqd
      have hmod := Nat.mul_mod q m 9
      rw [h1, ← hm, hN] at hmod
      have hm6 : m % 9 = 8 := by omega
      have hmlt : m < N := by
        have hm0 : 0 < m := by
          apply Nat.pos_of_ne_zero
          rintro rfl
          rw [mul_zero] at hm
          omega
        rw [hm]
        calc m = 1 * m := (one_mul m).symm
          _ < q * m := Nat.mul_lt_mul_of_pos_right hq.one_lt hm0
      have hall' : ∀ r, r.Prime → r ∣ m → r % 9 = 1 ∨ r % 9 = 8 := fun r hr hrm =>
        hall r hr (hrm.trans ⟨q, by rw [hm, mul_comm]⟩)
      obtain ⟨r, hr, hr6, hrd⟩ := ih m hmlt hm6 hall'
      exact ⟨r, hr, hr6, hrd.trans ⟨q, by rw [hm, mul_comm]⟩⟩
    · exact ⟨q, hq, h6, hqd⟩

end Lemma.P98

theorem Lemma.primes_mod_9_eq_8 :
    Set.Infinite {p : ℕ | p.Prime ∧ p % 9 = 8} := by
  apply Set.infinite_of_forall_exists_gt
  intro n
  set y := (n + 9).factorial with hydef
  have hy0 : 0 < y := Nat.factorial_pos _
  set x := 9 * y with hxdef
  have hle : 3 * x + 1 ≤ x ^ 3 := by
    have h9 : 9 ≤ x := by omega
    have h3 : x ^ 3 = x * (x * x) := by ring
    have h1 : 9 * x ≤ x * x := Nat.mul_le_mul_right x h9
    have h2 : 9 * (x * x) ≤ x * (x * x) := Nat.mul_le_mul_right (x * x) h9
    rw [h3]
    omega
  set N := x ^ 3 - (3 * x + 1) with hNdef
  have hN : N + (3 * x + 1) = x ^ 3 := Nat.sub_add_cancel hle
  have hN' : N + (27 * y + 1) = 729 * y ^ 3 := by
    rw [hxdef] at hN; linarith [hN]
  have hN9 : N % 9 = 8 := by
    generalize y ^ 3 = a at hN'
    omega
  have hfac : ∀ q, q.Prime → q ∣ N → (q % 9 = 1 ∨ q % 9 = 8) ∧ ¬ q ∣ y := by
    intro q hq hqN
    haveI := Fact.mk hq
    have hc : ((N : ℕ) : ZMod q) = 0 := (CharP.cast_eq_zero_iff (ZMod q) q _).2 hqN
    have hc2 : ((N + (3 * x + 1) : ℕ) : ZMod q) = ((x ^ 3 : ℕ) : ZMod q) := by rw [hN]
    push_cast at hc2
    rw [hc] at hc2
    have hf : (-(x : ZMod q)) ^ 3 - 3 * (-(x : ZMod q)) + 1 = 0 := by
      linear_combination hc2
    have hny : ¬ q ∣ y := by
      intro hqy
      have : (x : ZMod q) = 0 := by
        rw [hxdef]; push_cast
        rw [(CharP.cast_eq_zero_iff (ZMod q) q _).2 hqy, mul_zero]
      rw [this] at hf
      norm_num at hf
    refine ⟨Lemma.P98.key q hq ?_ _ hf, hny⟩
    rintro rfl
    generalize y ^ 3 = a at hN'
    omega
  obtain ⟨q, hq, h8, hqd⟩ := Lemma.P98.exists_factor N hN9 (fun q hq hd => (hfac q hq hd).1)
  refine ⟨q, ⟨hq, h8⟩, ?_⟩
  by_contra hle'
  push_neg at hle'
  exact (hfac 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_9_eq_8 or one of its units.