Average Error: 33.7 → 9.6
Time: 11.7s
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 -1.540932896291113 \cdot 10^{+151}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b}, \frac{b}{a} \cdot -0.6666666666666666\right)\\ \mathbf{elif}\;b \leq 4.458754763303836 \cdot 10^{-44}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right) + \mathsf{fma}\left(-c, a \cdot 3, c \cdot \left(a \cdot 3\right)\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \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 -1.540932896291113 \cdot 10^{+151}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b}, \frac{b}{a} \cdot -0.6666666666666666\right)\\

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

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


\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 -1.540932896291113e+151)
   (fma 0.5 (/ c b) (* (/ b a) -0.6666666666666666))
   (if (<= b 4.458754763303836e-44)
     (/
      (-
       (sqrt
        (+ (fma b b (* c (* a -3.0))) (fma (- c) (* a 3.0) (* c (* a 3.0)))))
       b)
      (* a 3.0))
     (* (/ c b) -0.5))))
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 <= -1.540932896291113e+151) {
		tmp = fma(0.5, (c / b), ((b / a) * -0.6666666666666666));
	} else if (b <= 4.458754763303836e-44) {
		tmp = (sqrt(fma(b, b, (c * (a * -3.0))) + fma(-c, (a * 3.0), (c * (a * 3.0)))) - b) / (a * 3.0);
	} else {
		tmp = (c / b) * -0.5;
	}
	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 < -1.540932896291113e151

    1. Initial program 63.1

      \[\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.2

      \[\leadsto \color{blue}{0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}} \]
    3. Simplified2.2

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

    if -1.540932896291113e151 < b < 4.4587547633038359e-44

    1. Initial program 13.0

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

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

    if 4.4587547633038359e-44 < b

    1. Initial program 54.4

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

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

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

Reproduce

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