Average Error: 33.7 → 10.3
Time: 10.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 -4.899534402647273 \cdot 10^{+110}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 7.694942576818603 \cdot 10^{-97}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{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 -4.899534402647273 \cdot 10^{+110}:\\
\;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\

\mathbf{elif}\;b \leq 7.694942576818603 \cdot 10^{-97}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{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 -4.899534402647273e+110)
   (/ (* b -2.0) (* 3.0 a))
   (if (<= b 7.694942576818603e-97)
     (/ (- (sqrt (fma b b (* 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 <= -4.899534402647273e+110) {
		tmp = (b * -2.0) / (3.0 * a);
	} else if (b <= 7.694942576818603e-97) {
		tmp = (sqrt(fma(b, b, (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 3 regimes
  2. if b < -4.89953440264727313e110

    1. Initial program 49.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 4.3

      \[\leadsto \frac{\color{blue}{-2 \cdot b}}{3 \cdot a} \]

    if -4.89953440264727313e110 < b < 7.6949425768186032e-97

    1. Initial program 12.2

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

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

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

    if 7.6949425768186032e-97 < b

    1. Initial program 52.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 inf 10.2

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

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

Reproduce

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