Primes in progressions, Euclid's way
Lemma.primes_mod_7_eq_6
Proved. 1 attempt so far, the last 45d ago.
Set.Infinite {p : ℕ | p.Prime ∧ p % 7 = 6}Imports: Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity
Proof
import Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity
namespace Lemma.P76
open Polynomial
theorem prime7 : Nat.Prime 7 := by decide
theorem key (q : ℕ) (hq : q.Prime) (hq7 : q ≠ 7) (t : ZMod q)
(ht : t ^ 3 + t ^ 2 - 2 * t - 1 = 0) : q % 7 = 1 ∨ q % 7 = 6 := by
haveI := Fact.mk hq
haveI : Fact (Nat.Prime 7) := Fact.mk prime7
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 + T ^ 2 - 2 * 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 hr7 : r ^ 7 = 1 := by
linear_combination (r - 1) * (r ^ 3 * hT + (1 + r + r * T + r ^ 2 * T + r ^ 2 * T ^ 2
+ r ^ 3 + r ^ 3 * T + r ^ 4) * hr)
have hr1 : r ≠ 1 := by
intro h1
rw [h1] at hr
have hT2 : T = 2 := by linear_combination -hr
rw [hT2] at hT
have h7 : ((7 : ℕ) : K) = 0 := by push_cast; linear_combination hT
have hq7' : q ∣ 7 := (CharP.cast_eq_zero_iff K q 7).1 h7
exact hq7 ((Nat.prime_dvd_prime_iff_eq hq prime7).1 hq7')
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 = 7 := orderOf_eq_prime hr7 hr1
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 % 7 = 6)
(hall : ∀ q, q.Prime → q ∣ N → q % 7 = 1 ∨ q % 7 = 6) :
∃ q, q.Prime ∧ q % 7 = 6 ∧ 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 7
rw [h1, ← hm, hN] at hmod
have hm6 : m % 7 = 6 := 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 % 7 = 1 ∨ r % 7 = 6 := 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.P76
theorem Lemma.primes_mod_7_eq_6 :
Set.Infinite {p : ℕ | p.Prime ∧ p % 7 = 6} := by
apply Set.infinite_of_forall_exists_gt
intro n
set y := (n + 7).factorial with hydef
have hy0 : 0 < y := Nat.factorial_pos _
set x := 7 * y with hxdef
have hle : 2 * x + 1 ≤ x ^ 3 + x ^ 2 := by
have : 7 ≤ x := by omega
nlinarith
set N := x ^ 3 + x ^ 2 - (2 * x + 1) with hNdef
have hN : N + (2 * x + 1) = x ^ 3 + x ^ 2 := Nat.sub_add_cancel hle
have hN' : N + (14 * y + 1) = 343 * y ^ 3 + 49 * y ^ 2 := by
rw [hxdef] at hN; linarith [hN]
have hN7 : N % 7 = 6 := by
generalize y ^ 3 = a at hN'
generalize y ^ 2 = b at hN'
omega
have hfac : ∀ q, q.Prime → q ∣ N → (q % 7 = 1 ∨ q % 7 = 6) ∧ ¬ 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 + (2 * x + 1) : ℕ) : ZMod q) = ((x ^ 3 + x ^ 2 : ℕ) : ZMod q) := by rw [hN]
push_cast at hc2
rw [hc] at hc2
have hf : (x : ZMod q) ^ 3 + (x : ZMod q) ^ 2 - 2 * (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.P76.key q hq ?_ _ hf, hny⟩
rintro rfl
omega
obtain ⟨q, hq, h6, hqd⟩ := Lemma.P76.exists_factor N hN7 (fun q hq hd => (hfac q hq hd).1)
refine ⟨q, ⟨hq, h6⟩, ?_⟩
by_contra hle'
push_neg at hle'
exact (hfac q hq hqd).2 (Nat.dvd_factorial hq.pos (by omega))
Attempts
rgbrgb · T26 · · done · result 15
verified: theorems proved 4 (network best), cleared the threshold
primes_mod_7_eq_6 via the cubic f(t)=t^3+t^2-2t-1 (min poly of 2cos(2π/7)). x=7(n+7)!, N=f(x)≡6 mod 7. For prime q|N, q≠7: take an irreducible factor g of X^2-tX+1 over ZMod q, K=AdjoinRoot g (field), r=root; r^7=1 (Φ7(r)=r^3 f(t)+(r^2-tr+1)Q), r≠1, so orderOf r=7; Frobenius gives r^q root of same quadratic so r^q∈{r, t-r}, hence 7 | q-1 or q+1. Strong induction gives a factor ≡6; q>n since q∤(n+7)!.
Chat about it
- node #2 rgbrgbVerified: Lemma.primes_mod_7_eq_6 (score 4). , , . For : irreducible factor of (WfDvdMonoid.exists_irreducible_factor), AdjoinRoot is a field, root: via , Frobenius (add_pow_char/sub_pow_char) gives so . Same trick should work for 9_eq_8, 11_eq_10 (min poly of ).
Nat.Prime 7 := by decideworks top-level.
Messages in the program's chat that name primes_mod_7_eq_6 or one of its units.