import Mathlib.Algebra.MvPolynomial.Funextimport Mathlib.RingTheory.MvPolynomial.Symmetric.Defsimport Mathlib.Order.Interval.Set.Infiniteimport Mathlib.Tactic/-!# Specializing a symmetric square pencil to one variableA nonzero rational polynomial can be kept nonzero while all but one of itsvariables are specialized to distinct rational numbers. The four fixedvariables and the remaining free one then produce the five square identities.-/namespace SquarePencilopen MvPolynomialprivate theorem exists_distinct_specialization {n : ℕ}{p : MvPolynomial (Fin n) ℚ} (hp : p ≠ 0) :∃ c : Fin n → ℚ, Function.Injective c ∧ eval c p ≠ 0 := byclassicallet box (i : Fin n) := Set.Ioo (i.val : ℚ) (i.val+1 : ℚ)have hbox (i : Fin n) : (box i).Infinite := Set.Ioo_infinite (by linarith)by_contra! no_pointapply hpapply MvPolynomial.funext_set box hboxintro c hchave hc' (i : Fin n) : (i.val : ℚ) < c i ∧ c i < (i.val : ℚ)+1 := hc i (Set.mem_univ i)have hstrict : StrictMono c := byintro i j hijhave hs : (i.val : ℚ)+1 ≤ (j.val : ℚ) := by exact_mod_cast hijexact ((hc' i).2.trans_le hs).trans (hc' j).1simpa using no_point c hstrict.injectiveprivate theorem square_at_every_index {n : ℕ} (i₀ : Fin n)(S₁ S₂ P : MvPolynomial (Fin n) ℚ)(h₁ : S₁.IsSymmetric) (h₂ : S₂.IsSymmetric)(hP : P^2 = S₁ + X i₀ * S₂) (i : Fin n) :∃ Q : MvPolynomial (Fin n) ℚ, Q^2 = S₁ + X i * S₂ := byclassicallet e := Equiv.swap i₀ irefine ⟨rename e P, ?_⟩simpa only [map_pow, map_add, map_mul, rename_X, h₁ e, h₂ e,e, Equiv.swap_apply_left] using congrArg (rename (R := ℚ) e) hP/-- Every nondegenerate symmetric example in n > 4 variables gives aone-variable example with four distinct fixed rational parameters. -/theorem exists_five {n : ℕ} (hn : 4 < n) (i₀ : Fin n)(S₁ S₂ P : MvPolynomial (Fin n) ℚ)(h₁ : S₁.IsSymmetric) (h₂ : S₂.IsSymmetric) (hnz : S₂ ≠ 0)(hP : P^2 = S₁ + X i₀ * S₂) :∃ (A B : Polynomial ℚ) (c : Fin 4 → ℚ) (y : Fin 4 → Polynomial ℚ) (z : Polynomial ℚ),B ≠ 0 ∧ Function.Injective c ∧(∀ i, y i ^ 2 = A + Polynomial.C (c i) * B) ∧ z ^ 2 = A + Polynomial.X * B := byclassicalobtain ⟨v,hv,hvB⟩ := exists_distinct_specialization hnzchoose Q hQ using square_at_every_index i₀ S₁ S₂ P h₁ h₂ hPlet f : Fin n := ⟨4,hn⟩let ι (i : Fin 4) : Fin n := ⟨i.val,by omega⟩let g (i : Fin n) : Polynomial ℚ := if i = f then Polynomial.X else Polynomial.C (v i)let φ := eval₂Hom Polynomial.C ghave hrecover (p : MvPolynomial (Fin n) ℚ) :Polynomial.eval (v f) (φ p) = eval v p := bychange Polynomial.eval (v f) (eval₂ Polynomial.C g p) = _rw [polynomial_eval_eval₂]have hc : (Polynomial.evalRingHom (v f)).comp Polynomial.C = RingHom.id ℚ := byext; simprw [hc]have hg : (fun i => Polynomial.eval (v f) (g i)) = v := byfunext iby_cases h : i=f <;> simp [g,h]rw [hg,eval₂_id]refine ⟨φ S₁,φ S₂,fun i => v (ι i),fun i => φ (Q (ι i)),φ (Q f),?_,?_,?_,?_⟩· intro heapply hvBrw [← hrecover,he,Polynomial.eval_zero]· apply hv.compintro i j hijexact Fin.ext (congrArg (Fin.val : Fin n → ℕ) hij)· intro ihave h : ι i ≠ f := byintro hehave := congrArg Fin.val hedsimp [ι,f] at thisomegasimpa only [map_pow,map_add,map_mul,φ,eval₂Hom_X',g,if_neg h] using congrArg φ (hQ (ι i))· simpa only [map_pow,map_add,map_mul,φ,eval₂Hom_X',g,if_pos rfl] using congrArg φ (hQ f)#print axioms exists_fiveend SquarePencil