Average Error: 19.6 → 8.8
Time: 10.0s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le -7.9501683196199669 \cdot 10^{81}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}\\ \end{array}\\ \mathbf{elif}\;b \le 1.38731738723855584 \cdot 10^{50}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\sqrt{-b}, \sqrt{-b}, \sqrt{\mathsf{fma}\left(b, b, -\left(\sqrt[3]{a} \cdot c\right) \cdot \left(4 \cdot \left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right)\right)\right) + \left(4 \cdot \left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right)\right) \cdot \left(\left(-\sqrt[3]{a} \cdot c\right) + \sqrt[3]{a} \cdot c\right)}\right)}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \left(b - 2 \cdot \frac{a \cdot c}{b}\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

\end{array}
\begin{array}{l}
\mathbf{if}\;b \le -7.9501683196199669 \cdot 10^{81}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}\\

\end{array}\\

\mathbf{elif}\;b \le 1.38731738723855584 \cdot 10^{50}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\sqrt{-b}, \sqrt{-b}, \sqrt{\mathsf{fma}\left(b, b, -\left(\sqrt[3]{a} \cdot c\right) \cdot \left(4 \cdot \left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right)\right)\right) + \left(4 \cdot \left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right)\right) \cdot \left(\left(-\sqrt[3]{a} \cdot c\right) + \sqrt[3]{a} \cdot c\right)}\right)}\\

\end{array}\\

\mathbf{elif}\;b \ge 0.0:\\
\;\;\;\;\frac{\left(-b\right) - \left(b - 2 \cdot \frac{a \cdot c}{b}\right)}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

\end{array}
double code(double a, double b, double c) {
	double VAR;
	if ((b >= 0.0)) {
		VAR = ((double) (((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))) / ((double) (2.0 * a))));
	} else {
		VAR = ((double) (((double) (2.0 * c)) / ((double) (((double) -(b)) + ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c))))))))));
	}
	return VAR;
}
double code(double a, double b, double c) {
	double VAR;
	if ((b <= -7.950168319619967e+81)) {
		double VAR_1;
		if ((b >= 0.0)) {
			VAR_1 = ((double) (((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))) / ((double) (2.0 * a))));
		} else {
			VAR_1 = ((double) (((double) (2.0 * c)) / ((double) (((double) (2.0 * ((double) (((double) (a * c)) / b)))) - ((double) (2.0 * b))))));
		}
		VAR = VAR_1;
	} else {
		double VAR_2;
		if ((b <= 1.3873173872385558e+50)) {
			double VAR_3;
			if ((b >= 0.0)) {
				VAR_3 = ((double) (((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))) / ((double) (2.0 * a))));
			} else {
				VAR_3 = ((double) (((double) (2.0 * c)) / ((double) fma(((double) sqrt(((double) -(b)))), ((double) sqrt(((double) -(b)))), ((double) sqrt(((double) (((double) fma(b, b, ((double) -(((double) (((double) (((double) cbrt(a)) * c)) * ((double) (4.0 * ((double) (((double) cbrt(a)) * ((double) cbrt(a)))))))))))) + ((double) (((double) (4.0 * ((double) (((double) cbrt(a)) * ((double) cbrt(a)))))) * ((double) (((double) -(((double) (((double) cbrt(a)) * c)))) + ((double) (((double) cbrt(a)) * c))))))))))))));
			}
			VAR_2 = VAR_3;
		} else {
			double VAR_4;
			if ((b >= 0.0)) {
				VAR_4 = ((double) (((double) (((double) -(b)) - ((double) (b - ((double) (2.0 * ((double) (((double) (a * c)) / b)))))))) / ((double) (2.0 * a))));
			} else {
				VAR_4 = ((double) (((double) (2.0 * c)) / ((double) (((double) -(b)) + ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c))))))))));
			}
			VAR_2 = VAR_4;
		}
		VAR = VAR_2;
	}
	return VAR;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if b < -7.950168319619967e+81

    1. Initial program 27.7

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Taylor expanded around -inf 7.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}\\ \end{array}\]

    if -7.950168319619967e+81 < b < 1.3873173872385558e+50

    1. Initial program 9.2

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt9.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\color{blue}{2 \cdot c}}{\sqrt{-b} \cdot \sqrt{-b} + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    4. Applied fma-def9.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{\mathsf{fma}\left(\sqrt{-b}, \sqrt{-b}, \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\\ \end{array}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt9.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\sqrt{-b}, \sqrt{-b}, \sqrt{b \cdot b - \left(4 \cdot \left(\left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right) \cdot \sqrt[3]{a}\right)\right) \cdot c}\right)}\\ \end{array}\]
    7. Applied associate-*r*9.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\sqrt{-b}, \sqrt{-b}, \sqrt{b \cdot b - \left(\left(4 \cdot \left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right)\right) \cdot \sqrt[3]{a}\right) \cdot c}\right)}\\ \end{array}\]
    8. Applied associate-*l*9.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\sqrt{-b}, \sqrt{-b}, \sqrt{b \cdot b - \left(4 \cdot \left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right)\right) \cdot \left(\sqrt[3]{a} \cdot c\right)}\right)}\\ \end{array}\]
    9. Applied prod-diff9.4

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\sqrt{-b}, \sqrt{-b}, \sqrt{\mathsf{fma}\left(b, b, -\left(\sqrt[3]{a} \cdot c\right) \cdot \left(4 \cdot \left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right)\right)\right) + \mathsf{fma}\left(-\sqrt[3]{a} \cdot c, 4 \cdot \left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right), \left(\sqrt[3]{a} \cdot c\right) \cdot \left(4 \cdot \left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right)\right)\right)}\right)}\\ \end{array}\]
    10. Simplified9.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\sqrt{-b}, \sqrt{-b}, \sqrt{\mathsf{fma}\left(b, b, -\left(\sqrt[3]{a} \cdot c\right) \cdot \left(4 \cdot \left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right)\right)\right) + \left(4 \cdot \left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right)\right) \cdot \left(\left(-\sqrt[3]{a} \cdot c\right) + \sqrt[3]{a} \cdot c\right)}\right)}\\ \end{array}\]

    if 1.3873173872385558e+50 < b

    1. Initial program 37.3

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Taylor expanded around inf 9.8

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{\left(b - 2 \cdot \frac{a \cdot c}{b}\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification8.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -7.9501683196199669 \cdot 10^{81}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}\\ \end{array}\\ \mathbf{elif}\;b \le 1.38731738723855584 \cdot 10^{50}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\sqrt{-b}, \sqrt{-b}, \sqrt{\mathsf{fma}\left(b, b, -\left(\sqrt[3]{a} \cdot c\right) \cdot \left(4 \cdot \left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right)\right)\right) + \left(4 \cdot \left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right)\right) \cdot \left(\left(-\sqrt[3]{a} \cdot c\right) + \sqrt[3]{a} \cdot c\right)}\right)}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \left(b - 2 \cdot \frac{a \cdot c}{b}\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020114 +o rules:numerics
(FPCore (a b c)
  :name "jeff quadratic root 1"
  :precision binary64
  (if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ (* 2 c) (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))))))