import Mathlib.RingTheory.Polynomial.Wronskianimport Mathlib.RingTheory.Coprime.Lemmasimport Mathlib.RingTheory.PrincipalIdealDomainimport Mathlib.Algebra.Polynomial.BigOperatorsimport Mathlib.Tacticnamespace SquarePencilopen Polynomialtheorem common {A B D : ℚ[X]} {x y : ℚ} (hne : y ≠ x)(hx : D ∣ A+C x*B) (hy : D ∣ A+C y*B) : D ∣ A ∧ D ∣ B := byhave h := dvd_sub hy hxhave hf : (A+C y*B)-(A+C x*B) = C (y-x)*B := by rw [map_sub]; ringrw [hf] at hhave hu : IsUnit (C (y-x) : ℚ[X]) := isUnit_C.mpr (sub_ne_zero.mpr hne).isUnithave hB := hu.dvd_mul_left.mp hrefine ⟨?_,hB⟩simpa using dvd_sub hx (dvd_mul_of_dvd_right hB (C x))theorem four_constant {A B : ℚ[X]} (hAB : IsCoprime A B)(c : Fin 4 → ℚ) (hc : Function.Injective c) (y : Fin 4 → ℚ[X])(hy : ∀ i, y i^2=A+C (c i)*B) : A.derivative=0 ∧ B.derivative=0 := byapply hAB.wronskian_eq_zero_iff.mpby_contra hwlet W := wronskian A Bhave we (i j : Fin 4) : wronskian (y i^2) (y j^2) = C (c j-c i)*W := byrw [hy,hy]simp [W,wronskian,derivative_add,derivative_mul] <;> ringhave nz (i : Fin 4) : y i ≠ 0 := byintro hhave he := congrArg (fun q : ℚ[X] => wronskian q B) (hy i)simp [h,wronskian,derivative_mul] at heapply hw; unfold wronskianlinear_combination -hehave co : Pairwise (fun i j => IsCoprime (y i) (y j)) := byintro i j hijapply isCoprime_of_dvd _ _ (fun h => nz i h.1)intro d hd _ hi hjhave hi' := dvd_pow hi (by decide : 2 ≠ 0)have hj' := dvd_pow hj (by decide : 2 ≠ 0)rw [hy] at hi' hj'obtain ⟨hda,hdb⟩ := common (hc.ne hij.symm) hi' hj'exact hd (hAB.isUnit_of_dvd' hda hdb)have hd (i : Fin 4) : y i ∣ W := byhave h : W = wronskian (y i^2) B := byrw [hy]; simp [W,wronskian,derivative_mul]; ringrw [h,wronskian,derivative_pow]use y i*derivative B-C 2*(y i).derivative*Bsimp; ringhave hp := natDegree_le_of_dvd (Fintype.prod_dvd_of_coprime co hd) hwrw [Polynomial.natDegree_prod _ _ (fun i _ => nz i)] at hpsimp only [Fin.sum_univ_four] at hphave upper (i j : Fin 4) (hij : i ≠ j) :W.natDegree < 2*(y i).natDegree+2*(y j).natDegree := byhave hne : c j-c i ≠ 0 := sub_ne_zero.mpr (hc.ne hij.symm)have h : wronskian (y i^2) (y j^2) ≠ 0 := byrw [we]; exact mul_ne_zero (C_ne_zero.mpr hne) hwhave hh := natDegree_wronskian_lt_add hrw [we,natDegree_C_mul hne,natDegree_pow,natDegree_pow] at hhsimpa [Nat.mul_comm] using hhhave he := upper 0 1 (by decide)have hf := upper 2 3 (by decide)change _ ≤ W.natDegree at hpomegaend SquarePencil