Average Error: 34.0 → 6.7
Time: 5.0s
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.427668844436332 \cdot 10^{79}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\ \mathbf{elif}\;b_2 \le -1.6070331019441596 \cdot 10^{-304}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\sqrt[3]{-b_2} \cdot \sqrt[3]{-b_2}, \sqrt[3]{-b_2}, \sqrt{b_2 \cdot b_2 - a \cdot c}\right)}{a}\\ \mathbf{elif}\;b_2 \le 5.6742922648294223 \cdot 10^{63}:\\ \;\;\;\;1 \cdot \frac{c}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}\\ \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.427668844436332 \cdot 10^{79}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\

\mathbf{elif}\;b_2 \le -1.6070331019441596 \cdot 10^{-304}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\sqrt[3]{-b_2} \cdot \sqrt[3]{-b_2}, \sqrt[3]{-b_2}, \sqrt{b_2 \cdot b_2 - a \cdot c}\right)}{a}\\

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

\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.4276688444363324e+79)) {
		temp = ((0.5 * (c / b_2)) - (2.0 * (b_2 / a)));
	} else {
		double temp_1;
		if ((b_2 <= -1.6070331019441596e-304)) {
			temp_1 = (fma((cbrt(-b_2) * cbrt(-b_2)), cbrt(-b_2), sqrt(((b_2 * b_2) - (a * c)))) / a);
		} else {
			double temp_2;
			if ((b_2 <= 5.674292264829422e+63)) {
				temp_2 = (1.0 * (c / (-b_2 - sqrt(((b_2 * b_2) - (a * c))))));
			} 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.4276688444363324e+79

    1. Initial program 43.9

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

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

    if -2.4276688444363324e+79 < b_2 < -1.6070331019441596e-304

    1. Initial program 8.8

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

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{-b_2} \cdot \sqrt[3]{-b_2}\right) \cdot \sqrt[3]{-b_2}} + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    4. Applied fma-def9.1

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

    if -1.6070331019441596e-304 < b_2 < 5.674292264829422e+63

    1. Initial program 29.4

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Using strategy rm
    3. Applied flip-+29.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. Simplified15.7

      \[\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 clear-num15.8

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

      \[\leadsto \frac{1}{\color{blue}{\frac{a}{a \cdot c} \cdot \left(\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}\right)}}\]
    8. Using strategy rm
    9. Applied clear-num15.5

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

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{c}} \cdot \left(\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}\right)}\]
    11. Using strategy rm
    12. Applied div-inv9.1

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

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

    if 5.674292264829422e+63 < b_2

    1. Initial program 57.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -2.427668844436332 \cdot 10^{79}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\ \mathbf{elif}\;b_2 \le -1.6070331019441596 \cdot 10^{-304}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\sqrt[3]{-b_2} \cdot \sqrt[3]{-b_2}, \sqrt[3]{-b_2}, \sqrt{b_2 \cdot b_2 - a \cdot c}\right)}{a}\\ \mathbf{elif}\;b_2 \le 5.6742922648294223 \cdot 10^{63}:\\ \;\;\;\;1 \cdot \frac{c}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

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