Average Error: 33.7 → 7.1
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} t_0 := \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\\ \mathbf{if}\;b \leq -1.3104263752164671 \cdot 10^{+126}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq -1.7696545692563913 \cdot 10^{-275}:\\ \;\;\;\;\frac{\left(t_0 - b\right) \cdot 0.5}{a}\\ \mathbf{elif}\;b \leq 1.2931991447555657 \cdot 10^{+38}:\\ \;\;\;\;\frac{c \cdot -2}{b + t_0}\\ \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
 (let* ((t_0 (sqrt (fma a (* c -4.0) (* b b)))))
   (if (<= b -1.3104263752164671e+126)
     (- (/ b a))
     (if (<= b -1.7696545692563913e-275)
       (/ (* (- t_0 b) 0.5) a)
       (if (<= b 1.2931991447555657e+38)
         (/ (* c -2.0) (+ b t_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 t_0 = sqrt(fma(a, (c * -4.0), (b * b)));
	double tmp;
	if (b <= -1.3104263752164671e+126) {
		tmp = -(b / a);
	} else if (b <= -1.7696545692563913e-275) {
		tmp = ((t_0 - b) * 0.5) / a;
	} else if (b <= 1.2931991447555657e+38) {
		tmp = (c * -2.0) / (b + t_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)
	t_0 = sqrt(fma(a, Float64(c * -4.0), Float64(b * b)))
	tmp = 0.0
	if (b <= -1.3104263752164671e+126)
		tmp = Float64(-Float64(b / a));
	elseif (b <= -1.7696545692563913e-275)
		tmp = Float64(Float64(Float64(t_0 - b) * 0.5) / a);
	elseif (b <= 1.2931991447555657e+38)
		tmp = Float64(Float64(c * -2.0) / Float64(b + t_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_] := Block[{t$95$0 = N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -1.3104263752164671e+126], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, -1.7696545692563913e-275], N[(N[(N[(t$95$0 - b), $MachinePrecision] * 0.5), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 1.2931991447555657e+38], N[(N[(c * -2.0), $MachinePrecision] / N[(b + t$95$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}
t_0 := \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\\
\mathbf{if}\;b \leq -1.3104263752164671 \cdot 10^{+126}:\\
\;\;\;\;-\frac{b}{a}\\

\mathbf{elif}\;b \leq -1.7696545692563913 \cdot 10^{-275}:\\
\;\;\;\;\frac{\left(t_0 - b\right) \cdot 0.5}{a}\\

\mathbf{elif}\;b \leq 1.2931991447555657 \cdot 10^{+38}:\\
\;\;\;\;\frac{c \cdot -2}{b + t_0}\\

\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 4 regimes
  2. if b < -1.3104263752164671e126

    1. Initial program 53.8

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

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b\right) \cdot \frac{0.5}{a}} \]
    3. Applied flip--_binary6463.6

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} \cdot \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b \cdot b}{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} + b}} \cdot \frac{0.5}{a} \]
    4. Applied associate-*l/_binary6463.6

      \[\leadsto \color{blue}{\frac{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} \cdot \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b \cdot b\right) \cdot \frac{0.5}{a}}{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} + b}} \]
    5. Simplified62.6

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    7. Simplified3.2

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

    if -1.3104263752164671e126 < b < -1.76965456925639134e-275

    1. Initial program 8.8

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

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b\right) \cdot \frac{0.5}{a}} \]
    3. Applied associate-*r/_binary648.8

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

    if -1.76965456925639134e-275 < b < 1.2931991447555657e38

    1. Initial program 27.4

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

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b\right) \cdot \frac{0.5}{a}} \]
    3. Applied flip--_binary6427.6

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} \cdot \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b \cdot b}{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} + b}} \cdot \frac{0.5}{a} \]
    4. Applied associate-*l/_binary6427.6

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

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

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

    if 1.2931991447555657e38 < b

    1. Initial program 56.3

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.3104263752164671 \cdot 10^{+126}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq -1.7696545692563913 \cdot 10^{-275}:\\ \;\;\;\;\frac{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b\right) \cdot 0.5}{a}\\ \mathbf{elif}\;b \leq 1.2931991447555657 \cdot 10^{+38}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]

Reproduce

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