# Stable formula for a specific root of a depressed cubic

I have a cubic of the form $$x^3 - a x - b = 0$$ where $a, b > 0$. Thus, I know there is exactly one positive root.

Is there a nice stable formula for this unique positive root?

• This might mean the answer is no on the "nice" front: en.wikipedia.org/wiki/Casus_irreducibilis Apr 16 '13 at 23:24
• Casus irreducibilis is the case of three real roots, so this is not too applicable for you. Still, have you seen this? Apr 18 '13 at 11:56
• Yeah, I was aware of those, but somehow thought I'd need to compute all the roots and choose between them. Fortunately, although you do need to branch on whether all roots are real, exactly one of the three root formulas in the all real case is positive, so no need for further branching. I'll write this up as a solution unless you want to. Apr 18 '13 at 17:05
• I don't mind, go ahead. :) Apr 18 '13 at 17:06

## 2 Answers

As J.M. pointed out, the standard stable formulas for arbitrary cubics also work for this case, and happily they nicely simplify. The arbitrary formulas are given here.

In the special case of a depressed cubic $x^3 - ax - b = 0$ with linear and constant coefficients negative, let $Q = a/3$, $R = -q/2$. Then $Q > 0$, $R < 0$, and the unique positive root is given by $$x = \begin{cases} -2 \sqrt{Q} \cos{\frac{2\pi+\cos^{-1} {R/Q^{3/2}}}{3}} & \mbox{if } R^2 < Q^3 \\ A + \frac{Q}{A} & \mbox{if } R^2 \ge Q^3 \\ \end{cases}$$ where $$A = \left(-R + \sqrt{R^2 - Q^3} \right)^{1/3}$$ Note that the first case is always positive since $R/Q^{3/2} < 0$ so that $$\frac{\pi}{2} < \cos^{-1} \frac{R}{Q^{3/2}} < \pi,$$ eliminating the need to check through the other real roots (which are guaranteed to be negative).

I am not sure there is a stable formula, but given one that is numerically not stable, you could follow it by a single Newton step and improve the accuracy considerably

• Yes, there are various ways to do it with Newton's method that take advantage of the special form. In particular, the cubic is convex up after the positive root. However, I am specifically curious about formulae here. Apr 17 '13 at 20:41