Average Error: 19.4 → 6.5
Time: 9.0s
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 := \mathsf{hypot}\left(b, \sqrt{t_0}\right)\\ t_2 := a \cdot \frac{c}{b}\\ t_3 := \sqrt{b \cdot b + t_0}\\ t_4 := \frac{c \cdot 2}{t_3 - b}\\ \mathbf{if}\;b \leq -1.65 \cdot 10^{+161}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - t_3}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{2 \cdot \left(t_2 - b\right)}\\ \end{array}\\ \mathbf{elif}\;b \leq -1 \cdot 10^{-152}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\sqrt[3]{{\left(b - t_1\right)}^{3}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;t_4\\ \end{array}\\ \mathbf{elif}\;b \leq 2.2 \cdot 10^{+86}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\left(b + \sqrt{\mathsf{fma}\left(b, b, t_0\right)}\right) \cdot \frac{-0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{2}{\mathsf{fma}\left(-1, b, t_1\right)}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \mathsf{fma}\left(t_2, -2, b\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;t_4\\ \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 (hypot b (sqrt t_0)))
        (t_2 (* a (/ c b)))
        (t_3 (sqrt (+ (* b b) t_0)))
        (t_4 (/ (* c 2.0) (- t_3 b))))
   (if (<= b -1.65e+161)
     (if (>= b 0.0)
       (/ (- (- b) t_3) (* a 2.0))
       (/ (* c 2.0) (* 2.0 (- t_2 b))))
     (if (<= b -1e-152)
       (if (>= b 0.0) (/ (cbrt (pow (- b t_1) 3.0)) (* a 2.0)) t_4)
       (if (<= b 2.2e+86)
         (if (>= b 0.0)
           (* (+ b (sqrt (fma b b t_0))) (/ -0.5 a))
           (* c (/ 2.0 (fma -1.0 b t_1))))
         (if (>= b 0.0) (/ (- (- b) (fma t_2 -2.0 b)) (* a 2.0)) t_4))))))
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 = hypot(b, sqrt(t_0));
	double t_2 = a * (c / b);
	double t_3 = sqrt(((b * b) + t_0));
	double t_4 = (c * 2.0) / (t_3 - b);
	double tmp_1;
	if (b <= -1.65e+161) {
		double tmp_2;
		if (b >= 0.0) {
			tmp_2 = (-b - t_3) / (a * 2.0);
		} else {
			tmp_2 = (c * 2.0) / (2.0 * (t_2 - b));
		}
		tmp_1 = tmp_2;
	} else if (b <= -1e-152) {
		double tmp_3;
		if (b >= 0.0) {
			tmp_3 = cbrt(pow((b - t_1), 3.0)) / (a * 2.0);
		} else {
			tmp_3 = t_4;
		}
		tmp_1 = tmp_3;
	} else if (b <= 2.2e+86) {
		double tmp_4;
		if (b >= 0.0) {
			tmp_4 = (b + sqrt(fma(b, b, t_0))) * (-0.5 / a);
		} else {
			tmp_4 = c * (2.0 / fma(-1.0, b, t_1));
		}
		tmp_1 = tmp_4;
	} else if (b >= 0.0) {
		tmp_1 = (-b - fma(t_2, -2.0, b)) / (a * 2.0);
	} else {
		tmp_1 = t_4;
	}
	return tmp_1;
}
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 = hypot(b, sqrt(t_0))
	t_2 = Float64(a * Float64(c / b))
	t_3 = sqrt(Float64(Float64(b * b) + t_0))
	t_4 = Float64(Float64(c * 2.0) / Float64(t_3 - b))
	tmp_1 = 0.0
	if (b <= -1.65e+161)
		tmp_2 = 0.0
		if (b >= 0.0)
			tmp_2 = Float64(Float64(Float64(-b) - t_3) / Float64(a * 2.0));
		else
			tmp_2 = Float64(Float64(c * 2.0) / Float64(2.0 * Float64(t_2 - b)));
		end
		tmp_1 = tmp_2;
	elseif (b <= -1e-152)
		tmp_3 = 0.0
		if (b >= 0.0)
			tmp_3 = Float64(cbrt((Float64(b - t_1) ^ 3.0)) / Float64(a * 2.0));
		else
			tmp_3 = t_4;
		end
		tmp_1 = tmp_3;
	elseif (b <= 2.2e+86)
		tmp_4 = 0.0
		if (b >= 0.0)
			tmp_4 = Float64(Float64(b + sqrt(fma(b, b, t_0))) * Float64(-0.5 / a));
		else
			tmp_4 = Float64(c * Float64(2.0 / fma(-1.0, b, t_1)));
		end
		tmp_1 = tmp_4;
	elseif (b >= 0.0)
		tmp_1 = Float64(Float64(Float64(-b) - fma(t_2, -2.0, b)) / Float64(a * 2.0));
	else
		tmp_1 = t_4;
	end
	return tmp_1
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[b ^ 2 + N[Sqrt[t$95$0], $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$2 = N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[(N[(b * b), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$3 - b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.65e+161], If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$3), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(2.0 * N[(t$95$2 - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, -1e-152], If[GreaterEqual[b, 0.0], N[(N[Power[N[Power[N[(b - t$95$1), $MachinePrecision], 3.0], $MachinePrecision], 1/3], $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], t$95$4], If[LessEqual[b, 2.2e+86], If[GreaterEqual[b, 0.0], N[(N[(b + N[Sqrt[N[(b * b + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[(c * N[(2.0 / N[(-1.0 * b + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[((-b) - N[(t$95$2 * -2.0 + b), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], t$95$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}
\begin{array}{l}
t_0 := c \cdot \left(a \cdot -4\right)\\
t_1 := \mathsf{hypot}\left(b, \sqrt{t_0}\right)\\
t_2 := a \cdot \frac{c}{b}\\
t_3 := \sqrt{b \cdot b + t_0}\\
t_4 := \frac{c \cdot 2}{t_3 - b}\\
\mathbf{if}\;b \leq -1.65 \cdot 10^{+161}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_3}{a \cdot 2}\\

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


\end{array}\\

\mathbf{elif}\;b \leq -1 \cdot 10^{-152}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\sqrt[3]{{\left(b - t_1\right)}^{3}}}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;t_4\\


\end{array}\\

\mathbf{elif}\;b \leq 2.2 \cdot 10^{+86}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\left(b + \sqrt{\mathsf{fma}\left(b, b, t_0\right)}\right) \cdot \frac{-0.5}{a}\\

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


\end{array}\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \mathsf{fma}\left(t_2, -2, b\right)}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;t_4\\


\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 < -1.64999999999999999e161

    1. Initial program 37.7

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

      \[\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}:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}\\ \end{array} \]
    3. Simplified1.2

      \[\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}:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}}\\ \end{array} \]

    if -1.64999999999999999e161 < b < -1.00000000000000007e-152

    1. Initial program 6.1

      \[\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. Applied egg-rr6.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{{\left({\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{0.25}\right)}^{2}}}{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} \]
    3. Applied egg-rr6.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\color{blue}{\sqrt[3]{{\left(b - \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right)\right)}^{3}}}}{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.00000000000000007e-152 < b < 2.20000000000000003e86

    1. Initial program 10.8

      \[\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. Simplified10.9

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

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

    if 2.20000000000000003e86 < b

    1. Initial program 44.7

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{\left(b - 2 \cdot \frac{c \cdot a}{b}\right)}}{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} \]
    3. Simplified4.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{\mathsf{fma}\left(a \cdot \frac{c}{b}, -2, b\right)}}{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} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification6.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.65 \cdot 10^{+161}:\\ \;\;\;\;\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}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\ \end{array}\\ \mathbf{elif}\;b \leq -1 \cdot 10^{-152}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\sqrt[3]{{\left(b - \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right)\right)}^{3}}}{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 \leq 2.2 \cdot 10^{+86}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}\right) \cdot \frac{-0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{2}{\mathsf{fma}\left(-1, b, \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right)\right)}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \mathsf{fma}\left(a \cdot \frac{c}{b}, -2, b\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}\\ \end{array} \]

Reproduce

herbie shell --seed 2022165 
(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)))))))