Average Error: 33.6 → 11.7
Time: 7.3s
Precision: binary64
\[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
\[\begin{array}{l} t_0 := {\left(\mathsf{fma}\left(-2, \frac{b_2}{c}, 0.5 \cdot \frac{a}{b_2}\right)\right)}^{-1}\\ \mathbf{if}\;b_2 \leq -1 \cdot 10^{+98}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a}\\ \mathbf{elif}\;b_2 \leq 3.9 \cdot 10^{-115}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{elif}\;b_2 \leq 2 \cdot 10^{-46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b_2 \leq 1.55 \cdot 10^{+31}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
(FPCore (a b_2 c)
 :precision binary64
 (let* ((t_0 (pow (fma -2.0 (/ b_2 c) (* 0.5 (/ a b_2))) -1.0)))
   (if (<= b_2 -1e+98)
     (* -2.0 (/ b_2 a))
     (if (<= b_2 3.9e-115)
       (/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
       (if (<= b_2 2e-46)
         t_0
         (if (<= b_2 1.55e+31) (/ (sqrt (* a (- c))) a) t_0))))))
double code(double a, double b_2, double c) {
	return (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
}
double code(double a, double b_2, double c) {
	double t_0 = pow(fma(-2.0, (b_2 / c), (0.5 * (a / b_2))), -1.0);
	double tmp;
	if (b_2 <= -1e+98) {
		tmp = -2.0 * (b_2 / a);
	} else if (b_2 <= 3.9e-115) {
		tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
	} else if (b_2 <= 2e-46) {
		tmp = t_0;
	} else if (b_2 <= 1.55e+31) {
		tmp = sqrt((a * -c)) / a;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b_2, c)
	return Float64(Float64(Float64(-b_2) + sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a)
end
function code(a, b_2, c)
	t_0 = fma(-2.0, Float64(b_2 / c), Float64(0.5 * Float64(a / b_2))) ^ -1.0
	tmp = 0.0
	if (b_2 <= -1e+98)
		tmp = Float64(-2.0 * Float64(b_2 / a));
	elseif (b_2 <= 3.9e-115)
		tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c))) - b_2) / a);
	elseif (b_2 <= 2e-46)
		tmp = t_0;
	elseif (b_2 <= 1.55e+31)
		tmp = Float64(sqrt(Float64(a * Float64(-c))) / a);
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) + N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
code[a_, b$95$2_, c_] := Block[{t$95$0 = N[Power[N[(-2.0 * N[(b$95$2 / c), $MachinePrecision] + N[(0.5 * N[(a / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]}, If[LessEqual[b$95$2, -1e+98], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 3.9e-115], N[(N[(N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, 2e-46], t$95$0, If[LessEqual[b$95$2, 1.55e+31], N[(N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision], t$95$0]]]]]
\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\begin{array}{l}
t_0 := {\left(\mathsf{fma}\left(-2, \frac{b_2}{c}, 0.5 \cdot \frac{a}{b_2}\right)\right)}^{-1}\\
\mathbf{if}\;b_2 \leq -1 \cdot 10^{+98}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a}\\

\mathbf{elif}\;b_2 \leq 3.9 \cdot 10^{-115}:\\
\;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\

\mathbf{elif}\;b_2 \leq 2 \cdot 10^{-46}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;b_2 \leq 1.55 \cdot 10^{+31}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)}}{a}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Bits error versus a

Bits error versus b_2

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b_2 < -9.99999999999999998e97

    1. Initial program 47.5

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Simplified47.5

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    3. Taylor expanded in b_2 around -inf 3.5

      \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a}} \]

    if -9.99999999999999998e97 < b_2 < 3.8999999999999998e-115

    1. Initial program 11.1

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Simplified11.1

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]

    if 3.8999999999999998e-115 < b_2 < 2.00000000000000005e-46 or 1.5500000000000001e31 < b_2

    1. Initial program 52.7

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Simplified52.7

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    3. Applied egg-rr52.8

      \[\leadsto \color{blue}{{\left(\frac{a}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}\right)}^{-1}} \]
    4. Taylor expanded in a around 0 9.7

      \[\leadsto {\color{blue}{\left(0.5 \cdot \frac{a}{b_2} - 2 \cdot \frac{b_2}{c}\right)}}^{-1} \]
    5. Simplified9.7

      \[\leadsto {\color{blue}{\left(\mathsf{fma}\left(-2, \frac{b_2}{c}, 0.5 \cdot \frac{a}{b_2}\right)\right)}}^{-1} \]

    if 2.00000000000000005e-46 < b_2 < 1.5500000000000001e31

    1. Initial program 41.5

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Simplified41.5

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    3. Taylor expanded in b_2 around 0 43.7

      \[\leadsto \color{blue}{\frac{\sqrt{-c \cdot a}}{a}} \]
    4. Simplified43.7

      \[\leadsto \color{blue}{\frac{\sqrt{c \cdot \left(-a\right)}}{a}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification11.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -1 \cdot 10^{+98}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a}\\ \mathbf{elif}\;b_2 \leq 3.9 \cdot 10^{-115}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{elif}\;b_2 \leq 2 \cdot 10^{-46}:\\ \;\;\;\;{\left(\mathsf{fma}\left(-2, \frac{b_2}{c}, 0.5 \cdot \frac{a}{b_2}\right)\right)}^{-1}\\ \mathbf{elif}\;b_2 \leq 1.55 \cdot 10^{+31}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;{\left(\mathsf{fma}\left(-2, \frac{b_2}{c}, 0.5 \cdot \frac{a}{b_2}\right)\right)}^{-1}\\ \end{array} \]

Reproduce

herbie shell --seed 2022162 
(FPCore (a b_2 c)
  :name "quad2p (problem 3.2.1, positive)"
  :precision binary64
  (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))