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

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


\end{array}\\

\mathbf{elif}\;b \leq -4 \cdot 10^{-149}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\sqrt{b + t_2} \cdot \left(-\sqrt{b + t_3}\right)}\\

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


\end{array}\\

\mathbf{elif}\;b \leq 10^{+103}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_4\\

\mathbf{else}:\\
\;\;\;\;{\left(\frac{a \cdot -2}{\mathsf{fma}\left(-1, \mathsf{hypot}\left(b, t_2\right), b\right)}\right)}^{-1}\\


\end{array}\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\

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


\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 < -9.4999999999999995e153

    1. Initial program 64.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} \]
    2. Taylor expanded in b around -inf 2.7

      \[\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} \]

    if -9.4999999999999995e153 < b < -3.99999999999999992e-149

    1. Initial program 5.9

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

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

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

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

    if -3.99999999999999992e-149 < b < 1e103

    1. Initial program 10.9

      \[\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-rr10.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}:\\ \;\;\;\;{\left(\frac{a \cdot -2}{b - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right)}^{-1}\\ \end{array} \]
    3. Applied egg-rr10.2

      \[\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}:\\ \;\;\;\;{\left(\frac{a \cdot -2}{\mathsf{fma}\left(-1, \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right), b\right)}\right)}^{-1}\\ \end{array} \]

    if 1e103 < b

    1. Initial program 30.3

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

      \[\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}:\\ \;\;\;\;{\left(\frac{a \cdot -2}{b - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right)}^{-1}\\ \end{array} \]
    3. Taylor expanded in b around inf 5.8

      \[\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}:\\ \;\;\;\;{\left(\frac{a \cdot -2}{b - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right)}^{-1}\\ \end{array} \]
    4. Simplified2.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -9.5 \cdot 10^{+153}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \leq -4 \cdot 10^{-149}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b + \sqrt{c \cdot \left(a \cdot -4\right)}} \cdot \left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \leq 10^{+103}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{a \cdot -2}{\mathsf{fma}\left(-1, \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right), b\right)}\right)}^{-1}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{a \cdot -2}{b - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right)}^{-1}\\ \end{array} \]

Reproduce

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