Average Error: 33.9 → 9.8
Time: 10.1s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -9.91160972146253504 \cdot 10^{93}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.66666666666666663 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \le 3.86815523717705745 \cdot 10^{-95}:\\ \;\;\;\;\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \left(\left(\sqrt[3]{3} \cdot a\right) \cdot c\right)}}{a}}{3}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -9.91160972146253504 \cdot 10^{93}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} - 0.66666666666666663 \cdot \frac{b}{a}\\

\mathbf{elif}\;b \le 3.86815523717705745 \cdot 10^{-95}:\\
\;\;\;\;\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \left(\left(\sqrt[3]{3} \cdot a\right) \cdot c\right)}}{a}}{3}\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b}\\

\end{array}
double code(double a, double b, double c) {
	return ((-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a));
}
double code(double a, double b, double c) {
	double temp;
	if ((b <= -9.911609721462535e+93)) {
		temp = ((0.5 * (c / b)) - (0.6666666666666666 * (b / a)));
	} else {
		double temp_1;
		if ((b <= 3.8681552371770574e-95)) {
			temp_1 = (((-b + sqrt(((b * b) - ((cbrt(3.0) * cbrt(3.0)) * ((cbrt(3.0) * a) * c))))) / a) / 3.0);
		} else {
			temp_1 = (-0.5 * (c / b));
		}
		temp = temp_1;
	}
	return temp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if b < -9.911609721462535e+93

    1. Initial program 45.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Taylor expanded around -inf 3.7

      \[\leadsto \color{blue}{0.5 \cdot \frac{c}{b} - 0.66666666666666663 \cdot \frac{b}{a}}\]

    if -9.911609721462535e+93 < b < 3.8681552371770574e-95

    1. Initial program 12.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Using strategy rm
    3. Applied *-commutative12.5

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 3}}\]
    4. Applied associate-/r*12.6

      \[\leadsto \color{blue}{\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{a}}{3}}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt12.6

      \[\leadsto \frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(\color{blue}{\left(\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}\right)} \cdot a\right) \cdot c}}{a}}{3}\]
    7. Applied associate-*l*12.6

      \[\leadsto \frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{\left(\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \left(\sqrt[3]{3} \cdot a\right)\right)} \cdot c}}{a}}{3}\]
    8. Applied associate-*l*12.6

      \[\leadsto \frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \left(\left(\sqrt[3]{3} \cdot a\right) \cdot c\right)}}}{a}}{3}\]

    if 3.8681552371770574e-95 < b

    1. Initial program 52.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Taylor expanded around inf 9.2

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification9.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -9.91160972146253504 \cdot 10^{93}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.66666666666666663 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \le 3.86815523717705745 \cdot 10^{-95}:\\ \;\;\;\;\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \left(\left(\sqrt[3]{3} \cdot a\right) \cdot c\right)}}{a}}{3}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020066 +o rules:numerics
(FPCore (a b c)
  :name "Cubic critical"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3 a) c)))) (* 3 a)))