Average Error: 34.6 → 11.0
Time: 8.2s
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.3971509965545484 \cdot 10^{+115}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b}, \frac{b}{a} \cdot -0.6666666666666666\right)\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b\\ \mathbf{if}\;b \leq 1.2626367882715619 \cdot 10^{-142}:\\ \;\;\;\;\frac{t_0}{a \cdot 3}\\ \mathbf{elif}\;b \leq 1.579289878984042 \cdot 10^{-78} \lor \neg \left(b \leq 3.0301703971888995 \cdot 10^{-45}\right):\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 3}{t_0}}\\ \end{array}\\ \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.3971509965545484 \cdot 10^{+115}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b}, \frac{b}{a} \cdot -0.6666666666666666\right)\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b\\
\mathbf{if}\;b \leq 1.2626367882715619 \cdot 10^{-142}:\\
\;\;\;\;\frac{t_0}{a \cdot 3}\\

\mathbf{elif}\;b \leq 1.579289878984042 \cdot 10^{-78} \lor \neg \left(b \leq 3.0301703971888995 \cdot 10^{-45}\right):\\
\;\;\;\;\frac{c}{b} \cdot -0.5\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{a \cdot 3}{t_0}}\\


\end{array}\\


\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.3971509965545484e+115)
   (fma 0.5 (/ c b) (* (/ b a) -0.6666666666666666))
   (let* ((t_0 (- (sqrt (- (* b b) (* c (* a 3.0)))) b)))
     (if (<= b 1.2626367882715619e-142)
       (/ t_0 (* a 3.0))
       (if (or (<= b 1.579289878984042e-78)
               (not (<= b 3.0301703971888995e-45)))
         (* (/ c b) -0.5)
         (/ 1.0 (/ (* a 3.0) t_0)))))))
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.3971509965545484e+115) {
		tmp = fma(0.5, (c / b), ((b / a) * -0.6666666666666666));
	} else {
		double t_0 = sqrt((b * b) - (c * (a * 3.0))) - b;
		double tmp_1;
		if (b <= 1.2626367882715619e-142) {
			tmp_1 = t_0 / (a * 3.0);
		} else if ((b <= 1.579289878984042e-78) || !(b <= 3.0301703971888995e-45)) {
			tmp_1 = (c / b) * -0.5;
		} else {
			tmp_1 = 1.0 / ((a * 3.0) / t_0);
		}
		tmp = tmp_1;
	}
	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.3971509965545484e115

    1. Initial program 51.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 3.7

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

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

    if -1.3971509965545484e115 < b < 1.26263678827156191e-142

    1. Initial program 11.5

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

    if 1.26263678827156191e-142 < b < 1.5792898789840419e-78 or 3.0301703971888995e-45 < b

    1. Initial program 51.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 11.6

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}} \]

    if 1.5792898789840419e-78 < b < 3.0301703971888995e-45

    1. Initial program 34.9

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

      \[\leadsto \color{blue}{\frac{1}{\frac{3 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification11.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.3971509965545484 \cdot 10^{+115}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b}, \frac{b}{a} \cdot -0.6666666666666666\right)\\ \mathbf{elif}\;b \leq 1.2626367882715619 \cdot 10^{-142}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 1.579289878984042 \cdot 10^{-78} \lor \neg \left(b \leq 3.0301703971888995 \cdot 10^{-45}\right):\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 3}{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}}\\ \end{array} \]

Reproduce

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