Average Error: 33.6 → 10.2
Time: 10.5s
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.153332913727811 \cdot 10^{+138}:\\ \;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\ \mathbf{elif}\;b \leq 1.9180183270872948 \cdot 10^{-83}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a}}{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 -4.153332913727811 \cdot 10^{+138}:\\
\;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\

\mathbf{elif}\;b \leq 1.9180183270872948 \cdot 10^{-83}:\\
\;\;\;\;\frac{\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a}}{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 -4.153332913727811e+138)
   (/ (/ (* b -2.0) 3.0) a)
   (if (<= b 1.9180183270872948e-83)
     (/ (/ (- (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 <= -4.153332913727811e+138) {
		tmp = ((b * -2.0) / 3.0) / a;
	} else if (b <= 1.9180183270872948e-83) {
		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

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if b < -4.1533329137278107e138

    1. Initial program 57.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Using strategy rm
    3. Applied associate-/r*_binary6457.5

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

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

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]
    6. Simplified2.9

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

    if -4.1533329137278107e138 < b < 1.9180183270872948e-83

    1. Initial program 12.4

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

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}\right) \cdot \sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}{3 \cdot a} \]
    4. Applied times-frac_binary6413.3

      \[\leadsto \color{blue}{\frac{\sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3} \cdot \frac{\sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{a}} \]
    5. Applied associate-*l/_binary6413.3

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

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

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

    if 1.9180183270872948e-83 < b

    1. Initial program 52.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.153332913727811 \cdot 10^{+138}:\\ \;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\ \mathbf{elif}\;b \leq 1.9180183270872948 \cdot 10^{-83}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a}}{3}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]

Reproduce

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