Average Error: 34.2 → 10.0
Time: 13.8s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -7.518753900645323 \cdot 10^{+128}:\\ \;\;\;\;\frac{\left(-b\right) - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 7.17628680422661 \cdot 10^{-166}:\\ \;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(a \cdot c, -3, b \cdot b\right)} - b}{3}}{a}\\ \mathbf{elif}\;b \leq 6606110945.941845:\\ \;\;\;\;\frac{\frac{3 \cdot \left(a \cdot c\right)}{\left(-b\right) - \mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right)}}{3 \cdot a}\\ \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 \leq -7.518753900645323 \cdot 10^{+128}:\\
\;\;\;\;\frac{\left(-b\right) - b}{3 \cdot a}\\

\mathbf{elif}\;b \leq 7.17628680422661 \cdot 10^{-166}:\\
\;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(a \cdot c, -3, b \cdot b\right)} - b}{3}}{a}\\

\mathbf{elif}\;b \leq 6606110945.941845:\\
\;\;\;\;\frac{\frac{3 \cdot \left(a \cdot c\right)}{\left(-b\right) - \mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right)}}{3 \cdot a}\\

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


\end{array}
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
 :precision binary64
 (if (<= b -7.518753900645323e+128)
   (/ (- (- b) b) (* 3.0 a))
   (if (<= b 7.17628680422661e-166)
     (/ (/ (- (sqrt (fma (* a c) -3.0 (* b b))) b) 3.0) a)
     (if (<= b 6606110945.941845)
       (/
        (/ (* 3.0 (* a c)) (- (- b) (hypot (sqrt (* c (* a -3.0))) b)))
        (* 3.0 a))
       (* -0.5 (/ c b))))))
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 tmp;
	if (b <= -7.518753900645323e+128) {
		tmp = (-b - b) / (3.0 * a);
	} else if (b <= 7.17628680422661e-166) {
		tmp = ((sqrt(fma((a * c), -3.0, (b * b))) - b) / 3.0) / a;
	} else if (b <= 6606110945.941845) {
		tmp = ((3.0 * (a * c)) / (-b - hypot(sqrt(c * (a * -3.0)), b))) / (3.0 * a);
	} else {
		tmp = -0.5 * (c / b);
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b < -7.51875390064532329e128

    1. Initial program 53.9

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

      \[\leadsto \frac{\left(-b\right) + \color{blue}{-1 \cdot b}}{3 \cdot a} \]
    3. Simplified2.9

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

    if -7.51875390064532329e128 < b < 7.17628680422661011e-166

    1. Initial program 10.6

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

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

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

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

    if 7.17628680422661011e-166 < b < 6606110945.9418449

    1. Initial program 31.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Applied flip-+_binary6431.9

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

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

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

    if 6606110945.9418449 < b

    1. Initial program 57.0

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

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}}{3 \cdot a} \]
    4. Taylor expanded in b around inf 5.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -7.518753900645323 \cdot 10^{+128}:\\ \;\;\;\;\frac{\left(-b\right) - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 7.17628680422661 \cdot 10^{-166}:\\ \;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(a \cdot c, -3, b \cdot b\right)} - b}{3}}{a}\\ \mathbf{elif}\;b \leq 6606110945.941845:\\ \;\;\;\;\frac{\frac{3 \cdot \left(a \cdot c\right)}{\left(-b\right) - \mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]

Reproduce

herbie shell --seed 2021275 
(FPCore (a b c)
  :name "Cubic critical"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))