Average Error: 34.4 → 10.9
Time: 20.8s
Precision: binary64
Cost: 14160
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
\[\begin{array}{l} t_0 := -0.5 \cdot \frac{c}{b}\\ \mathbf{if}\;b \leq -8.6 \cdot 10^{+110}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 5.5 \cdot 10^{-157}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 6.2 \cdot 10^{-66}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{-45}:\\ \;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b\right) \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \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
 (let* ((t_0 (* -0.5 (/ c b))))
   (if (<= b -8.6e+110)
     (/ (* b -2.0) (* 3.0 a))
     (if (<= b 5.5e-157)
       (/ (- (sqrt (- (* b b) (* (* 3.0 a) c))) b) (* 3.0 a))
       (if (<= b 6.2e-66)
         t_0
         (if (<= b 3.6e-45)
           (* (- (sqrt (fma b b (* a (* c -3.0)))) b) (/ 0.3333333333333333 a))
           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 t_0 = -0.5 * (c / b);
	double tmp;
	if (b <= -8.6e+110) {
		tmp = (b * -2.0) / (3.0 * a);
	} else if (b <= 5.5e-157) {
		tmp = (sqrt(((b * b) - ((3.0 * a) * c))) - b) / (3.0 * a);
	} else if (b <= 6.2e-66) {
		tmp = t_0;
	} else if (b <= 3.6e-45) {
		tmp = (sqrt(fma(b, b, (a * (c * -3.0)))) - b) * (0.3333333333333333 / a);
	} else {
		tmp = t_0;
	}
	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)
	t_0 = Float64(-0.5 * Float64(c / b))
	tmp = 0.0
	if (b <= -8.6e+110)
		tmp = Float64(Float64(b * -2.0) / Float64(3.0 * a));
	elseif (b <= 5.5e-157)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c))) - b) / Float64(3.0 * a));
	elseif (b <= 6.2e-66)
		tmp = t_0;
	elseif (b <= 3.6e-45)
		tmp = Float64(Float64(sqrt(fma(b, b, Float64(a * Float64(c * -3.0)))) - b) * Float64(0.3333333333333333 / a));
	else
		tmp = t_0;
	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_] := Block[{t$95$0 = N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -8.6e+110], N[(N[(b * -2.0), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.5e-157], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.2e-66], t$95$0, If[LessEqual[b, 3.6e-45], N[(N[(N[Sqrt[N[(b * b + N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.3333333333333333 / a), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
t_0 := -0.5 \cdot \frac{c}{b}\\
\mathbf{if}\;b \leq -8.6 \cdot 10^{+110}:\\
\;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\

\mathbf{elif}\;b \leq 5.5 \cdot 10^{-157}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\

\mathbf{elif}\;b \leq 6.2 \cdot 10^{-66}:\\
\;\;\;\;t_0\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Derivation

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

    1. Initial program 50.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 4.0

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

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

    if -8.60000000000000014e110 < b < 5.4999999999999998e-157

    1. Initial program 10.5

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

    if 5.4999999999999998e-157 < b < 6.1999999999999995e-66 or 3.60000000000000001e-45 < b

    1. Initial program 50.2

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{3 \cdot \left(c \cdot a\right)}}}{3 \cdot a} \]
    3. Taylor expanded in b around inf 12.6

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

    if 6.1999999999999995e-66 < b < 3.60000000000000001e-45

    1. Initial program 36.6

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

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b\right) \cdot \frac{0.3333333333333333}{a}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification10.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -8.6 \cdot 10^{+110}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 5.5 \cdot 10^{-157}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 6.2 \cdot 10^{-66}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{-45}:\\ \;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b\right) \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]

Alternatives

Alternative 1
Error11.0
Cost7888
\[\begin{array}{l} t_0 := \frac{0.3333333333333333}{a} \cdot \left(\sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)} - b\right)\\ t_1 := -0.5 \cdot \frac{c}{b}\\ \mathbf{if}\;b \leq -8.6 \cdot 10^{+110}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 5.5 \cdot 10^{-157}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 6.2 \cdot 10^{-66}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{-45}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error11.0
Cost7888
\[\begin{array}{l} t_0 := -0.5 \cdot \frac{c}{b}\\ \mathbf{if}\;b \leq -8.6 \cdot 10^{+110}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 5.5 \cdot 10^{-157}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + -3 \cdot \left(a \cdot c\right)} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 6.2 \cdot 10^{-66}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{-45}:\\ \;\;\;\;\frac{0.3333333333333333}{a} \cdot \left(\sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error10.9
Cost7888
\[\begin{array}{l} t_0 := -0.5 \cdot \frac{c}{b}\\ \mathbf{if}\;b \leq -8.6 \cdot 10^{+110}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 5.5 \cdot 10^{-157}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 6.2 \cdot 10^{-66}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{-45}:\\ \;\;\;\;\frac{0.3333333333333333}{a} \cdot \left(\sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error14.5
Cost7632
\[\begin{array}{l} t_0 := \frac{0.3333333333333333}{a} \cdot \left(\sqrt{-3 \cdot \left(a \cdot c\right)} - b\right)\\ t_1 := -0.5 \cdot \frac{c}{b}\\ \mathbf{if}\;b \leq -1.22 \cdot 10^{-26}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + \frac{c}{b} \cdot 0.5\\ \mathbf{elif}\;b \leq 5.5 \cdot 10^{-157}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 6.2 \cdot 10^{-66}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{-45}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error14.4
Cost7632
\[\begin{array}{l} t_0 := -0.5 \cdot \frac{c}{b}\\ \mathbf{if}\;b \leq -1.22 \cdot 10^{-26}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + \frac{c}{b} \cdot 0.5\\ \mathbf{elif}\;b \leq 5.5 \cdot 10^{-157}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 6.2 \cdot 10^{-66}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{-45}:\\ \;\;\;\;\frac{0.3333333333333333}{a} \cdot \left(\sqrt{-3 \cdot \left(a \cdot c\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error22.8
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.6 \cdot 10^{-217}:\\ \;\;\;\;b \cdot \frac{-0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{-0.5}{b}\\ \end{array} \]
Alternative 7
Error22.7
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.6 \cdot 10^{-217}:\\ \;\;\;\;b \cdot \frac{-0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 8
Error22.7
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.6 \cdot 10^{-217}:\\ \;\;\;\;\frac{-0.6666666666666666}{\frac{a}{b}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 9
Error22.7
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.6 \cdot 10^{-217}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 10
Error45.8
Cost320
\[b \cdot \frac{-0.6666666666666666}{a} \]

Error

Reproduce

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