# Finding the solution for the cubic formula over NonNegativeReals

The standard cubic polynomial is: $$ax^3+bx^2+cx + d$$.

And when I used my function:

piecewiseForm[equation_,solvingVariable_,domain_]:=
solutions = Solve[equation, solvingVariable, domain];
radicalSolutions = ToRadicals[Normal @ x /. solutions];
piecewiseList = Piecewise[Table[
]];
]


with:

piecewiseForm[a*x^3+b*x^2+c*x+d==0,x,Reals]


I got:

$$\begin{cases} -\frac{b}{3 a}+\frac{\sqrt[3]{-2 b^3+9 a c b-27 a^2 d+\sqrt{4 \left(3 a c-b^2\right)^3+\left(-2 b^3+9 a c b-27 a^2 d\right)^2}}}{3 \sqrt[3]{2} a}-\frac{\sqrt[3]{2} \left(3 a c-b^2\right)}{3 a \sqrt[3]{-2 b^3+9 a c b-27 a^2 d+\sqrt{4 \left(3 a c-b^2\right)^3+\left(-2 b^3+9 a c b-27 a^2 d\right)^2}}} & \left(3 a-\frac{b^2}{c}>0\land c>0\right)\lor \left(3 a-\frac{b^2}{c}>0\land c<0\land \frac{2 b^3}{a^2}-\frac{9 c b}{a}+27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\land -\frac{2 b^3}{a^2}+\frac{9 c b}{a}-27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\right)\lor \left(3 a-\frac{b^2}{c}>0\land c<0\land \frac{2 b^3}{a^2}-\frac{9 c b}{a}+27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}<0\right)\lor \left(3 a-\frac{b^2}{c}>0\land c<0\land -\frac{2 b^3}{a^2}+\frac{9 c b}{a}-27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}<0\right)\lor \left(3 a-\frac{b^2}{c}<0\land c>0\land \frac{2 b^3}{a^2}-\frac{9 c b}{a}+27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\land -\frac{2 b^3}{a^2}+\frac{9 c b}{a}-27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\right)\lor \left(3 a-\frac{b^2}{c}<0\land c>0\land \frac{2 b^3}{a^2}-\frac{9 c b}{a}+27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}<0\right)\lor \left(3 a-\frac{b^2}{c}<0\land c>0\land -\frac{2 b^3}{a^2}+\frac{9 c b}{a}-27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}<0\right)\lor \left(3 a-\frac{b^2}{c}<0\land c<0\right) \\ -\frac{b}{3 a}-\frac{\left(1-i \sqrt{3}\right) \sqrt[3]{-2 b^3+9 a c b-27 a^2 d+\sqrt{4 \left(3 a c-b^2\right)^3+\left(-2 b^3+9 a c b-27 a^2 d\right)^2}}}{6 \sqrt[3]{2} a}+\frac{\left(1+i \sqrt{3}\right) \left(3 a c-b^2\right)}{3\ 2^{2/3} a \sqrt[3]{-2 b^3+9 a c b-27 a^2 d+\sqrt{4 \left(3 a c-b^2\right)^3+\left(-2 b^3+9 a c b-27 a^2 d\right)^2}}} & \left(3 a-\frac{b^2}{c}>0\land \frac{2 b^3}{a^2}-\frac{9 c b}{a}+27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\land -\frac{2 b^3}{a^2}+\frac{9 c b}{a}-27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\land c<0\right)\lor \left(3 a-\frac{b^2}{c}<0\land \frac{2 b^3}{a^2}-\frac{9 c b}{a}+27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\land -\frac{2 b^3}{a^2}+\frac{9 c b}{a}-27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\land c>0\right) \end{cases}$$

but when I try:

piecewiseForm[a*x^3+b*x^2+c*x+d==0,x,NonNegativeReals]

I just get $$0$$ and even:

Solve[a*x^3+b*x^2+c*x+d==0,x,NonNegativeReals]


gives: $$\{\}$$

but I know there are obviously non-negative solutions for the general cubic polynomial. How do I find this formula using Mathematica?

• solutions = equation, solvingVariable, domain] is wrong syntax. Jan 22 at 16:34
• I will correct it right now. Sorry. Jan 22 at 16:36
• LogicalExpand[Reduce[a*x^3+b*x^2+c*x+d==0&&x>=0,x,Reals]] and LogicalExpand[Simplify[Reduce[a*x^3+b*x^2+c*x+d==0&&x>=0,x,Reals]]] reduces the size by 25% at the cost making the result less explicit for x in some cases. Maybe you can eliminate some cases that you consider not interesting and find the solution you are looking for in that.
– Bill
Jan 22 at 16:37
• Thanks. I want it to be an explicit piecewise function for personal reasons. I didn't know about LogicalExpand though. Thanks. Jan 22 at 16:42
• See NeatExamples at resources.wolframcloud.com/FunctionRepository/resources/… and you will see that function used on this problem. Jan 22 at 17:50

\$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global*"]

sol1 = Assuming[
x ∈ NonNegativeReals && {a, b, c, d} ∈ Reals,
SolveValues[a*x^3 + b*x^2 + c*x + d == 0, x] // ToRadicals //
Simplify]


sol2 = Piecewise[List @@@ sol1]
`

• It worked for Mathematica Online as well. Jan 22 at 19:56