Average Error: 34.0 → 10.1
Time: 6.9s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} t_0 := a \cdot \left(c \cdot -4\right)\\ t_1 := \frac{-c}{b}\\ \mathbf{if}\;b \leq -2.15 \cdot 10^{+105}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 6.2 \cdot 10^{-55}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, t_0\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 1.7 \cdot 10^{-46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 6.6 \cdot 10^{-22}:\\ \;\;\;\;\frac{\frac{\mathsf{hypot}\left(b, \sqrt{t_0}\right) - b}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (* a (* c -4.0))) (t_1 (/ (- c) b)))
   (if (<= b -2.15e+105)
     (- (/ c b) (/ b a))
     (if (<= b 6.2e-55)
       (/ (- (sqrt (fma b b t_0)) b) (* a 2.0))
       (if (<= b 1.7e-46)
         t_1
         (if (<= b 6.6e-22) (/ (/ (- (hypot b (sqrt t_0)) b) a) 2.0) t_1))))))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
double code(double a, double b, double c) {
	double t_0 = a * (c * -4.0);
	double t_1 = -c / b;
	double tmp;
	if (b <= -2.15e+105) {
		tmp = (c / b) - (b / a);
	} else if (b <= 6.2e-55) {
		tmp = (sqrt(fma(b, b, t_0)) - b) / (a * 2.0);
	} else if (b <= 1.7e-46) {
		tmp = t_1;
	} else if (b <= 6.6e-22) {
		tmp = ((hypot(b, sqrt(t_0)) - b) / a) / 2.0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a))
end
function code(a, b, c)
	t_0 = Float64(a * Float64(c * -4.0))
	t_1 = Float64(Float64(-c) / b)
	tmp = 0.0
	if (b <= -2.15e+105)
		tmp = Float64(Float64(c / b) - Float64(b / a));
	elseif (b <= 6.2e-55)
		tmp = Float64(Float64(sqrt(fma(b, b, t_0)) - b) / Float64(a * 2.0));
	elseif (b <= 1.7e-46)
		tmp = t_1;
	elseif (b <= 6.6e-22)
		tmp = Float64(Float64(Float64(hypot(b, sqrt(t_0)) - b) / a) / 2.0);
	else
		tmp = t_1;
	end
	return tmp
end
code[a_, b_, c_] := 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[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-c) / b), $MachinePrecision]}, If[LessEqual[b, -2.15e+105], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.2e-55], N[(N[(N[Sqrt[N[(b * b + t$95$0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.7e-46], t$95$1, If[LessEqual[b, 6.6e-22], N[(N[(N[(N[Sqrt[b ^ 2 + N[Sqrt[t$95$0], $MachinePrecision] ^ 2], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision] / 2.0), $MachinePrecision], t$95$1]]]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
t_0 := a \cdot \left(c \cdot -4\right)\\
t_1 := \frac{-c}{b}\\
\mathbf{if}\;b \leq -2.15 \cdot 10^{+105}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq 6.2 \cdot 10^{-55}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, t_0\right)} - b}{a \cdot 2}\\

\mathbf{elif}\;b \leq 1.7 \cdot 10^{-46}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;b \leq 6.6 \cdot 10^{-22}:\\
\;\;\;\;\frac{\frac{\mathsf{hypot}\left(b, \sqrt{t_0}\right) - b}{a}}{2}\\

\mathbf{else}:\\
\;\;\;\;t_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 < -2.1500000000000001e105

    1. Initial program 47.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Simplified47.0

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b}{a \cdot 2}} \]
    3. Taylor expanded in b around -inf 3.0

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

    if -2.1500000000000001e105 < b < 6.19999999999999993e-55

    1. Initial program 13.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Simplified13.5

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b}{a \cdot 2}} \]

    if 6.19999999999999993e-55 < b < 1.69999999999999998e-46 or 6.6000000000000002e-22 < b

    1. Initial program 54.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Simplified54.5

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b}{a \cdot 2}} \]
    3. Taylor expanded in b around inf 7.2

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    4. Simplified7.2

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

    if 1.69999999999999998e-46 < b < 6.6000000000000002e-22

    1. Initial program 37.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Simplified37.2

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b}{a \cdot 2}} \]
    3. Applied egg-rr38.5

      \[\leadsto \color{blue}{\left(\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right) - b\right) \cdot \frac{1}{a \cdot 2}} \]
    4. Applied egg-rr38.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.15 \cdot 10^{+105}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 6.2 \cdot 10^{-55}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 1.7 \cdot 10^{-46}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 6.6 \cdot 10^{-22}:\\ \;\;\;\;\frac{\frac{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right) - b}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Reproduce

herbie shell --seed 2022155 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))