Solving the cubic equation

While developing a graphical presentation of the Elliptic Curve function, I needed to discover how to find the roots of a cubic equation. There are two major solutions, one by Gerolamo Cardano, from 1545, and another based on trigonometry and de Moivre's theorem. The two solutions are needed for differing values of the coefficients in the equation. I have produced on online cubic equation solver that uses the techniques described below.

Cardano's solution

This exposition is based on Cardano and the Solution of the Cubic, by Bryan Dorsey, Kerry-Lyn Downie, and Marcus Huber (University of Kentucky), and Wikipedia, but showing the working that they left out.

Given an initial cubic equation:

$$a x^3 + b x^2 + c x + d = 0$$

we substitute $x = t - b / 3 a$ to get a reduced (or depressed) equation of the form: $t^3 + p t + q = 0$, where $p = (3 a c - b^2)/3a^2$ and $q = (2 b^3 - 9 a b c + 27 a^2 d)/27 a^3$.

$$ a \left( t - \frac{b}{3a}\right)^3 + b \left( t - \frac{b}{3a}\right)^2 + c \left( t - \frac{b}{3a}\right) + d = 0 \\ a \left( t^3 - 3 t^2 \left(\frac{b}{3a}\right) + 3 t \left(\frac{b}{3a}\right)^2 - \left(\frac{b}{3a}\right)^3 \right) + b \left( t^2 - 2 \frac{b}{3a}t + \left(\frac{b}{3a} \right)^2 \right) + c \left(t - \left(\frac{b}{3a}\right) \right) + d = 0 \\ a t^3 - b t^2 + \frac {b^2}{3 a} t - \frac{b^3}{27a^2} + b t^2 -2 \frac{b^2 t}{3a} +\frac{b^3}{9a^2} + c t - \frac{b c}{3a} + d = 0 \\ a t^3 + \left( \frac{b^2}{3 a} -2\frac{b^2}{3 a} + c \right) t - \frac{b^3}{27a^2} +\frac{b^3}{9a^2} - \frac{b c}{3 a} + d = 0 \\ t^3 + \left( \frac{b^2}{3 a^2} -2\frac{b^2}{3 a^2} + \frac{c}{a} \right) t - \frac{b^3}{27a^3} +\frac{b^3}{9a^3} - \frac{b c}{3 a^2} + \frac{d}{a} = 0 \\ t^3 + \frac{3 a c - b^2}{3 a^2} t + \frac{2 b^3 - 9 a b c +27 a^2 d}{27a^3} = 0 \\ \boxed{ t^3 + p t + q = 0 } $$

Then substitute $t = u + v$ to get: $$\begin{align} (u + v)^3 + p (u + v) + q &= 0 \\ u^3 +3 u^2 v + 3 u v^2 + v^3 + p (u + v) + q &= 0 \\ u^3 + v^3 + (3 u v + p)(u + v) + q &= 0 \end{align}$$

Now set $3 u v + p = 0$, giving $u v = -p/3$ and $u^3 + v^3 + q = 0$, to get:

$$\begin{align} u^3 + v^3 &= -q \\ u^3 v^3 &= - \left( \frac{p}{3} \right)^3 \end{align} $$

Substitute for $v^3$: $$ v^3 = -q - u^3 \\ (-q - u^3) u^3 = - \left( \frac{p}{3} \right)^3 \\ (q + u^3) u^3 - \left( \frac{p}{3} \right)^3 = 0 \\ u^6 + q u^3 - \left( \frac{p}{3} \right)^3 = 0 $$

Although this is a sextic equation in $u$, it is actually only quadratic in $u^3$, so we can use the standard quadratic solution: $$\begin{align} u^3 &= \frac{ - q \pm \sqrt{q^2 - 4 \left( - \frac{p}{3} \right)^3 }}{2} \\ &= -\frac{q}{2} \pm \sqrt{ \left( \frac{q}{2} \right)^2 + \left( \frac{p}{3} \right)^3 } \\ &= -\frac{q}{2} \pm \sqrt{ \Delta } \\ & \text{where } \Delta = \left( \frac{q}{2} \right) ^2 + \left( \frac{p}{3} \right) ^3 \end{align}$$

$\Delta$ is known as the discriminant for the equation. In other documents, the discriminant is sometimes multiplied by $27 \times 4$ to give $27 q^2 + 4 p^3$, and sometimes it is negated to give $-(27 q^2 + 4 p^3)$, so you have to be aware of the context before using it. The actual value is usually unimportant, as it is usually only the sign of the discriminant that is important for finding the expected number of real roots.

Since $u^3 + v^3 = - q$, we also have:

$$\begin{align} v^3 &= - q - u^3 \\ &= -q - \left( - \frac{q}{2} \pm \sqrt{ \Delta } \right) \\ &= -\frac{q}{2} \mp \sqrt{ \Delta } \end{align}$$

Since $t = u + v$, Cardano's solution is now:

$$\ \boxed{ t_0 = \sqrt[3]{- \frac{q}{2}+\sqrt{\Delta}} + \sqrt[3]{ - \frac{q}{2}-\sqrt{\Delta}}} $$

This result is only valid when the square root of the discriminant can be taken; that is, when $\Delta \geq 0$.

Show that Cardano's solution is a root

When we substitute the above result for $t_0$ into the original (reduced) equation, we get:

$$\begin{align} t_0^3 + p t_0 + q = &\left( \sqrt[3]{ -\frac{q}{2}+\sqrt{\Delta}} + \sqrt[3]{ -\frac{q}{2}-\sqrt{\Delta}} \right)^3 + p \left( \sqrt[3]{ -\frac{q}{2}+\sqrt{\Delta}} + \sqrt[3]{ -\frac{q}{2}-\sqrt{\Delta}} \right) + q \\ \text{Expand using the binomial expansion: } (A + B)^3 = A^3 + 3 A^2 B + 3 A B^2 + B^3 \\ = &\left( -\frac{q}{2}+\sqrt{\Delta} \right) + 3 \left( \sqrt[3]{-\frac{q}{2}+\sqrt{\Delta} } \right)^2 \left( \sqrt[3]{-\frac{q}{2}-\sqrt{\Delta} } \right) + 3 \left( \sqrt[3]{-\frac{q}{2}+\sqrt{\Delta} } \right) \left( \sqrt[3]{-\frac{q}{2}-\sqrt{\Delta} } \right)^2 \\ &+ \left( -\frac{q}{2}-\sqrt{\Delta} \right) + p \left( \sqrt[3]{-\frac{q}{2}+\sqrt{\Delta}} + \sqrt[3]{-\frac{q}{2}-\sqrt{\Delta}} \right) + q \\ \text{The unrooted terms in } q \text{ cancel out.} \\ = & 3 \left( \sqrt[3]{-\frac{q}{2}+\sqrt{\Delta} } \right)^2 \left( \sqrt[3]{-\frac{q}{2}-\sqrt{\Delta} } \right) + 3 \left( \sqrt[3]{-\frac{q}{2}+\sqrt{\Delta} } \right) \left( \sqrt[3]{-\frac{q}{2}-\sqrt{\Delta} } \right)^2 + p \left( \sqrt[3]{-\frac{q}{2}+\sqrt{\Delta} } + \sqrt[3]{-\frac{q}{2}-\sqrt{\Delta} } \right) \\ \text{Bring the power terms inside the roots: } (\sqrt[3]{A})^2 \sqrt[3]{B} = \sqrt[3]{A^2 B} \\ = & 3 \sqrt[3]{\left(-\frac{q}{2}+\sqrt{\Delta} \right)^2 \left(-\frac{q}{2}-\sqrt{\Delta} \right) } + 3 \sqrt[3]{\left(-\frac{q}{2}+\sqrt{\Delta} \right) \left(-\frac{q}{2}-\sqrt{\Delta} \right)^2 } + p \left(\sqrt[3]{-\frac{q}{2}+\sqrt{\Delta}} + \sqrt[3]{-\frac{q}{2}-\sqrt{\Delta}} \right) \\ \text{Using the “difference of squares” identity: } (A + B)(A - B) = A^2 - B^2 \\ = & 3 \sqrt[3]{\left(-\frac{q}{2}+\sqrt{\Delta} \right) \left( \left( \frac{q}{2} \right)^2 -\Delta \right) } + 3 \sqrt[3]{\left( \left( \frac{q}{2} \right)^2 -\Delta \right) \left(-\frac{q}{2}-\sqrt{\Delta} \right) } + p \left(\sqrt[3]{-\frac{q}{2}+\sqrt{\Delta}} + \sqrt[3]{-\frac{q}{2}-\sqrt{\Delta}} \right) \\ \text{By definition of } \Delta \text{: } (q/2)^2 - \Delta =(-p/3)^3 \\ = & 3 \sqrt[3]{\left(-\frac{q}{2}+\sqrt{\Delta} \right) \left( \frac{-p}{3} \right)^3 } + 3 \sqrt[3]{ \left( \frac{-p}{3} \right)^3 \left(-\frac{q}{2}-\sqrt{\Delta} \right) } + p \left(\sqrt[3]{-\frac{q}{2}+\sqrt{\Delta}} + \sqrt[3]{-\frac{q}{2}-\sqrt{\Delta}} \right) \\ \text{Bring the cubed terms outside the roots: } \\ = & 3 \left(\frac{-p}{3} \right) \sqrt[3]{\left(-\frac{q}{2}+\sqrt{\Delta} \right) } + 3 \left(\frac{-p}{3} \right) \sqrt[3]{\left(-\frac{q}{2}-\sqrt{\Delta} \right) } + p \left(\sqrt[3]{-\frac{q}{2}+\sqrt{\Delta}} + \sqrt[3]{-\frac{q}{2}-\sqrt{\Delta}} \right) \\ = & - p \sqrt[3]{\left(-\frac{q}{2}+\sqrt{\Delta} \right) } - p \sqrt[3]{\left(-\frac{q}{2}-\sqrt{\Delta} \right) } + p \left(\sqrt[3]{-\frac{q}{2}+\sqrt{\Delta}} + \sqrt[3]{-\frac{q}{2}-\sqrt{\Delta}} \right) \\ = & - p \left(\sqrt[3]{-\frac{q}{2}+\sqrt{\Delta}} + \sqrt[3]{-\frac{q}{2}-\sqrt{\Delta}} \right) + p \left(\sqrt[3]{-\frac{q}{2}+\sqrt{\Delta}} + \sqrt[3]{-\frac{q}{2}-\sqrt{\Delta}} \right) \\ = & 0 \end{align}$$

This confirms that the Cardano formula is indeed a root.

The other two roots

The above process obtains the major root of the cubic equation, but there are two other roots. These are real if $\Delta \leq 0$, but complex if $\Delta > 0$. When $\Delta = 0$ at least two of the real roots are equal. The easiest way to find these roots is with a trigonometric identity and de Moivre's theorem. This is described in Solving the Cubic Equation and Roots of Polynomials. Solution of Cubic Equation with Three Real Roots by Henry Baker explains the trigonometry and has a nice animated GIF to show it graphically.

Multiple roots from Cardano's solution

The exposition of Cardano's solution arrives at a single root, because Cardano was unaware of complex numbers. When complex numbers are allowed, the two additional roots can be derived. When the values for $u$ and $v$ were derived earlier, it was tacitly assumed that the cube roots of $u^3$ and $v^3$ were just $u$ and $v$ respectively. But, when complex numbers are allowed, there are three possible cube roots, which are multiples of the three cube roots of one. These are the following, where $i = \sqrt{-1}$, as usual:

$$ \sqrt[3]{1} = \begin{cases} 1 \\ \frac{- 1 - \sqrt{3} i}{2} \\ \frac{- 1 + \sqrt{3} i}{2} \\ \end{cases} $$

So, for when calculating the values for $u$ and $v$ earlier, we should use: $$\begin{align} u_0 &= \sqrt[3]{- \frac{q}{2}+\sqrt{\Delta}} \\ u_1 &= \frac{- 1 - \sqrt{3} i}{2} \sqrt[3]{- \frac{q}{2}+\sqrt{\Delta}} \\ u_2 &= \frac{- 1 + \sqrt{3} i}{2} \sqrt[3]{- \frac{q}{2}+\sqrt{\Delta}} \\ v_0 &= \sqrt[3]{- \frac{q}{2}-\sqrt{\Delta}} \\ v_1 &= \frac{- 1 - \sqrt{3} i}{2} \sqrt[3]{- \frac{q}{2}-\sqrt{\Delta}} \\ v_2 &= \frac{- 1 + \sqrt{3} i}{2} \sqrt[3]{- \frac{q}{2}-\sqrt{\Delta}} \\ \end{align} $$

The values of $u_1$ and $u_2$ cannot be combined arbitrarily with those of $v_1$ and $v_2$ however. The $u$ and $v$ pairs must also meet the condition $3 u v + p = 0$, or $u v = -p/3$. First try $u_1$ and $v_1$: $$\begin{align} u_1 v_1 &= \frac{- 1 - \sqrt{3} i}{2} \sqrt[3]{- \frac{q}{2}+\sqrt{\Delta}} \cdot \frac{- 1 - \sqrt{3} i}{2} \sqrt[3]{- \frac{q}{2}-\sqrt{\Delta}} \\ &= \left( \frac{1 + \sqrt{3} i}{2} \right)^2 \sqrt[3]{ \left( - \frac{q}{2}+\sqrt{\Delta}\right) \left( - \frac{q}{2}-\sqrt{\Delta} \right) } \\ &= \left( \frac{1 + \sqrt{3} i}{2} \right)^2 \sqrt[3]{ \left(\frac{q}{2}\right)^2 - \Delta } \\ &= \left( \frac{1 + \sqrt{3} i}{2} \right)^2 \sqrt[3]{ \left( - \frac{p}{3}\right)^3 } \\ &= - \left( \frac{1 + 2 \sqrt{3} i - 3}{4} \right) \sqrt[3]{ \left(\frac{p}{3}\right)^3 } \\ &= \left( \frac{1- \sqrt{3} i}{2} \right) \left( \frac{p}{3} \right) \end{align}$$

This is obviously not equal the required $-p/3$, so let us try $u_1$ and $v_2$; $$\begin{align} u_1 v_2 &= \frac{- 1 - \sqrt{3} i}{2} \sqrt[3]{- \frac{q}{2}+\sqrt{\Delta}} \cdot \frac{- 1 + \sqrt{3} i}{2} \sqrt[3]{- \frac{q}{2}-\sqrt{\Delta}} \\ &= \frac{- 1 - \sqrt{3} i}{2} \cdot \frac{- 1 + \sqrt{3} i}{2} \sqrt[3]{\left(- \frac{q}{2}+\sqrt{\Delta}\right) \left(- \frac{q}{2}-\sqrt{\Delta}\right)} \\ &= \frac{1 + 3}{4} \sqrt[3]{\left(\frac{q}{2} \right)^2 - \Delta} \\ &= \sqrt[3]{ \left(-\frac{p}{3}\right)^3 } \\ &= - \frac{p}{3} \end{align}$$

Thus the two additional complex roots of the reduced equation are:

$$\begin{align} t_1 &= u_1 + v_2 = \frac{- 1 - \sqrt{3} i}{2} \sqrt[3]{- \frac{q}{2}+\sqrt{\Delta}} + \frac{- 1 + \sqrt{3} i}{2} \sqrt[3]{- \frac{q}{2}-\sqrt{\Delta}} \\ t_2 &= u_2 + v_1 = \frac{- 1 + \sqrt{3} i}{2} \sqrt[3]{- \frac{q}{2}+\sqrt{\Delta}} + \frac{- 1 - \sqrt{3} i}{2} \sqrt[3]{- \frac{q}{2}-\sqrt{\Delta}} \end{align}$$

These roots are complex when $\Delta \gt 0$, since $\sqrt{\Delta}$ is real. Notice that the coefficients of $i$ in the expressions for $t_1$ and $t_2$ are equal and opposite in sign, so the roots are complex conjugates.

There is another way of demonstrating that $u_1+v_1$ is not a valid root, but that $u_1+v_2$ is valid, which is based on the requirement that the imaginary part of the reduced expression must be zero, but it is even more long-winded, so I have hidden it. If you really want to see it, press .

The trigonometric solution

The trigonometric solution depends of the triple angle trigonometric identity:

$$\cos ( 3 \theta) = 4 \cos^3 \theta - 3 \cos \theta \text{, or } \\ 4 \cos^3 \theta - 3 \cos \theta - cos(3 \theta) = 0 $$

As the Henry Baker paper states, this is a bit of a deus ex machina, or something up my sleeve, which we will have to take on trust, for now (but will be proved later). If we set $t = \lambda \cos \theta$ in the reduced equation: $$\begin{align} t^3 + p t + q &= 0 \\ (\lambda \cos \theta)^3 + p (\lambda \cos \theta) + q &= 0 \\ \lambda^3 \cos^3 \theta + p \lambda \cos \theta + q &= 0 \\ 4 \lambda^3 \cos^3 \theta + 4 p \lambda \cos \theta + 4 q &= 0 \\ 4 \cos^3 \theta + \frac{4 p}{\lambda^2} \cos \theta + \frac{4 q} {\lambda^3} &= 0 \\ \text{Now set } 4 p/\lambda^2 = - 3 \text{, or } \lambda = \sqrt{- \frac{4 p}{3}} \text{, to get:} \\ 4 \cos^3 \theta + 3 \cos \theta + \frac{4 q} {\left(\sqrt{- \frac{4 p}{3}} \right)^3} &= 0 \\ 4 \cos^3 \theta + 3 \cos \theta + \frac{4 q} {\sqrt{- (\frac{4 p}{3})^3}} &= 0 \\ 4 \cos^3 \theta + 3 \cos \theta + \frac{4q} {(\frac{4 p}{3}) \sqrt{- (\frac{4 p}{3}) }} &= 0 \\ 4 \cos^3 \theta + 3 \cos \theta + \frac{q} {( \frac{p}{3}) \sqrt{- (\frac{4 p}{3}) }} &= 0 \\ 4 \cos^3 \theta + 3 \cos \theta + \frac{q} {( \frac{2 p}{3}) \sqrt{- \frac{p}{3} }} &= 0 \\ 4 \cos^3 \theta + 3 \cos \theta + \frac{3 q}{2 p}\sqrt{-\frac{3}{p}} &= 0 \\ \end{align}$$

This is equivalent to the triple angle identity if:

$$\begin{align} \cos ( 3 \theta ) & = \frac{3 q}{2 p} \sqrt{ - \frac{3}{p}} \end{align}$$

Now, for any angle $\alpha$,

$$\begin{align} \cos ( 3 \alpha ) & = \cos (3 \alpha + \tau ) = \cos (3 ( \alpha + \tau / 3)) \\ & = \cos (3 \alpha + 2 \tau ) = \cos (3 ( \alpha + 2 \tau / 3)) \\ & \quad \text{ where } \tau \text{ is } \href{http://www.tauday.com/tau-manifesto}{\text{one turn}} \text{, also known as } 2 \pi . \end{align}$$

So we can say: $$\begin{align} 3 \theta & = \arccos \left( \frac{3 q}{2 p} \sqrt{ - \frac{3}{p}} \right) - k \tau \text{, for } k = 0,1,2 \\ \theta & = \frac{1}{3} \arccos \left( \frac{3 q}{2 p} \sqrt{ - \frac{3}{p}} \right) - k \tau / 3 \text{, for } k = 0,1,2 \\ \end{align}$$

Recall that we had originally set $t = \lambda \cos \theta$. Substituting for $\lambda$ and $\theta$ gives the three real roots: $$ \boxed{t_k = \sqrt{- \frac{4 p}{3}} \cos \left( \frac{1}{3} \arccos \left( \frac{3 q}{2 p} \sqrt{ - \frac{3}{p}} \right) - \frac{k \tau}{3} \right) \text{ for } k = 0,1,2 } $$

This is only valid when the argument of the $\arccos$ function lies within the range $ [ -1, +1 ] $: $$ -1 \leq \frac{3 q}{2 p} \sqrt{ - \frac{3}{p}} \leq + 1 \\ -1 \leq \sqrt{ - \frac{27 q^2 }{4 p^3} } \leq + 1 $$

The value within the square root must be positive, so, since $q^2$ is positive, $p$ (and $p^3$) must be negative. $$ 0 \leq - \frac{27 q^2 }{4 p^3} \leq 1 $$

Multiply by $-4 p^3 $, which is positive, so preserves the direction of the inequality:

$$ 0 \leq 27 q^2 \leq - 4 p^3 $$

Divide by $27 \times 4$:

$$ 0 \leq \frac{q^2}{4} \leq -\frac{p^3}{27} $$

Add $p^3/27$:

$$ \frac{p^3}{27} \leq \frac{q^2}{4} + \frac{p^3}{27} \leq 0 \\ \left( \frac{p}{3} \right)^3 \leq \left( \frac{q}{2} \right)^2 + \left( \frac{p}{3} \right)^3 \leq 0 $$

The final inequality is just a restatement of the discriminant condition: $\Delta \leq 0$: $$ \left( \frac{q}{2} \right)^2 + \left( \frac{p}{3} \right)^3 \leq 0 $$

Derivation of the triple angle identity

The triple angle identity can be obtained from de Moivre's theorem, using complex algebra:

$$\begin{align} \cos ( 3 \theta ) &= \frac{1}{2} ( e^{3 i \theta} + e^{-3 i \theta}) \\ &= \frac{1}{2} (( \cos \theta + i \sin \theta )^3 + ( \cos \theta - i \sin \theta )^3 ) \\ &= \frac{1}{2} ( ( \cos^3 \theta + 3 i cos^2 \theta \sin \theta + 3 i^2 \cos \theta \sin^2 \theta + i^3 \sin^3 \theta ) + ( \cos^3 \theta - 3 i cos^2 \theta \sin \theta + 3 i^2 \cos \theta \sin^2 \theta - i^3 \sin^3 \theta ) ) \\ &= \frac{1}{2} ( ( \cos^3 \theta + 3 i cos^2 \theta \sin \theta - 3 \cos \theta \sin^2 \theta - i \sin^3 \theta ) + ( \cos^3 \theta - 3 i cos^2 \theta \sin \theta - 3 \cos \theta \sin^2 \theta + i \sin^3 \theta ) ) \\ &= \frac{1}{2} ( 2 \cos^3 \theta - 6 \cos \theta \sin^2 \theta ) \\ &= \cos^3 \theta - 3 \cos \theta \sin^2 \theta \\ &= 4 \cos^3 \theta - 3 ( \cos^3 \theta + \cos \theta \sin^2 \theta ) \\ &= 4 \cos^3 \theta - 3 ( \cos \theta (\cos^2 \theta + \sin^2 \theta )) \\ &= 4 \cos^3 \theta - 3 \cos \theta \end{align}$$

A simple example

To see how this works in practice, let's consider a simple cubic whose roots we already know. Now:

$$(x-1)(x-2)(x-3) = 0$$

obviously has three real roots. They are actually integers: $x= 1 , 2, 3$.

Written out in full, the equation becomes:

$$(x-1)(x^2 - 5 x + 6) = 0 \\ x^3 - 5 x^2 +6 x -x^2 + 5 x - 6 = 0 \\ x^3 -6 x^2 + 11 x - 6 =0\\ \text{ or } (x^2 - 3 x +2)(x - 3) = 0 \\ x^3 -3 x^2 +2 x -3 x^2 +9 x - 6 = 0 \\ x^3 -6 x^2 +11 x - 6 = 0 $$

This is the standard form (not reduced) with $a = 1, b = -6, c = 11, d = -6$. To obtain the reduced form, substitute $p = (3 a c - b^2)/3a^2$ and $q = (2 b^3 - 9 a b c + 27 a^2 d)/27 a^3$. So: $$\begin{align} p &= (3 \times 1 \times 11 - (-6)^2 ) / (3 \times 1^2 ) \\ &= (33 - 36) / 3 \\ &= - 1 \\ q &= (2 \times (-6)^3 - 9 \times 1 \times (-6) \times 11 + 27 \times 1^2 \times (-6) ) / (27 \times 1^3) \\ &= (2 \times (-216) + 594 - 162) / 27 \\ &= (-432 + 594 -162) / 27 \\ &= 0 / 27 \\ &= 0 \end{align} $$

So the reduced equation is:

$$t^3 - t = 0$$

Recall that we had substituted $x = t - b / 3 a$, or $t = x + b/ 3 a = x + (-6) / (3 \times 1) = x -2$, so the equation in $x$ becomes, as expected:

$$\begin{align} (x -2)^3 -(x-2) + 0 &= 0 \\ x^3 -6x^2 +12 x - 8 -x +2 &= 0 \\ x^3 -6 x^2 +11 x -6 &= 0 \end{align}$$

The discriminant is $\Delta = p^3/27 + q^2/4 = (-1)^3/27 + (0)^2/4 = -1/27$. As expected, this is negative, so there are three real roots. We can factorise the expression in $t$ as:

$$t (t^2-1) = t(t-1)(t+1) = 0$$ whose roots are obviously $t = 0, +1, -1$. But, by applying the trigonometic formula for $t$, we should use: $$\begin{align} t_k &=\sqrt{- \frac{4 p}{3}} \cos \left( \frac{1}{3} \arccos \left( \frac{3 q}{2 p} \sqrt{ - \frac{3}{p}} \right) - \frac{k \tau}{3} \right) \text{ for } k = 0,1,2 \\ &= \sqrt{- \frac{4\times(-1)}{3}} \cos \left( \frac{1}{3} \arccos \left( \frac{3 \times 0}{2\times(-1)} \sqrt{ - \frac{3}{(-1)}} \right) - \frac{k \tau}{3} \right) \text{ for } k = 0,1,2 \\ &= \sqrt{\frac{4}{3}} \cos \left( \frac{1}{3} \arccos (0) - \frac{k \tau}{3} \right) \text{ for } k = 0,1,2 \\ &= \sqrt{\frac{4}{3}} \cos \left( \frac{1}{3} \left( \frac{\tau}{4} \right) - \frac{k \tau}{3} \right) \text{ for } k = 0,1,2 \\ &= \sqrt{\frac{4}{3}} \cos \left( \frac{1}{3} \left( \frac{360^\circ}{4} \right) - \frac{k \times 360^\circ}{3} \right) \text{ for } k = 0,1,2 \\ &= \begin{cases} \sqrt{\frac{4}{3}} \cos(30^\circ) \\ \sqrt{\frac{4}{3}} \cos(150^\circ) \\ \sqrt{\frac{4}{3}} \cos(270^\circ) \\ \end{cases} \\ &= \begin{cases} \sqrt{\frac{4}{3}} \times \sqrt{\frac{3}{4}} \\ \sqrt{\frac{4}{3}} \times (- \sqrt{\frac{3}{4}}) \\ \sqrt{\frac{4}{3}} \times 0 \\ \end{cases} \\ &= \begin{cases} 1 \\ -1 \\ 0 \\ \end{cases} \end{align} $$

We recover the values for $x$ using the original substitution, giving: $$\begin{align} x &= t - b / 3 \text{ for } b = -6, t = -1, 0, 1 \\ &= \begin{cases} -1 & - (-6)/3 \\ 0 & - (-6)/3 \\ +1 & - (-6)/3 \\ \end{cases} \\ &= \begin{cases} 1 \\ 2 \\ 3 \\ \end{cases} \end{align}$$

So in a very roundabout and convoluted way, we have recovered the roots $x = 1,2,3$.