-- Monic real cubics and conjugation: a root p + q√d of a cubic over F -- with √d ∉ F has the conjugate root p − q√d, two distinct roots give the -- third by Vieta, and a root in F(√d) descends to a root in F. -- Part of Cumulus, the Grace17 mathematics library. -- Copyright (c) 2026 Grant Passmore. -- Released under the Apache License 2.0. See LICENSE in the repository root. -- Authors: Grant Passmore module Grace.Cumulus.Algebra.Field.CubicConjugation import Grace.Cumulus.Algebra.Field.QuadraticAdjoin -- The cubic -- The monic cubic x³ + a x² + b x + c, with the cube written as a product -- so that ring normalizes it. def cubic (a b c x : Real) : Real := x * x * x + a * (x * x) + b * x + c theorem cubic.real (a b c x : Real) shows Real(cubic(a, b, c, x)) proof unfold cubic typecheck instance cubic.mem (F : Set) (a b c x : Real) requires field : RealSubfield(F) requires aIn : a ∈ F requires bIn : b ∈ F requires cIn : c ∈ F requires xIn : x ∈ F shows cubic(a, b, c, x) ∈ F proof unfold cubic typecheck -- Vieta and conjugation -- Vieta for two distinct roots. The certificate is -- (r − s) · cubic(−a − r − s) = (−a − 2s − r) · cubic(r) -- − (−a − 2r − s) · cubic(s), -- a ring identity, after which r − s cancels. theorem cubic.third_root (a b c r s : Real) requires rootR : cubic(a, b, c, r) = 0 requires rootS : cubic(a, b, c, s) = 0 requires distinct : r ≠ s shows cubic(a, b, c, -a - r - s) = 0 proof have difference : r - s ≠ 0 intro zero apply distinct linarith have cancel : (r - s) * cubic(a, b, c, -a - r - s) = 0 unfold cubic at rootR unfold cubic at rootS unfold cubic linear_combination (-a - (2:R) * s - r) * rootR - (-a - (2:R) * r - s) * rootS rcases realMulValue.eq_zero_or with cancel with zero | root . exfalso exact difference with zero . exact root -- The value at p ± q√d splits as U ± V√d with U, V polynomial in -- a, b, c, p, q, d: ring after sqrt.square. theorem cubic.split (a b c d p q : Real) requires dNonneg : (0:R) ≤ d shows cubic(a, b, c, p + q * √d) = (p * p * p + (3:R) * p * (q * q) * d + a * (p * p + q * q * d) + b * p + c) + ((3:R) * (p * p) * q + q * q * q * d + (2:R) * a * p * q + b * q) * √d ∧ cubic(a, b, c, p - q * √d) = (p * p * p + (3:R) * p * (q * q) * d + a * (p * p + q * q * d) + b * p + c) - ((3:R) * (p * p) * q + q * q * q * d + (2:R) * a * p * q + b * q) * √d proof have nonnegative := NonnegativeReal.of_le with dNonneg have square := sqrt.square at d with nonnegative constructor . unfold cubic linear_combination ((3:R) * p * (q * q) + q * q * q * √d + a * (q * q)) * square . unfold cubic linear_combination ((3:R) * p * (q * q) - q * q * q * √d + a * (q * q)) * square -- U + V√d = 0 with U, V ∈ F and √d ∉ F forces U = V = 0, so U − V√d = 0. theorem cubic.conjugate_root (F : Set) (d a b c p q : Real) requires field : RealSubfield(F) requires dIn : d ∈ F requires dNonneg : (0:R) ≤ d requires rootOut : √d ∉ F requires aIn : a ∈ F requires bIn : b ∈ F requires cIn : c ∈ F requires pIn : p ∈ F requires qIn : q ∈ F requires root : cubic(a, b, c, p + q * √d) = 0 shows cubic(a, b, c, p - q * √d) = 0 proof obtain ⟨plus, minus⟩ := cubic.split at a, b, c, d, p, q with dNonneg have constantIn : p * p * p + (3:R) * p * (q * q) * d + a * (p * p + q * q * d) + b * p + c ∈ F typecheck have rootCoefficientIn : (3:R) * (p * p) * q + q * q * q * d + (2:R) * a * p * q + b * q ∈ F typecheck rw plus at root obtain ⟨constantZero, rootCoefficientZero⟩ := adjoinSqrt.coefficients_unique with field, dNonneg, rootOut, constantIn, rootCoefficientIn, root rw [minus, constantZero, rootCoefficientZero] ring -- Descent through one square root -- r = p + q√d. If q = 0 or √d ∈ F then r ∈ F; otherwise the conjugate is -- a distinct root and the third root −a − 2p lies in F. theorem cubic.root_descends (F : Set) (d a b c r : Real) requires field : RealSubfield(F) requires dIn : d ∈ F requires dNonneg : (0:R) ≤ d requires aIn : a ∈ F requires bIn : b ∈ F requires cIn : c ∈ F requires rIn : r ∈ adjoinSqrt(F, d) requires root : cubic(a, b, c, r) = 0 shows ∃ s ∈ F, cubic(a, b, c, s) = 0 proof obtain ⟨p, pIn, q, qIn, same⟩ := adjoinSqrt.cases with dNonneg, rIn have realP := RealSubfield.real with field, pIn have realQ := RealSubfield.real with field, qIn have zeroIn := RealSubfield.zero_mem with field by_cases rootIn : √d ∈ F . have rInF : r ∈ F rw same typecheck exact ⟨r, rInF, root⟩ . by_cases qZero : (q:R) = 0 . have value : r = p rw [same, qZero] ring rw value at root exact ⟨p, pIn, root⟩ . have rootPlus : cubic(a, b, c, (p:R) + (q:R) * √d) = 0 by rwa same at root have rootMinus := cubic.conjugate_root with field, dIn, dNonneg, rootIn, aIn, bIn, cIn, pIn, qIn, rootPlus have rootNonzero : √d ≠ 0 intro zero apply rootIn rw zero exact zeroIn have distinct : (p:R) + (q:R) * √d ≠ (p:R) - (q:R) * √d intro equal have product : (q:R) * √d = 0 by linarith rcases realMulValue.eq_zero_or with product with qIsZero | rootIsZero . exact qZero with qIsZero . exact rootNonzero with rootIsZero have third := cubic.third_root with rootPlus, rootMinus, distinct have value : -a - ((p:R) + (q:R) * √d) - ((p:R) - (q:R) * √d) = -a - (2:R) * (p:R) ring rw value at third have thirdIn : -a - (2:R) * (p:R) ∈ F by typecheck exact ⟨-a - (2:R) * (p:R), thirdIn, third⟩