Sharedfirst_steps / solving-the-cubic.sagewsOpen in CoCalc
Step-by-step solution to the cubic equation with a worked example.
# We are working in the ring of polynomials in u, v, w over the ring Q[j] where j^3 = 1.
R.<x, u, v, w> = QQ[]
R.<j, u, v, w> = R.quo([x^3 - 1])
# Our goal is to solve for u, v, w in terms of a, b, c, given the following equations:
a = -(u + v + w)
b = (u*v + u*w + v*w)
c = - u*v*w
# We will first solve for the following:
f = j*u + j^2*v + w
g = j^2*u + j*v + w
# This is sufficient because we can use Gaussian elimination to solve for u, v, w in terms of a, f and g:
jj = (-1 + sqrt(3)*I)/2  # Unfortunately we can't do linear algebra with our symbolic j, so give it the complex value.
assert(jj^3 == 1)
M = matrix(3, 3, [-1,-1,-1, jj,jj^2,1, jj^2,jj,1])  # Rows are coefficients of a, f, g
# To solve for f and g we will have to solve for h and t:
h = f^3 + g^3
show(h)
3*j^2*u^2*v + 3*j^2*u*v^2 + 3*j^2*u^2*w + 3*j^2*v^2*w + 3*j^2*u*w^2 + 3*j^2*v*w^2 + 3*j*u^2*v + 3*j*u*v^2 + 3*j*u^2*w + 3*j*v^2*w + 3*j*u*w^2 + 3*j*v*w^2 + 2*u^3 + 2*v^3 + 12*u*v*w + 2*w^3
# Since h is homogenous of degree 3, in order to be a polynomial in a, b, c each monomial must be homogenous in degree 3.
# There are 3 such monomials:
show(a^3)
show(a*b)
show(c)
-u^3 - 3*u^2*v - 3*u*v^2 - v^3 - 3*u^2*w - 6*u*v*w - 3*v^2*w - 3*u*w^2 - 3*v*w^2 - w^3 -u^2*v - u*v^2 - u^2*w - 3*u*v*w - v^2*w - u*w^2 - v*w^2 -u*v*w
# Eliminating terms gives us.
show(h - (-2)*a^3)
show(h - (-2)*a^3 - (6 - 3*j - 3*j^2)*a*b)
show(h - (-2)*a^3 - (6 - 3*j - 3*j^2)*a*b - (-18 + 9*j + 9*j^2)*c)
assert(h == -2*a^3 + (6 - 3*j - 3*j^2)*a*b + (-18 + 9*j + 9*j^2)*c)
3*j^2*u^2*v + 3*j^2*u*v^2 + 3*j^2*u^2*w + 3*j^2*v^2*w + 3*j^2*u*w^2 + 3*j^2*v*w^2 + 3*j*u^2*v + 3*j*u*v^2 + 3*j*u^2*w + 3*j*v^2*w + 3*j*u*w^2 + 3*j*v*w^2 - 6*u^2*v - 6*u*v^2 - 6*u^2*w - 6*v^2*w - 6*u*w^2 - 6*v*w^2 -9*j^2*u*v*w - 9*j*u*v*w + 18*u*v*w
0\displaystyle 0
# Luckily t is much simpler:
t = f*g
show(t)
j^2*u*v + j^2*u*w + j^2*v*w + j*u*v + j*u*w + j*v*w + u^2 + v^2 + w^2
show(t - a^2)
j^2*u*v + j^2*u*w + j^2*v*w + j*u*v + j*u*w + j*v*w - 2*u*v - 2*u*w - 2*v*w
show(t - a^2 - (-2 + j + j^2)*b)
assert(t == a^2 + (-2 + j + j^2)*b)
0\displaystyle 0
# Let's work an example
y = var('y')
poly = y^3 - 3*y - 1
a = 0
b = -3
c = -1
h = -2*a^3 + (6 - 3*jj - 3*jj^2)*a*b + (-18 + 9*jj + 9*jj^2)*c
show(h)
t = a^2 + (-2 + jj + jj^2)*b
show(t)
9(12i312)292i3+452\displaystyle -9 \, {\left(\frac{1}{2} i \, \sqrt{3} - \frac{1}{2}\right)}^{2} - \frac{9}{2} i \, \sqrt{3} + \frac{45}{2}
3(12i312)232i3+152\displaystyle -3 \, {\left(\frac{1}{2} i \, \sqrt{3} - \frac{1}{2}\right)}^{2} - \frac{3}{2} i \, \sqrt{3} + \frac{15}{2}
729(12i312)2+7292i336452\displaystyle 729 \, {\left(\frac{1}{2} i \, \sqrt{3} - \frac{1}{2}\right)}^{2} + \frac{729}{2} i \, \sqrt{3} - \frac{3645}{2}
(272i3+272)13\displaystyle {\left(\frac{27}{2} i \, \sqrt{3} + \frac{27}{2}\right)}^{\frac{1}{3}}
f = ((h + sqrt(h^2 - 4*t^3)) / 2)^(1/3)
g = ((h - sqrt(h^2 - 4*t^3)) / 2)^(1/3)
show(f)
show(g)
solutions = (M \ vector([a, f, g])).simplify_rational()
u, v, w = solutions
show(u)
show(v)
show(w)
16(272i3+272)13(i3+1)16(i3+1)(272i3+272)13\displaystyle -\frac{1}{6} \, {\left(\frac{27}{2} i \, \sqrt{3} + \frac{27}{2}\right)}^{\frac{1}{3}} {\left(i \, \sqrt{3} + 1\right)} - \frac{1}{6} \, {\left(-i \, \sqrt{3} + 1\right)} {\left(-\frac{27}{2} i \, \sqrt{3} + \frac{27}{2}\right)}^{\frac{1}{3}}
16(272i3+272)13(i31)+16(i31)(272i3+272)13\displaystyle \frac{1}{6} \, {\left(\frac{27}{2} i \, \sqrt{3} + \frac{27}{2}\right)}^{\frac{1}{3}} {\left(i \, \sqrt{3} - 1\right)} + \frac{1}{6} \, {\left(-i \, \sqrt{3} - 1\right)} {\left(-\frac{27}{2} i \, \sqrt{3} + \frac{27}{2}\right)}^{\frac{1}{3}}
13(272i3+272)13+13(272i3+272)13\displaystyle \frac{1}{3} \, {\left(\frac{27}{2} i \, \sqrt{3} + \frac{27}{2}\right)}^{\frac{1}{3}} + \frac{1}{3} \, {\left(-\frac{27}{2} i \, \sqrt{3} + \frac{27}{2}\right)}^{\frac{1}{3}}
# Double-check that these are actually roots (up to the limits of Sage's precision).
show(poly(y = u).numerical_approx())
show(poly(y = v).numerical_approx())
show(poly(y = w).numerical_approx())
5.55111512312578×1016\displaystyle 5.55111512312578 \times 10^{-16}
1.77635683940025×1015\displaystyle 1.77635683940025 \times 10^{-15}
2.66453525910038×1015\displaystyle -2.66453525910038 \times 10^{-15}