{"attempts":[],"challenge":{"imports":["Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity"],"name":"Lemma.primes_mod_12_eq_1","statement":"Set.Infinite {p : ℕ | p.Prime ∧ p % 12 = 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.P121\n\ntheorem key (x N : ℕ) (hx : 6 ∣ x) (hN : N + x ^ 2 = x ^ 4 + 1) (q : ℕ) (hq : q.Prime)\n    (hd : q ∣ N) : q % 12 = 1 ∧ ¬ q ∣ x := by\n  haveI := Fact.mk hq\n  haveI : Fact (Nat.Prime 3) := Fact.mk Nat.prime_three\n  have hN0 : ((N : ℕ) : ZMod q) = 0 :=\n    (CharP.cast_eq_zero_iff (ZMod q) q _).2 hd\n  have hNc : ((N : ℕ) : ZMod q) + (x : ZMod q) ^ 2 = (x : ZMod q) ^ 4 + 1 := by\n    have := congrArg (fun m : ℕ => (m : ZMod q)) hN\n    push_cast at this\n    exact this\n  have h1 : (x : ZMod q) ^ 4 + 1 = (x : ZMod q) ^ 2 := by\n    linear_combination -hNc + hN0\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 hq2 : q ≠ 2 := by\n    rintro rfl\n    obtain ⟨k, rfl⟩ := hx\n    have e1 : (6 * k) ^ 2 = 2 * (18 * k ^ 2) := by ring\n    have e2 : (6 * k) ^ 4 = 2 * (648 * k ^ 4) := by ring\n    rw [e1, e2] at hN\n    have := Nat.mod_eq_zero_of_dvd hd\n    omega\n  set u : ZMod q := -(x : ZMod q) ^ 2 with hudef\n  have hu3 : u ^ 3 = 1 := by\n    rw [hudef]\n    linear_combination (-((x : ZMod q) ^ 2 + 1)) * h1\n  have hu1 : u ≠ 1 := by\n    intro hu\n    rw [hudef] at hu\n    have h3 : ((3 : ℕ) : ZMod q) = 0 := by\n      push_cast\n      linear_combination h1 + ((x : ZMod q) ^ 2 - 2) * hu\n    have hq3 : q ∣ 3 := (CharP.cast_eq_zero_iff (ZMod q) q _).1 h3\n    have : q = 3 := (Nat.prime_dvd_prime_iff_eq hq Nat.prime_three).1 hq3\n    exact hndvd (this ▸ (Dvd.dvd.trans (by norm_num : 3 ∣ 6) hx))\n  have hu0 : u ≠ 0 := by\n    rw [hudef]\n    exact neg_ne_zero.mpr (pow_ne_zero 2 hx0)\n  have hord : orderOf u = 3 := orderOf_eq_prime hu3 hu1\n  have hdvd : 3 ∣ q - 1 := hord ▸ ZMod.orderOf_dvd_card_sub_one hu0\n  have hinv : (x : ZMod q) * (x : ZMod q)⁻¹ = 1 := mul_inv_cancel₀ hx0\n  have hsq : IsSquare (-1 : ZMod q) :=\n    ⟨((x : ZMod q) ^ 2 - 1) * (x : ZMod q)⁻¹, by\n      linear_combination (-((x : ZMod q)⁻¹) ^ 2) * h1\n        + ((x : ZMod q) * (x : ZMod q)⁻¹ + 1) * hinv⟩\n  have h4 := (ZMod.exists_sq_eq_neg_one_iff (p := q)).1 hsq\n  have hodd := hq.eq_two_or_odd\n  have h2 := hq.two_le\n  omega\n\nend Lemma.P121\n\ntheorem Lemma.primes_mod_12_eq_1 :\n    Set.Infinite {p : ℕ | p.Prime ∧ p % 12 = 1} := by\n  apply Set.infinite_of_forall_exists_gt\n  intro n\n  set x := (n + 6).factorial with hxdef\n  have hx6 : 6 ∣ x := Nat.dvd_factorial (by norm_num) (by omega)\n  have hxpos : 0 < x := Nat.factorial_pos _\n  have hx2 : 2 ≤ x := by\n    have : (6 : ℕ) ≤ x := Nat.le_of_dvd hxpos hx6\n    omega\n  have hx4 : 4 ≤ x ^ 2 := by nlinarith\n  have h4 : x ^ 4 = x ^ 2 * x ^ 2 := by ring\n  have hle : x ^ 2 ≤ x ^ 4 + 1 := by\n    rw [h4]\n    have := Nat.mul_le_mul_left (x ^ 2) hx4\n    omega\n  set N := x ^ 4 + 1 - x ^ 2 with hNdef\n  have hN : N + x ^ 2 = x ^ 4 + 1 := Nat.sub_add_cancel hle\n  have hN1 : N ≠ 1 := by\n    have hm : x ^ 2 * 4 ≤ x ^ 2 * x ^ 2 := Nat.mul_le_mul_left _ hx4\n    rw [h4] at hN\n    generalize x ^ 2 * x ^ 2 = b at *\n    generalize x ^ 2 = a at *\n    omega\n  have hq := Nat.minFac_prime hN1\n  have hqd := Nat.minFac_dvd N\n  obtain ⟨h12, hnd⟩ := Lemma.P121.key x N hx6 hN _ hq hqd\n  refine ⟨_, ⟨hq, h12⟩, ?_⟩\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_12_eq_1","statement":null,"status":"proved"}}