Average Error: 28.5 → 5.3
Time: 4.4s
Precision: binary64
\[\left(\left(1.0536712127723509 \cdot 10^{-8} < a \land a < 94906265.62425156\right) \land \left(1.0536712127723509 \cdot 10^{-8} < b \land b < 94906265.62425156\right)\right) \land \left(1.0536712127723509 \cdot 10^{-8} < c \land c < 94906265.62425156\right)\]
\[\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)\\ \mathbf{if}\;b \leq 0.0033:\\ \;\;\;\;\frac{\sqrt{t_0 \cdot \left(1 + \frac{b \cdot b}{t_0}\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\mathsf{fma}\left(2, \frac{a \cdot a}{\frac{{b}^{5}}{{c}^{3}}}, \mathsf{fma}\left(5, {a}^{3} \cdot \frac{{c}^{4}}{{b}^{7}}, \mathsf{fma}\left(c \cdot c, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{a}{{b}^{3}}\right)\right), \frac{c}{b}\right)\right)\right)\\ \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))))
   (if (<= b 0.0033)
     (/ (- (sqrt (* t_0 (+ 1.0 (/ (* b b) t_0)))) b) (* a 2.0))
     (-
      (fma
       2.0
       (/ (* a a) (/ (pow b 5.0) (pow c 3.0)))
       (fma
        5.0
        (* (pow a 3.0) (/ (pow c 4.0) (pow b 7.0)))
        (fma (* c c) (expm1 (log1p (/ a (pow b 3.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 = a * (c * -4.0);
	double tmp;
	if (b <= 0.0033) {
		tmp = (sqrt((t_0 * (1.0 + ((b * b) / t_0)))) - b) / (a * 2.0);
	} else {
		tmp = -fma(2.0, ((a * a) / (pow(b, 5.0) / pow(c, 3.0))), fma(5.0, (pow(a, 3.0) * (pow(c, 4.0) / pow(b, 7.0))), fma((c * c), expm1(log1p((a / pow(b, 3.0)))), (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 = Float64(a * Float64(c * -4.0))
	tmp = 0.0
	if (b <= 0.0033)
		tmp = Float64(Float64(sqrt(Float64(t_0 * Float64(1.0 + Float64(Float64(b * b) / t_0)))) - b) / Float64(a * 2.0));
	else
		tmp = Float64(-fma(2.0, Float64(Float64(a * a) / Float64((b ^ 5.0) / (c ^ 3.0))), fma(5.0, Float64((a ^ 3.0) * Float64((c ^ 4.0) / (b ^ 7.0))), fma(Float64(c * c), expm1(log1p(Float64(a / (b ^ 3.0)))), 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[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 0.0033], N[(N[(N[Sqrt[N[(t$95$0 * N[(1.0 + N[(N[(b * b), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], (-N[(2.0 * N[(N[(a * a), $MachinePrecision] / N[(N[Power[b, 5.0], $MachinePrecision] / N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(5.0 * N[(N[Power[a, 3.0], $MachinePrecision] * N[(N[Power[c, 4.0], $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(c * c), $MachinePrecision] * N[(Exp[N[Log[1 + N[(a / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision])]]
\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)\\
\mathbf{if}\;b \leq 0.0033:\\
\;\;\;\;\frac{\sqrt{t_0 \cdot \left(1 + \frac{b \cdot b}{t_0}\right)} - b}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;-\mathsf{fma}\left(2, \frac{a \cdot a}{\frac{{b}^{5}}{{c}^{3}}}, \mathsf{fma}\left(5, {a}^{3} \cdot \frac{{c}^{4}}{{b}^{7}}, \mathsf{fma}\left(c \cdot c, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{a}{{b}^{3}}\right)\right), \frac{c}{b}\right)\right)\right)\\


\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 0.0033

    1. Initial program 7.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Simplified7.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-rr7.3

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

    if 0.0033 < b

    1. Initial program 29.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Simplified29.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 5.1

      \[\leadsto \color{blue}{-\left(2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} + \left(5 \cdot \frac{{c}^{4} \cdot {a}^{3}}{{b}^{7}} + \left(\frac{{c}^{2} \cdot a}{{b}^{3}} + \frac{c}{b}\right)\right)\right)} \]
    4. Simplified5.1

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

      \[\leadsto -\mathsf{fma}\left(2, \frac{a \cdot a}{\frac{{b}^{5}}{{c}^{3}}}, \mathsf{fma}\left(5, {a}^{3} \cdot \frac{{c}^{4}}{{b}^{7}}, \mathsf{fma}\left(c \cdot c, \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{a}{{b}^{3}}\right)\right)}, \frac{c}{b}\right)\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification5.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 0.0033:\\ \;\;\;\;\frac{\sqrt{\left(a \cdot \left(c \cdot -4\right)\right) \cdot \left(1 + \frac{b \cdot b}{a \cdot \left(c \cdot -4\right)}\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\mathsf{fma}\left(2, \frac{a \cdot a}{\frac{{b}^{5}}{{c}^{3}}}, \mathsf{fma}\left(5, {a}^{3} \cdot \frac{{c}^{4}}{{b}^{7}}, \mathsf{fma}\left(c \cdot c, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{a}{{b}^{3}}\right)\right), \frac{c}{b}\right)\right)\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022155 
(FPCore (a b c)
  :name "Quadratic roots, narrow range"
  :precision binary64
  :pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))