Average Error: 34.7 → 8.2
Time: 8.4s
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.59935918986980612 \cdot 10^{99}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\ \mathbf{elif}\;b_2 \le 1.1645666821487491 \cdot 10^{-186}:\\ \;\;\;\;\frac{1}{\frac{a}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}\\ \mathbf{elif}\;b_2 \le 6.94810397910727439 \cdot 10^{-8}:\\ \;\;\;\;\frac{\frac{a}{\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{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 -1.59935918986980612 \cdot 10^{99}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\

\mathbf{elif}\;b_2 \le 1.1645666821487491 \cdot 10^{-186}:\\
\;\;\;\;\frac{1}{\frac{a}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}\\

\mathbf{elif}\;b_2 \le 6.94810397910727439 \cdot 10^{-8}:\\
\;\;\;\;\frac{\frac{a}{\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{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 VAR;
	if ((b_2 <= -1.599359189869806e+99)) {
		VAR = ((0.5 * (c / b_2)) - (2.0 * (b_2 / a)));
	} else {
		double VAR_1;
		if ((b_2 <= 1.164566682148749e-186)) {
			VAR_1 = (1.0 / (a / (sqrt(((b_2 * b_2) - (a * c))) - b_2)));
		} else {
			double VAR_2;
			if ((b_2 <= 6.948103979107274e-08)) {
				VAR_2 = ((a / ((-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / c)) / a);
			} 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.599359189869806e+99

    1. Initial program 48.1

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

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

    if -1.599359189869806e+99 < b_2 < 1.164566682148749e-186

    1. Initial program 10.8

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

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

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

    if 1.164566682148749e-186 < b_2 < 6.948103979107274e-08

    1. Initial program 30.4

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

      \[\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. Simplified17.1

      \[\leadsto \frac{\frac{\color{blue}{0 + a \cdot c}}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}}{a}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity17.1

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

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

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

    if 6.948103979107274e-08 < b_2

    1. Initial program 56.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -1.59935918986980612 \cdot 10^{99}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\ \mathbf{elif}\;b_2 \le 1.1645666821487491 \cdot 10^{-186}:\\ \;\;\;\;\frac{1}{\frac{a}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}\\ \mathbf{elif}\;b_2 \le 6.94810397910727439 \cdot 10^{-8}:\\ \;\;\;\;\frac{\frac{a}{\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{c}}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

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