Average Error: 34.3 → 7.8
Time: 10.4s
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 -241.3804940250154:\\ \;\;\;\;\frac{\left(-b\right) - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 2.7437864687343154 \cdot 10^{-306}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-1, b, \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{3 \cdot a}\\ \mathbf{elif}\;b \leq 3.027908356170109 \cdot 10^{+125}:\\ \;\;\;\;\frac{-c}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b + 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 -241.3804940250154)
   (/ (- (- b) b) (* 3.0 a))
   (if (<= b 2.7437864687343154e-306)
     (/ (fma -1.0 b (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a))
     (if (<= b 3.027908356170109e+125)
       (/ (- c) (+ b (sqrt (fma c (* a -3.0) (* b b)))))
       (/ (- c) (+ b 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 <= -241.3804940250154) {
		tmp = (-b - b) / (3.0 * a);
	} else if (b <= 2.7437864687343154e-306) {
		tmp = fma(-1.0, b, sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
	} else if (b <= 3.027908356170109e+125) {
		tmp = -c / (b + sqrt(fma(c, (a * -3.0), (b * b))));
	} else {
		tmp = -c / (b + 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 <= -241.3804940250154)
		tmp = Float64(Float64(Float64(-b) - b) / Float64(3.0 * a));
	elseif (b <= 2.7437864687343154e-306)
		tmp = Float64(fma(-1.0, b, sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a));
	elseif (b <= 3.027908356170109e+125)
		tmp = Float64(Float64(-c) / Float64(b + sqrt(fma(c, Float64(a * -3.0), Float64(b * b)))));
	else
		tmp = Float64(Float64(-c) / Float64(b + 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, -241.3804940250154], N[(N[((-b) - b), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.7437864687343154e-306], N[(N[(-1.0 * 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], If[LessEqual[b, 3.027908356170109e+125], N[((-c) / N[(b + N[Sqrt[N[(c * N[(a * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / N[(b + 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 -241.3804940250154:\\
\;\;\;\;\frac{\left(-b\right) - b}{3 \cdot a}\\

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

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

\mathbf{else}:\\
\;\;\;\;\frac{-c}{b + b}\\


\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b < -241.380494025015395

    1. Initial program 31.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 8.6

      \[\leadsto \frac{\left(-b\right) + \color{blue}{-1 \cdot b}}{3 \cdot a} \]
    3. Simplified8.6

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

    if -241.380494025015395 < b < 2.7437864687343154e-306

    1. Initial program 11.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Applied *-un-lft-identity_binary6411.5

      \[\leadsto \frac{\left(-\color{blue}{1 \cdot b}\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    3. Applied distribute-lft-neg-in_binary6411.5

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

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

    if 2.7437864687343154e-306 < b < 3.02790835617010882e125

    1. Initial program 33.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Simplified33.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. Applied flip--_binary6433.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} \]
    4. Applied associate-*l/_binary6433.8

      \[\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 \frac{0.3333333333333333}{a}}{\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)} + b}} \]
    5. Simplified15.5

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

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

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

      \[\leadsto \frac{-c}{\sqrt{\color{blue}{{b}^{2} - 3 \cdot \left(c \cdot a\right)}} + b} \]
    9. Simplified8.6

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

    if 3.02790835617010882e125 < b

    1. Initial program 61.2

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

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

      \[\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} \]
    4. Applied associate-*l/_binary6461.2

      \[\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 \frac{0.3333333333333333}{a}}{\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)} + b}} \]
    5. Simplified33.6

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

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

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

      \[\leadsto \frac{-c}{\color{blue}{b} + b} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification7.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -241.3804940250154:\\ \;\;\;\;\frac{\left(-b\right) - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 2.7437864687343154 \cdot 10^{-306}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-1, b, \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{3 \cdot a}\\ \mathbf{elif}\;b \leq 3.027908356170109 \cdot 10^{+125}:\\ \;\;\;\;\frac{-c}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b + b}\\ \end{array} \]

Reproduce

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