Average Error: 34.0 → 10.2
Time: 10.9s
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.5621525294355644 \cdot 10^{+153}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 7.586865080956008 \cdot 10^{-35}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-1, b, \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}\right)}{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 -1.5621525294355644e+153)
   (/ (* b -2.0) (* 3.0 a))
   (if (<= b 7.586865080956008e-35)
     (/ (fma -1.0 b (sqrt (fma b b (* c (* a -3.0))))) (* 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 <= -1.5621525294355644e+153) {
		tmp = (b * -2.0) / (3.0 * a);
	} else if (b <= 7.586865080956008e-35) {
		tmp = fma(-1.0, b, sqrt(fma(b, b, (c * (a * -3.0))))) / (3.0 * a);
	} else {
		tmp = -0.5 * (c / b);
	}
	return tmp;
}
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a))
end
function code(a, b, c)
	tmp = 0.0
	if (b <= -1.5621525294355644e+153)
		tmp = Float64(Float64(b * -2.0) / Float64(3.0 * a));
	elseif (b <= 7.586865080956008e-35)
		tmp = Float64(fma(-1.0, b, sqrt(fma(b, b, Float64(c * Float64(a * -3.0))))) / Float64(3.0 * a));
	else
		tmp = Float64(-0.5 * Float64(c / b));
	end
	return tmp
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := If[LessEqual[b, -1.5621525294355644e+153], N[(N[(b * -2.0), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7.586865080956008e-35], N[(N[(-1.0 * b + N[Sqrt[N[(b * b + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\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.5621525294355644 \cdot 10^{+153}:\\
\;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\

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

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


\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -1.56215252943556438e153

    1. Initial program 63.9

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

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

    if -1.56215252943556438e153 < b < 7.5868650809560082e-35

    1. Initial program 13.9

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

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

    if 7.5868650809560082e-35 < b

    1. Initial program 54.7

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

      \[\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 -1.5621525294355644 \cdot 10^{+153}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 7.586865080956008 \cdot 10^{-35}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-1, b, \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}\right)}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]

Reproduce

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