Average Error: 19.9 → 6.6
Time: 16.6s
Precision: binary64
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array} \]
\[\begin{array}{l} t_0 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a}{{\left(\sqrt[3]{b}\right)}^{2}} \cdot \frac{c}{\sqrt[3]{b}}, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \end{array}\\ t_1 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\ t_2 := \frac{2 \cdot c}{\left(-b\right) - t_1}\\ t_3 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1 - b}{2 \cdot a}\\ \end{array}\\ \mathbf{if}\;t_3 \leq -\infty:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_3 \leq -5 \cdot 10^{-257}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_3 \leq 5 \cdot 10^{-247}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_3 \leq 5 \cdot 10^{+283}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \mathsf{fma}\left(c, a \cdot -4, \mathsf{fma}\left(c, a \cdot -4, 4 \cdot \left(c \cdot a\right)\right)\right)\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (>= b 0.0)
   (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))
   (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))
(FPCore (a b c)
 :precision binary64
 (let* ((t_0
         (if (>= b 0.0)
           (/
            (* 2.0 c)
            (fma 2.0 (* (/ a (pow (cbrt b) 2.0)) (/ c (cbrt b))) (* b -2.0)))
           (/ (- (- b) b) (* 2.0 a))))
        (t_1 (sqrt (- (* b b) (* c (* 4.0 a)))))
        (t_2 (/ (* 2.0 c) (- (- b) t_1)))
        (t_3 (if (>= b 0.0) t_2 (/ (- t_1 b) (* 2.0 a)))))
   (if (<= t_3 (- INFINITY))
     t_0
     (if (<= t_3 -5e-257)
       t_3
       (if (<= t_3 5e-247)
         t_0
         (if (<= t_3 5e+283)
           (if (>= b 0.0)
             t_2
             (/
              (-
               (sqrt
                (fma
                 b
                 b
                 (fma c (* a -4.0) (fma c (* a -4.0) (* 4.0 (* c a))))))
               b)
              (* 2.0 a)))
           t_0))))))
double code(double a, double b, double c) {
	double tmp;
	if (b >= 0.0) {
		tmp = (2.0 * c) / (-b - sqrt(((b * b) - ((4.0 * a) * c))));
	} else {
		tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
	}
	return tmp;
}
double code(double a, double b, double c) {
	double tmp;
	if (b >= 0.0) {
		tmp = (2.0 * c) / fma(2.0, ((a / pow(cbrt(b), 2.0)) * (c / cbrt(b))), (b * -2.0));
	} else {
		tmp = (-b - b) / (2.0 * a);
	}
	double t_0 = tmp;
	double t_1 = sqrt(((b * b) - (c * (4.0 * a))));
	double t_2 = (2.0 * c) / (-b - t_1);
	double tmp_1;
	if (b >= 0.0) {
		tmp_1 = t_2;
	} else {
		tmp_1 = (t_1 - b) / (2.0 * a);
	}
	double t_3 = tmp_1;
	double tmp_2;
	if (t_3 <= -((double) INFINITY)) {
		tmp_2 = t_0;
	} else if (t_3 <= -5e-257) {
		tmp_2 = t_3;
	} else if (t_3 <= 5e-247) {
		tmp_2 = t_0;
	} else if (t_3 <= 5e+283) {
		double tmp_3;
		if (b >= 0.0) {
			tmp_3 = t_2;
		} else {
			tmp_3 = (sqrt(fma(b, b, fma(c, (a * -4.0), fma(c, (a * -4.0), (4.0 * (c * a)))))) - b) / (2.0 * a);
		}
		tmp_2 = tmp_3;
	} else {
		tmp_2 = t_0;
	}
	return tmp_2;
}
function code(a, b, c)
	tmp = 0.0
	if (b >= 0.0)
		tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))));
	else
		tmp = Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a));
	end
	return tmp
end
function code(a, b, c)
	tmp = 0.0
	if (b >= 0.0)
		tmp = Float64(Float64(2.0 * c) / fma(2.0, Float64(Float64(a / (cbrt(b) ^ 2.0)) * Float64(c / cbrt(b))), Float64(b * -2.0)));
	else
		tmp = Float64(Float64(Float64(-b) - b) / Float64(2.0 * a));
	end
	t_0 = tmp
	t_1 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a))))
	t_2 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_1))
	tmp_1 = 0.0
	if (b >= 0.0)
		tmp_1 = t_2;
	else
		tmp_1 = Float64(Float64(t_1 - b) / Float64(2.0 * a));
	end
	t_3 = tmp_1
	tmp_2 = 0.0
	if (t_3 <= Float64(-Inf))
		tmp_2 = t_0;
	elseif (t_3 <= -5e-257)
		tmp_2 = t_3;
	elseif (t_3 <= 5e-247)
		tmp_2 = t_0;
	elseif (t_3 <= 5e+283)
		tmp_3 = 0.0
		if (b >= 0.0)
			tmp_3 = t_2;
		else
			tmp_3 = Float64(Float64(sqrt(fma(b, b, fma(c, Float64(a * -4.0), fma(c, Float64(a * -4.0), Float64(4.0 * Float64(c * a)))))) - b) / Float64(2.0 * a));
		end
		tmp_2 = tmp_3;
	else
		tmp_2 = t_0;
	end
	return tmp_2
end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
code[a_, b_, c_] := Block[{t$95$0 = If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(N[(a / N[Power[N[Power[b, 1/3], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(c / N[Power[b, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = If[GreaterEqual[b, 0.0], t$95$2, N[(N[(t$95$1 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]}, If[LessEqual[t$95$3, (-Infinity)], t$95$0, If[LessEqual[t$95$3, -5e-257], t$95$3, If[LessEqual[t$95$3, 5e-247], t$95$0, If[LessEqual[t$95$3, 5e+283], If[GreaterEqual[b, 0.0], t$95$2, N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision] + N[(c * N[(a * -4.0), $MachinePrecision] + N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], t$95$0]]]]]]]]
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\


\end{array}
\begin{array}{l}
t_0 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a}{{\left(\sqrt[3]{b}\right)}^{2}} \cdot \frac{c}{\sqrt[3]{b}}, b \cdot -2\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\


\end{array}\\
t_1 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\
t_2 := \frac{2 \cdot c}{\left(-b\right) - t_1}\\
t_3 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;\frac{t_1 - b}{2 \cdot a}\\


\end{array}\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_3 \leq -5 \cdot 10^{-257}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_3 \leq 5 \cdot 10^{-247}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_3 \leq 5 \cdot 10^{+283}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \mathsf{fma}\left(c, a \cdot -4, \mathsf{fma}\left(c, a \cdot -4, 4 \cdot \left(c \cdot a\right)\right)\right)\right)} - b}{2 \cdot a}\\


\end{array}\\

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


\end{array}

Error

Derivation

  1. Split input into 3 regimes
  2. if (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < -inf.0 or -4.99999999999999989e-257 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < 4.99999999999999978e-247 or 5.0000000000000004e283 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)))

    1. Initial program 44.8

      \[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array} \]
    2. Taylor expanded in b around -inf 27.8

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + -1 \cdot b}{2 \cdot a}\\ \end{array} \]
    3. Simplified27.8

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \left(-b\right)}{2 \cdot a}\\ \end{array} \]
    4. Taylor expanded in b around inf 14.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\color{blue}{2 \cdot \frac{c \cdot a}{b} + -2 \cdot b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \left(-b\right)}{2 \cdot a}\\ \end{array} \]
    5. Simplified12.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\color{blue}{\mathsf{fma}\left(2, a \cdot \frac{c}{b}, b \cdot -2\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \left(-b\right)}{2 \cdot a}\\ \end{array} \]
    6. Applied egg-rr12.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \color{blue}{{\left(\sqrt[3]{a \cdot \frac{c}{b}}\right)}^{3}}, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \left(-b\right)}{2 \cdot a}\\ \end{array} \]
    7. Applied egg-rr12.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \color{blue}{\frac{a}{{\left(\sqrt[3]{b}\right)}^{2}} \cdot \frac{c}{\sqrt[3]{b}}}, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \left(-b\right)}{2 \cdot a}\\ \end{array} \]

    if -inf.0 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < -4.99999999999999989e-257

    1. Initial program 2.7

      \[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array} \]

    if 4.99999999999999978e-247 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < 5.0000000000000004e283

    1. Initial program 2.8

      \[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array} \]
    2. Applied egg-rr2.9

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(b, b, \mathsf{fma}\left(c, a \cdot -4, \mathsf{fma}\left(c, a \cdot -4, 4 \cdot \left(a \cdot c\right)\right)\right)\right)}}{2 \cdot a}\\ \end{array} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification6.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array} \leq -\infty:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a}{{\left(\sqrt[3]{b}\right)}^{2}} \cdot \frac{c}{\sqrt[3]{b}}, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array} \leq -5 \cdot 10^{-257}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array} \leq 5 \cdot 10^{-247}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a}{{\left(\sqrt[3]{b}\right)}^{2}} \cdot \frac{c}{\sqrt[3]{b}}, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array} \leq 5 \cdot 10^{+283}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \mathsf{fma}\left(c, a \cdot -4, \mathsf{fma}\left(c, a \cdot -4, 4 \cdot \left(c \cdot a\right)\right)\right)\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a}{{\left(\sqrt[3]{b}\right)}^{2}} \cdot \frac{c}{\sqrt[3]{b}}, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \end{array} \]

Reproduce

herbie shell --seed 2022210 
(FPCore (a b c)
  :name "jeff quadratic root 2"
  :precision binary64
  (if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))