{"attempts":[],"challenge":{"imports":["Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity"],"name":"Lemma.primes_mod_9_eq_1","statement":"Set.Infinite {p : ℕ | p.Prime ∧ p % 9 = 1}"},"chat":[],"disproof":null,"program":{"checked_by":"nodes","id":"euclid-primes","lean":"v4.34.1","mathlib":"v4.34.1","project":null,"title":"Primes in progressions, Euclid's way"},"proof":"import Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity\n\nnamespace Lemma.P91\n\ntheorem key (x : ℕ) (hx : 3 ∣ x) (q : ℕ) (hq : q.Prime)\n    (hd : q ∣ x ^ 6 + x ^ 3 + 1) : q % 9 = 1 ∧ ¬ q ∣ x := by\n  haveI := Fact.mk hq\n  haveI : Fact (Nat.Prime 3) := Fact.mk Nat.prime_three\n  have h1 : ((x ^ 6 + x ^ 3 + 1 : ℕ) : ZMod q) = 0 :=\n    (CharP.cast_eq_zero_iff (ZMod q) q _).2 hd\n  push_cast at h1\n  have hndvd : ¬ q ∣ x := by\n    intro hqx\n    have : (x : ZMod q) = 0 := (CharP.cast_eq_zero_iff (ZMod q) q _).2 hqx\n    rw [this] at h1\n    simp at h1\n  refine ⟨?_, hndvd⟩\n  have hx0 : (x : ZMod q) ≠ 0 := by\n    intro h\n    exact hndvd ((CharP.cast_eq_zero_iff (ZMod q) q _).1 h)\n  have hq3 : q ≠ 3 := by\n    rintro rfl\n    exact hndvd hx\n  have hn : ¬ (x : ZMod q) ^ (3 ^ 1) = 1 := by\n    intro h\n    have h3' : ((3 : ℕ) : ZMod q) = 0 := by\n      push_cast\n      have h3 : (x : ZMod q) ^ 3 = 1 := by simpa using h\n      linear_combination h1 - ((x : ZMod q) ^ 3 + 2) * h3\n    have hq3' : q ∣ 3 := (CharP.cast_eq_zero_iff (ZMod q) q _).1 h3'\n    exact hq3 ((Nat.prime_dvd_prime_iff_eq hq Nat.prime_three).1 hq3')\n  have h9 : (x : ZMod q) ^ (3 ^ (1 + 1)) = 1 := by\n    norm_num\n    linear_combination ((x : ZMod q) ^ 3 - 1) * h1\n  have hord : orderOf (x : ZMod q) = 3 ^ (1 + 1) := orderOf_eq_prime_pow hn h9\n  have hdvd : 3 ^ (1 + 1) ∣ q - 1 := hord ▸ ZMod.orderOf_dvd_card_sub_one hx0\n  have h2 := hq.two_le\n  norm_num at hdvd\n  omega\n\nend Lemma.P91\n\ntheorem Lemma.primes_mod_9_eq_1 :\n    Set.Infinite {p : ℕ | p.Prime ∧ p % 9 = 1} := by\n  apply Set.infinite_of_forall_exists_gt\n  intro n\n  set x := (n + 3).factorial with hxdef\n  have hx3 : 3 ∣ x := Nat.dvd_factorial (by norm_num) (by omega)\n  have hN : x ^ 6 + x ^ 3 + 1 ≠ 1 := by\n    have : 0 < x := Nat.factorial_pos _\n    have : 0 < x ^ 6 := by positivity\n    omega\n  have hq := Nat.minFac_prime hN\n  have hqd := Nat.minFac_dvd (x ^ 6 + x ^ 3 + 1)\n  obtain ⟨h9, hnd⟩ := Lemma.P91.key x hx3 _ hq hqd\n  refine ⟨_, ⟨hq, h9⟩, ?_⟩\n  by_contra hle\n  push_neg at hle\n  exact hnd (Nat.dvd_factorial hq.pos (by omega))\n","proposals":[],"row":{"attempts":0,"blocker":null,"either":false,"last":null,"name":"Lemma.primes_mod_9_eq_1","statement":null,"status":"proved"}}