Average Error: 34.3 → 11.5
Time: 9.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 -2.23401914471045 \cdot 10^{+152}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b_2}, -2 \cdot \frac{b_2}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := \sqrt{b_2 \cdot b_2 - c \cdot a}\\ \mathbf{if}\;b_2 \leq 2.9407118485521444 \cdot 10^{-128}:\\ \;\;\;\;\frac{t_0 - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_1 := \frac{c}{b_2} \cdot -0.5\\ \mathbf{if}\;b_2 \leq 1.547379492825384 \cdot 10^{-89}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b_2 \leq 124431463817995.98:\\ \;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{a}, -\frac{b_2}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array}\\ \end{array}\\ \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 -2.23401914471045 \cdot 10^{+152}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b_2}, -2 \cdot \frac{b_2}{a}\right)\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \sqrt{b_2 \cdot b_2 - c \cdot a}\\
\mathbf{if}\;b_2 \leq 2.9407118485521444 \cdot 10^{-128}:\\
\;\;\;\;\frac{t_0 - b_2}{a}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := \frac{c}{b_2} \cdot -0.5\\
\mathbf{if}\;b_2 \leq 1.547379492825384 \cdot 10^{-89}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;b_2 \leq 124431463817995.98:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{a}, -\frac{b_2}{a}\right)\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}\\


\end{array}\\


\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 -2.23401914471045e+152)
   (fma 0.5 (/ c b_2) (* -2.0 (/ b_2 a)))
   (let* ((t_0 (sqrt (- (* b_2 b_2) (* c a)))))
     (if (<= b_2 2.9407118485521444e-128)
       (/ (- t_0 b_2) a)
       (let* ((t_1 (* (/ c b_2) -0.5)))
         (if (<= b_2 1.547379492825384e-89)
           t_1
           (if (<= b_2 124431463817995.98)
             (fma t_0 (/ 1.0 a) (- (/ b_2 a)))
             t_1)))))))
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 <= -2.23401914471045e+152) {
		tmp = fma(0.5, (c / b_2), (-2.0 * (b_2 / a)));
	} else {
		double t_0 = sqrt((b_2 * b_2) - (c * a));
		double tmp_1;
		if (b_2 <= 2.9407118485521444e-128) {
			tmp_1 = (t_0 - b_2) / a;
		} else {
			double t_1 = (c / b_2) * -0.5;
			double tmp_2;
			if (b_2 <= 1.547379492825384e-89) {
				tmp_2 = t_1;
			} else if (b_2 <= 124431463817995.98) {
				tmp_2 = fma(t_0, (1.0 / a), -(b_2 / a));
			} else {
				tmp_2 = t_1;
			}
			tmp_1 = tmp_2;
		}
		tmp = tmp_1;
	}
	return tmp;
}

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 < -2.2340191447104499e152

    1. Initial program 63.1

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

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

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

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

    if -2.2340191447104499e152 < b_2 < 2.94071184855214437e-128

    1. Initial program 10.6

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{{\left(b_2 \cdot b_2 - a \cdot c\right)}^{1}}} - b_2}{a} \]

    if 2.94071184855214437e-128 < b_2 < 1.5473794928253839e-89 or 124431463817995.984 < b_2

    1. Initial program 53.8

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

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

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

    if 1.5473794928253839e-89 < b_2 < 124431463817995.984

    1. Initial program 38.7

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}} \]
    4. Applied egg38.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -2.23401914471045 \cdot 10^{+152}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b_2}, -2 \cdot \frac{b_2}{a}\right)\\ \mathbf{elif}\;b_2 \leq 2.9407118485521444 \cdot 10^{-128}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2}{a}\\ \mathbf{elif}\;b_2 \leq 1.547379492825384 \cdot 10^{-89}:\\ \;\;\;\;\frac{c}{b_2} \cdot -0.5\\ \mathbf{elif}\;b_2 \leq 124431463817995.98:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{b_2 \cdot b_2 - c \cdot a}, \frac{1}{a}, -\frac{b_2}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot -0.5\\ \end{array} \]

Reproduce

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