Average Error: 34.5 → 8.1
Time: 8.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.0187968088253477 \cdot 10^{+144}:\\ \;\;\;\;\mathsf{fma}\left(-0.6666666666666666, \frac{b}{a}, 0.5 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq -4.0088356050405405 \cdot 10^{-270}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 8.64278930394556 \cdot 10^{-27}:\\ \;\;\;\;\frac{a}{a} \cdot \frac{-c}{b + \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -3\right)}\right)}\\ \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.0187968088253477 \cdot 10^{+144}:\\
\;\;\;\;\mathsf{fma}\left(-0.6666666666666666, \frac{b}{a}, 0.5 \cdot \frac{c}{b}\right)\\

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

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

\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.0187968088253477e+144)
   (fma -0.6666666666666666 (/ b a) (* 0.5 (/ c b)))
   (if (<= b -4.0088356050405405e-270)
     (/ (- (sqrt (fma b b (* c (* a -3.0)))) b) (* a 3.0))
     (if (<= b 8.64278930394556e-27)
       (* (/ a a) (/ (- c) (+ b (hypot b (sqrt (* a (* c -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.0187968088253477e+144) {
		tmp = fma(-0.6666666666666666, (b / a), (0.5 * (c / b)));
	} else if (b <= -4.0088356050405405e-270) {
		tmp = (sqrt(fma(b, b, (c * (a * -3.0)))) - b) / (a * 3.0);
	} else if (b <= 8.64278930394556e-27) {
		tmp = (a / a) * (-c / (b + hypot(b, sqrt(a * (c * -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 4 regimes
  2. if b < -1.0187968088253477e144

    1. Initial program 59.6

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

      \[\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} \]
    4. Simplified62.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} \]
    5. Simplified62.8

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

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

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

    if -1.0187968088253477e144 < b < -4.0088356050405405e-270

    1. Initial program 8.9

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

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

      \[\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 -4.0088356050405405e-270 < b < 8.6427893039455601e-27

    1. Initial program 22.5

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

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)} - b\right) \cdot \frac{0.3333333333333333}{a}} \]
    3. Using strategy rm
    4. Applied flip--_binary6422.8

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

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

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

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

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

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

    if 8.6427893039455601e-27 < b

    1. Initial program 55.0

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

      \[\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} \]
    4. Simplified26.6

      \[\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} \]
    5. Simplified26.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.0187968088253477 \cdot 10^{+144}:\\ \;\;\;\;\mathsf{fma}\left(-0.6666666666666666, \frac{b}{a}, 0.5 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq -4.0088356050405405 \cdot 10^{-270}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 8.64278930394556 \cdot 10^{-27}:\\ \;\;\;\;\frac{a}{a} \cdot \frac{-c}{b + \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -3\right)}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \]

Reproduce

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