Average Error: 19.8 → 7.2
Time: 5.3s
Precision: binary64
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array} \]
\[\begin{array}{l} t_0 := c \cdot \left(a \cdot -4\right)\\ t_1 := \sqrt{b \cdot b + t_0}\\ t_2 := \frac{c \cdot 2}{t_1 - b}\\ t_3 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - t_1}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ t_4 := \left(-b\right) - b\\ t_5 := \frac{c \cdot 2}{t_4}\\ t_6 := \frac{t_4}{a \cdot 2}\\ \mathbf{if}\;t_3 \leq -1.821187953291325 \cdot 10^{+195}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_6\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ \mathbf{elif}\;t_3 \leq -2.623762971542931 \cdot 10^{-267}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_3 \leq 0:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\sqrt[3]{{\left(b - \sqrt{\mathsf{fma}\left(b, b, t_0\right)}\right)}^{3}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;t_5\\ \end{array}\\ \mathbf{elif}\;t_3 \leq 2.1482622163419423 \cdot 10^{+269}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;t_6\\ \mathbf{else}:\\ \;\;\;\;t_5\\ \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (>= b 0.0)
   (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))
   (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (* c (* a -4.0)))
        (t_1 (sqrt (+ (* b b) t_0)))
        (t_2 (/ (* c 2.0) (- t_1 b)))
        (t_3 (if (>= b 0.0) (/ (- (- b) t_1) (* a 2.0)) t_2))
        (t_4 (- (- b) b))
        (t_5 (/ (* c 2.0) t_4))
        (t_6 (/ t_4 (* a 2.0))))
   (if (<= t_3 -1.821187953291325e+195)
     (if (>= b 0.0) t_6 t_2)
     (if (<= t_3 -2.623762971542931e-267)
       t_3
       (if (<= t_3 0.0)
         (if (>= b 0.0)
           (/ (cbrt (pow (- b (sqrt (fma b b t_0))) 3.0)) (* a 2.0))
           t_5)
         (if (<= t_3 2.1482622163419423e+269) t_3 (if (>= b 0.0) t_6 t_5)))))))
double code(double a, double b, double c) {
	double tmp;
	if (b >= 0.0) {
		tmp = (-b - sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
	} else {
		tmp = (2.0 * c) / (-b + sqrt(((b * b) - ((4.0 * a) * c))));
	}
	return tmp;
}
double code(double a, double b, double c) {
	double t_0 = c * (a * -4.0);
	double t_1 = sqrt(((b * b) + t_0));
	double t_2 = (c * 2.0) / (t_1 - b);
	double tmp;
	if (b >= 0.0) {
		tmp = (-b - t_1) / (a * 2.0);
	} else {
		tmp = t_2;
	}
	double t_3 = tmp;
	double t_4 = -b - b;
	double t_5 = (c * 2.0) / t_4;
	double t_6 = t_4 / (a * 2.0);
	double tmp_2;
	if (t_3 <= -1.821187953291325e+195) {
		double tmp_3;
		if (b >= 0.0) {
			tmp_3 = t_6;
		} else {
			tmp_3 = t_2;
		}
		tmp_2 = tmp_3;
	} else if (t_3 <= -2.623762971542931e-267) {
		tmp_2 = t_3;
	} else if (t_3 <= 0.0) {
		double tmp_4;
		if (b >= 0.0) {
			tmp_4 = cbrt(pow((b - sqrt(fma(b, b, t_0))), 3.0)) / (a * 2.0);
		} else {
			tmp_4 = t_5;
		}
		tmp_2 = tmp_4;
	} else if (t_3 <= 2.1482622163419423e+269) {
		tmp_2 = t_3;
	} else if (b >= 0.0) {
		tmp_2 = t_6;
	} else {
		tmp_2 = t_5;
	}
	return tmp_2;
}
function code(a, b, c)
	tmp = 0.0
	if (b >= 0.0)
		tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a));
	else
		tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))));
	end
	return tmp
end
function code(a, b, c)
	t_0 = Float64(c * Float64(a * -4.0))
	t_1 = sqrt(Float64(Float64(b * b) + t_0))
	t_2 = Float64(Float64(c * 2.0) / Float64(t_1 - b))
	tmp = 0.0
	if (b >= 0.0)
		tmp = Float64(Float64(Float64(-b) - t_1) / Float64(a * 2.0));
	else
		tmp = t_2;
	end
	t_3 = tmp
	t_4 = Float64(Float64(-b) - b)
	t_5 = Float64(Float64(c * 2.0) / t_4)
	t_6 = Float64(t_4 / Float64(a * 2.0))
	tmp_2 = 0.0
	if (t_3 <= -1.821187953291325e+195)
		tmp_3 = 0.0
		if (b >= 0.0)
			tmp_3 = t_6;
		else
			tmp_3 = t_2;
		end
		tmp_2 = tmp_3;
	elseif (t_3 <= -2.623762971542931e-267)
		tmp_2 = t_3;
	elseif (t_3 <= 0.0)
		tmp_4 = 0.0
		if (b >= 0.0)
			tmp_4 = Float64(cbrt((Float64(b - sqrt(fma(b, b, t_0))) ^ 3.0)) / Float64(a * 2.0));
		else
			tmp_4 = t_5;
		end
		tmp_2 = tmp_4;
	elseif (t_3 <= 2.1482622163419423e+269)
		tmp_2 = t_3;
	elseif (b >= 0.0)
		tmp_2 = t_6;
	else
		tmp_2 = t_5;
	end
	return tmp_2
end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], 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], 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]]
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$1 - b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$1), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], t$95$2]}, Block[{t$95$4 = N[((-b) - b), $MachinePrecision]}, Block[{t$95$5 = N[(N[(c * 2.0), $MachinePrecision] / t$95$4), $MachinePrecision]}, Block[{t$95$6 = N[(t$95$4 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -1.821187953291325e+195], If[GreaterEqual[b, 0.0], t$95$6, t$95$2], If[LessEqual[t$95$3, -2.623762971542931e-267], t$95$3, If[LessEqual[t$95$3, 0.0], If[GreaterEqual[b, 0.0], N[(N[Power[N[Power[N[(b - N[Sqrt[N[(b * b + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], 1/3], $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], t$95$5], If[LessEqual[t$95$3, 2.1482622163419423e+269], t$95$3, If[GreaterEqual[b, 0.0], t$95$6, t$95$5]]]]]]]]]]]]
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

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


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

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}\\
t_4 := \left(-b\right) - b\\
t_5 := \frac{c \cdot 2}{t_4}\\
t_6 := \frac{t_4}{a \cdot 2}\\
\mathbf{if}\;t_3 \leq -1.821187953291325 \cdot 10^{+195}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_6\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}\\

\mathbf{elif}\;t_3 \leq -2.623762971542931 \cdot 10^{-267}:\\
\;\;\;\;t_3\\

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

\mathbf{else}:\\
\;\;\;\;t_5\\


\end{array}\\

\mathbf{elif}\;t_3 \leq 2.1482622163419423 \cdot 10^{+269}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t_6\\

\mathbf{else}:\\
\;\;\;\;t_5\\


\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < -1.821187953291325e195

    1. Initial program 43.2

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

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

    if -1.821187953291325e195 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < -2.62376297154293109e-267 or -0.0 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < 2.1482622163419423e269

    1. Initial program 3.0

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

    if -2.62376297154293109e-267 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < -0.0

    1. Initial program 36.4

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

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

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

    if 2.1482622163419423e269 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))))

    1. Initial program 57.9

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + -1 \cdot b}\\ \end{array} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification7.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}\\ \end{array} \leq -1.821187953291325 \cdot 10^{+195}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}\\ \end{array}\\ \mathbf{elif}\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}\\ \end{array} \leq -2.623762971542931 \cdot 10^{-267}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}\\ \end{array}\\ \mathbf{elif}\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}\\ \end{array} \leq 0:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\sqrt[3]{{\left(b - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}\right)}^{3}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - b}\\ \end{array}\\ \mathbf{elif}\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}\\ \end{array} \leq 2.1482622163419423 \cdot 10^{+269}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - b}\\ \end{array} \]

Reproduce

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