Average Error: 34.3 → 10.3
Time: 13.2s
Precision: binary64
\[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
\[\begin{array}{l} \mathbf{if}\;b_2 \leq -7.563214498963372 \cdot 10^{+93}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b_2}, -2 \cdot \frac{b_2}{a}\right)\\ \mathbf{elif}\;b_2 \leq 4.903807995826219 \cdot 10^{-77}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(0.5, \frac{a}{b_2}, 2 \cdot \frac{b_2}{-c}\right)}\\ \end{array} \]
\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\begin{array}{l}
\mathbf{if}\;b_2 \leq -7.563214498963372 \cdot 10^{+93}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b_2}, -2 \cdot \frac{b_2}{a}\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.5, \frac{a}{b_2}, 2 \cdot \frac{b_2}{-c}\right)}\\


\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
 (if (<= b_2 -7.563214498963372e+93)
   (fma 0.5 (/ c b_2) (* -2.0 (/ b_2 a)))
   (if (<= b_2 4.903807995826219e-77)
     (/ (- (sqrt (- (* b_2 b_2) (* c a))) b_2) a)
     (/ 1.0 (fma 0.5 (/ a b_2) (* 2.0 (/ b_2 (- c))))))))
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 tmp;
	if (b_2 <= -7.563214498963372e+93) {
		tmp = fma(0.5, (c / b_2), (-2.0 * (b_2 / a)));
	} else if (b_2 <= 4.903807995826219e-77) {
		tmp = (sqrt((b_2 * b_2) - (c * a)) - b_2) / a;
	} else {
		tmp = 1.0 / fma(0.5, (a / b_2), (2.0 * (b_2 / -c)));
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b_2

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b_2 < -7.5632144989633717e93

    1. Initial program 45.9

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}} \]
    4. Simplified3.6

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

    if -7.5632144989633717e93 < b_2 < 4.9038079958262192e-77

    1. Initial program 13.6

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    3. Applied *-un-lft-identity_binary6413.6

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

    if 4.9038079958262192e-77 < b_2

    1. Initial program 53.3

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    3. Applied clear-num_binary6453.3

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}} \]
    4. Simplified47.9

      \[\leadsto \frac{1}{\color{blue}{\frac{a}{\mathsf{hypot}\left(\sqrt{-c \cdot a}, b_2\right) - b_2}}} \]
    5. Taylor expanded in b_2 around inf 39.8

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

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(0.5, \frac{a}{b_2}, 2 \cdot \frac{b_2}{-c}\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification10.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -7.563214498963372 \cdot 10^{+93}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b_2}, -2 \cdot \frac{b_2}{a}\right)\\ \mathbf{elif}\;b_2 \leq 4.903807995826219 \cdot 10^{-77}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(0.5, \frac{a}{b_2}, 2 \cdot \frac{b_2}{-c}\right)}\\ \end{array} \]

Reproduce

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