Average Error: 34.3 → 11.0
Time: 10.1s
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 -19862.42266342159:\\ \;\;\;\;\mathsf{fma}\left(\frac{-3 \cdot c}{b}, -0.16666666666666666, \frac{b}{a} \cdot -0.6666666666666666\right)\\ \mathbf{elif}\;b \leq 7.69231311753423 \cdot 10^{-110}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 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 \leq -19862.42266342159:\\
\;\;\;\;\mathsf{fma}\left(\frac{-3 \cdot c}{b}, -0.16666666666666666, \frac{b}{a} \cdot -0.6666666666666666\right)\\

\mathbf{elif}\;b \leq 7.69231311753423 \cdot 10^{-110}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\

\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 -19862.42266342159)
   (fma (/ (* -3.0 c) b) -0.16666666666666666 (* (/ b a) -0.6666666666666666))
   (if (<= b 7.69231311753423e-110)
     (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))
     (* -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 <= -19862.42266342159) {
		tmp = fma(((-3.0 * c) / b), -0.16666666666666666, ((b / a) * -0.6666666666666666));
	} else if (b <= 7.69231311753423e-110) {
		tmp = (sqrt((b * b) - (c * (a * 3.0))) - b) / (a * 3.0);
	} 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 3 regimes
  2. if b < -19862.422663421588

    1. Initial program 33.5

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

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

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

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

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

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

    if -19862.422663421588 < b < 7.6923131175342304e-110

    1. Initial program 13.9

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

    if 7.6923131175342304e-110 < b

    1. Initial program 51.8

      \[\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 10.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -19862.42266342159:\\ \;\;\;\;\mathsf{fma}\left(\frac{-3 \cdot c}{b}, -0.16666666666666666, \frac{b}{a} \cdot -0.6666666666666666\right)\\ \mathbf{elif}\;b \leq 7.69231311753423 \cdot 10^{-110}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]

Reproduce

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