Average Error: 34.0 → 8.3
Time: 4.2s
Precision: 64
\[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
\[\begin{array}{l} \mathbf{if}\;b_2 \le -1.3324370156406744 \cdot 10^{154}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\ \mathbf{elif}\;b_2 \le -2.8947243902888692 \cdot 10^{-170}:\\ \;\;\;\;\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\\ \mathbf{elif}\;b_2 \le 4.05510754439488906 \cdot 10^{-23}:\\ \;\;\;\;\frac{\frac{a}{\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{c}}}{\frac{a}{1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \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 \le -1.3324370156406744 \cdot 10^{154}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\

\mathbf{elif}\;b_2 \le -2.8947243902888692 \cdot 10^{-170}:\\
\;\;\;\;\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\\

\mathbf{elif}\;b_2 \le 4.05510754439488906 \cdot 10^{-23}:\\
\;\;\;\;\frac{\frac{a}{\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{c}}}{\frac{a}{1}}\\

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

\end{array}
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 VAR;
	if ((b_2 <= -1.3324370156406744e+154)) {
		VAR = ((0.5 * (c / b_2)) - (2.0 * (b_2 / a)));
	} else {
		double VAR_1;
		if ((b_2 <= -2.8947243902888692e-170)) {
			VAR_1 = ((-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a);
		} else {
			double VAR_2;
			if ((b_2 <= 4.055107544394889e-23)) {
				VAR_2 = ((a / ((-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / c)) / (a / 1.0));
			} else {
				VAR_2 = (-0.5 * (c / b_2));
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	return VAR;
}

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.3324370156406744e+154

    1. Initial program 64.0

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Taylor expanded around -inf 2.6

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

    if -1.3324370156406744e+154 < b_2 < -2.8947243902888692e-170

    1. Initial program 6.6

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

    if -2.8947243902888692e-170 < b_2 < 4.055107544394889e-23

    1. Initial program 21.2

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Using strategy rm
    3. Applied div-inv21.3

      \[\leadsto \color{blue}{\left(\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}\right) \cdot \frac{1}{a}}\]
    4. Using strategy rm
    5. Applied flip-+21.6

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

      \[\leadsto \frac{\color{blue}{0 + 1 \cdot \left(a \cdot c\right)}}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}} \cdot \frac{1}{a}\]
    7. Using strategy rm
    8. Applied clear-num16.8

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

      \[\leadsto \color{blue}{\frac{\frac{0 + 1 \cdot \left(a \cdot c\right)}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}} \cdot 1}{\frac{a}{1}}}\]
    10. Simplified14.4

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

    if 4.055107544394889e-23 < b_2

    1. Initial program 55.1

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Taylor expanded around inf 6.4

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b_2}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification8.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -1.3324370156406744 \cdot 10^{154}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\ \mathbf{elif}\;b_2 \le -2.8947243902888692 \cdot 10^{-170}:\\ \;\;\;\;\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\\ \mathbf{elif}\;b_2 \le 4.05510754439488906 \cdot 10^{-23}:\\ \;\;\;\;\frac{\frac{a}{\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{c}}}{\frac{a}{1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

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