Average Error: 33.8 → 9.8
Time: 7.9s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -1 \cdot 10^{+152}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.6 \cdot 10^{-90}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + \mathsf{fma}\left(-c, a \cdot 4, a \cdot \left(c \cdot 4\right)\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \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
 (if (<= b -1e+152)
   (/ (- b) a)
   (if (<= b 1.6e-90)
     (/
      (-
       (sqrt
        (+ (fma b b (* c (* a -4.0))) (fma (- c) (* a 4.0) (* a (* c 4.0)))))
       b)
      (* a 2.0))
     (/ (- c) b))))
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 tmp;
	if (b <= -1e+152) {
		tmp = -b / a;
	} else if (b <= 1.6e-90) {
		tmp = (sqrt((fma(b, b, (c * (a * -4.0))) + fma(-c, (a * 4.0), (a * (c * 4.0))))) - b) / (a * 2.0);
	} else {
		tmp = -c / b;
	}
	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)
	tmp = 0.0
	if (b <= -1e+152)
		tmp = Float64(Float64(-b) / a);
	elseif (b <= 1.6e-90)
		tmp = Float64(Float64(sqrt(Float64(fma(b, b, Float64(c * Float64(a * -4.0))) + fma(Float64(-c), Float64(a * 4.0), Float64(a * Float64(c * 4.0))))) - b) / Float64(a * 2.0));
	else
		tmp = Float64(Float64(-c) / b);
	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_] := If[LessEqual[b, -1e+152], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.6e-90], N[(N[(N[Sqrt[N[(N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[((-c) * N[(a * 4.0), $MachinePrecision] + N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{+152}:\\
\;\;\;\;\frac{-b}{a}\\

\mathbf{elif}\;b \leq 1.6 \cdot 10^{-90}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + \mathsf{fma}\left(-c, a \cdot 4, a \cdot \left(c \cdot 4\right)\right)} - b}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\


\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -1e152

    1. Initial program 63.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Taylor expanded in b around -inf 2.6

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    3. Simplified2.6

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

    if -1e152 < b < 1.60000000000000004e-90

    1. Initial program 11.4

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

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

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

    if 1.60000000000000004e-90 < b

    1. Initial program 52.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Taylor expanded in b around inf 9.9

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    3. Simplified9.9

      \[\leadsto \color{blue}{\frac{-c}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification9.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1 \cdot 10^{+152}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.6 \cdot 10^{-90}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + \mathsf{fma}\left(-c, a \cdot 4, a \cdot \left(c \cdot 4\right)\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Reproduce

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