Average Error: 34.0 → 6.8
Time: 12.8s
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 -1.361732391767175 \cdot 10^{+95}:\\ \;\;\;\;\frac{\left(-b_2\right) - b_2}{a}\\ \mathbf{elif}\;b_2 \leq -1.6792010575006621 \cdot 10^{-307}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{elif}\;b_2 \leq 1.1291300979796327 \cdot 10^{+98}:\\ \;\;\;\;\frac{-c}{b_2 + \sqrt{b_2 \cdot b_2 - a \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \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 -1.361732391767175 \cdot 10^{+95}:\\
\;\;\;\;\frac{\left(-b_2\right) - b_2}{a}\\

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

\mathbf{elif}\;b_2 \leq 1.1291300979796327 \cdot 10^{+98}:\\
\;\;\;\;\frac{-c}{b_2 + \sqrt{b_2 \cdot b_2 - a \cdot c}}\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\

\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 -1.361732391767175e+95)
   (/ (- (- b_2) b_2) a)
   (if (<= b_2 -1.6792010575006621e-307)
     (/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
     (if (<= b_2 1.1291300979796327e+98)
       (/ (- c) (+ b_2 (sqrt (- (* b_2 b_2) (* a c)))))
       (* -0.5 (/ c b_2))))))
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 <= -1.361732391767175e+95) {
		tmp = (-b_2 - b_2) / a;
	} else if (b_2 <= -1.6792010575006621e-307) {
		tmp = (sqrt((b_2 * b_2) - (a * c)) - b_2) / a;
	} else if (b_2 <= 1.1291300979796327e+98) {
		tmp = -c / (b_2 + sqrt((b_2 * b_2) - (a * c)));
	} else {
		tmp = -0.5 * (c / b_2);
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b_2

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 4 regimes
  2. if b_2 < -1.361732391767175e95

    1. Initial program 44.2

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

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

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

    if -1.361732391767175e95 < b_2 < -1.6792010575006621e-307

    1. Initial program 9.7

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

    if -1.6792010575006621e-307 < b_2 < 1.1291300979796327e98

    1. Initial program 32.6

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Using strategy rm
    4. Applied clear-num_binary6432.6

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}}\]
    5. Using strategy rm
    6. Applied flip--_binary6432.6

      \[\leadsto \frac{1}{\frac{a}{\color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} \cdot \sqrt{b_2 \cdot b_2 - a \cdot c} - b_2 \cdot b_2}{\sqrt{b_2 \cdot b_2 - a \cdot c} + b_2}}}}\]
    7. Applied associate-/r/_binary6432.7

      \[\leadsto \frac{1}{\color{blue}{\frac{a}{\sqrt{b_2 \cdot b_2 - a \cdot c} \cdot \sqrt{b_2 \cdot b_2 - a \cdot c} - b_2 \cdot b_2} \cdot \left(\sqrt{b_2 \cdot b_2 - a \cdot c} + b_2\right)}}\]
    8. Applied associate-/r*_binary6432.7

      \[\leadsto \color{blue}{\frac{\frac{1}{\frac{a}{\sqrt{b_2 \cdot b_2 - a \cdot c} \cdot \sqrt{b_2 \cdot b_2 - a \cdot c} - b_2 \cdot b_2}}}{\sqrt{b_2 \cdot b_2 - a \cdot c} + b_2}}\]
    9. Simplified32.6

      \[\leadsto \frac{\color{blue}{\frac{b_2 \cdot b_2 - \left(a \cdot c + b_2 \cdot b_2\right)}{a}}}{\sqrt{b_2 \cdot b_2 - a \cdot c} + b_2}\]
    10. Taylor expanded around 0 8.4

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

    if 1.1291300979796327e98 < b_2

    1. Initial program 59.4

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification6.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -1.361732391767175 \cdot 10^{+95}:\\ \;\;\;\;\frac{\left(-b_2\right) - b_2}{a}\\ \mathbf{elif}\;b_2 \leq -1.6792010575006621 \cdot 10^{-307}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{elif}\;b_2 \leq 1.1291300979796327 \cdot 10^{+98}:\\ \;\;\;\;\frac{-c}{b_2 + \sqrt{b_2 \cdot b_2 - a \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

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