Average Error: 33.8 → 11.3
Time: 7.2s
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 -8.5 \cdot 10^{+153}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -1.3 \cdot 10^{-163}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-1, b, \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}\right)}{a \cdot 2}\\ \mathbf{elif}\;b \leq -1.52 \cdot 10^{-279}:\\ \;\;\;\;{\left(\sqrt[3]{\mathsf{fma}\left(b, -1, \mathsf{hypot}\left(b, \sqrt{a \cdot -4} \cdot \sqrt{c}\right)\right) \cdot \frac{0.5}{a}}\right)}^{3}\\ \mathbf{elif}\;b \leq 1.22 \cdot 10^{-82}:\\ \;\;\;\;\frac{0.5 \cdot \mathsf{fma}\left(b, -1, \mathsf{hypot}\left(b, \sqrt{-4 \cdot \left(c \cdot a\right)}\right)\right)}{a}\\ \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 -8.5e+153)
   (- (/ c b) (/ b a))
   (if (<= b -1.3e-163)
     (/ (fma -1.0 b (sqrt (fma b b (* c (* a -4.0))))) (* a 2.0))
     (if (<= b -1.52e-279)
       (pow
        (cbrt
         (* (fma b -1.0 (hypot b (* (sqrt (* a -4.0)) (sqrt c)))) (/ 0.5 a)))
        3.0)
       (if (<= b 1.22e-82)
         (/ (* 0.5 (fma b -1.0 (hypot b (sqrt (* -4.0 (* c a)))))) a)
         (/ (- 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 <= -8.5e+153) {
		tmp = (c / b) - (b / a);
	} else if (b <= -1.3e-163) {
		tmp = fma(-1.0, b, sqrt(fma(b, b, (c * (a * -4.0))))) / (a * 2.0);
	} else if (b <= -1.52e-279) {
		tmp = pow(cbrt((fma(b, -1.0, hypot(b, (sqrt((a * -4.0)) * sqrt(c)))) * (0.5 / a))), 3.0);
	} else if (b <= 1.22e-82) {
		tmp = (0.5 * fma(b, -1.0, hypot(b, sqrt((-4.0 * (c * a)))))) / a;
	} 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 <= -8.5e+153)
		tmp = Float64(Float64(c / b) - Float64(b / a));
	elseif (b <= -1.3e-163)
		tmp = Float64(fma(-1.0, b, sqrt(fma(b, b, Float64(c * Float64(a * -4.0))))) / Float64(a * 2.0));
	elseif (b <= -1.52e-279)
		tmp = cbrt(Float64(fma(b, -1.0, hypot(b, Float64(sqrt(Float64(a * -4.0)) * sqrt(c)))) * Float64(0.5 / a))) ^ 3.0;
	elseif (b <= 1.22e-82)
		tmp = Float64(Float64(0.5 * fma(b, -1.0, hypot(b, sqrt(Float64(-4.0 * Float64(c * a)))))) / a);
	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, -8.5e+153], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -1.3e-163], N[(N[(-1.0 * b + N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -1.52e-279], N[Power[N[Power[N[(N[(b * -1.0 + N[Sqrt[b ^ 2 + N[(N[Sqrt[N[(a * -4.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[c], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision], If[LessEqual[b, 1.22e-82], N[(N[(0.5 * N[(b * -1.0 + N[Sqrt[b ^ 2 + N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $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 -8.5 \cdot 10^{+153}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

\mathbf{elif}\;b \leq -1.52 \cdot 10^{-279}:\\
\;\;\;\;{\left(\sqrt[3]{\mathsf{fma}\left(b, -1, \mathsf{hypot}\left(b, \sqrt{a \cdot -4} \cdot \sqrt{c}\right)\right) \cdot \frac{0.5}{a}}\right)}^{3}\\

\mathbf{elif}\;b \leq 1.22 \cdot 10^{-82}:\\
\;\;\;\;\frac{0.5 \cdot \mathsf{fma}\left(b, -1, \mathsf{hypot}\left(b, \sqrt{-4 \cdot \left(c \cdot a\right)}\right)\right)}{a}\\

\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 5 regimes
  2. if b < -8.49999999999999935e153

    1. Initial program 63.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 1.8

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

    if -8.49999999999999935e153 < b < -1.30000000000000001e-163

    1. Initial program 5.4

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

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

    if -1.30000000000000001e-163 < b < -1.5200000000000001e-279

    1. Initial program 16.2

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

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

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\mathsf{fma}\left(b, -1, \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right)\right) \cdot \frac{0.5}{a}}\right)}^{3}} \]
    4. Applied egg-rr33.7

      \[\leadsto {\left(\sqrt[3]{\mathsf{fma}\left(b, -1, \mathsf{hypot}\left(b, \color{blue}{\sqrt{a \cdot -4} \cdot \sqrt{c}}\right)\right) \cdot \frac{0.5}{a}}\right)}^{3} \]

    if -1.5200000000000001e-279 < b < 1.22000000000000001e-82

    1. Initial program 20.8

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

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

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\mathsf{fma}\left(b, -1, \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right)\right) \cdot \frac{0.5}{a}}\right)}^{3}} \]
    4. Applied egg-rr20.9

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

    if 1.22000000000000001e-82 < b

    1. Initial program 53.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -8.5 \cdot 10^{+153}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -1.3 \cdot 10^{-163}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-1, b, \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}\right)}{a \cdot 2}\\ \mathbf{elif}\;b \leq -1.52 \cdot 10^{-279}:\\ \;\;\;\;{\left(\sqrt[3]{\mathsf{fma}\left(b, -1, \mathsf{hypot}\left(b, \sqrt{a \cdot -4} \cdot \sqrt{c}\right)\right) \cdot \frac{0.5}{a}}\right)}^{3}\\ \mathbf{elif}\;b \leq 1.22 \cdot 10^{-82}:\\ \;\;\;\;\frac{0.5 \cdot \mathsf{fma}\left(b, -1, \mathsf{hypot}\left(b, \sqrt{-4 \cdot \left(c \cdot a\right)}\right)\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Reproduce

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