Average Error: 34.1 → 9.2
Time: 4.5s
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 -2.37749702272254886 \cdot 10^{101}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\ \mathbf{elif}\;b_2 \le 1.9238883452280037 \cdot 10^{-130}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}{a}\\ \mathbf{elif}\;b_2 \le 4.01993084419163312 \cdot 10^{109}:\\ \;\;\;\;\frac{\frac{0 + a \cdot c}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}}{a}\\ \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 -2.37749702272254886 \cdot 10^{101}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\

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

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

\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 temp;
	if ((b_2 <= -2.377497022722549e+101)) {
		temp = ((0.5 * (c / b_2)) - (2.0 * (b_2 / a)));
	} else {
		double temp_1;
		if ((b_2 <= 1.9238883452280037e-130)) {
			temp_1 = ((sqrt(((b_2 * b_2) - (a * c))) + -b_2) / a);
		} else {
			double temp_2;
			if ((b_2 <= 4.019930844191633e+109)) {
				temp_2 = (((0.0 + (a * c)) / (-b_2 - sqrt(((b_2 * b_2) - (a * c))))) / a);
			} else {
				temp_2 = (-0.5 * (c / b_2));
			}
			temp_1 = temp_2;
		}
		temp = temp_1;
	}
	return temp;
}

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 < -2.377497022722549e+101

    1. Initial program 47.1

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

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

    if -2.377497022722549e+101 < b_2 < 1.9238883452280037e-130

    1. Initial program 11.9

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

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

    if 1.9238883452280037e-130 < b_2 < 4.019930844191633e+109

    1. Initial program 40.3

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

      \[\leadsto \frac{\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}}}}{a}\]
    4. Simplified15.5

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

    if 4.019930844191633e+109 < b_2

    1. Initial program 59.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -2.37749702272254886 \cdot 10^{101}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\ \mathbf{elif}\;b_2 \le 1.9238883452280037 \cdot 10^{-130}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}{a}\\ \mathbf{elif}\;b_2 \le 4.01993084419163312 \cdot 10^{109}:\\ \;\;\;\;\frac{\frac{0 + a \cdot c}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

herbie shell --seed 2020060 +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))