Average Error: 19.3 → 7.9
Time: 6.8s
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 -1.4465906485348473 \cdot 10^{93}:\\ \;\;\;\;\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) + \left(2 \cdot \left(\left(\left(\sqrt[3]{\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}}}} \cdot \sqrt[3]{\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}}}}\right) \cdot \sqrt[3]{\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}}}}\right) \cdot \frac{\sqrt[3]{a}}{\frac{\sqrt[3]{b}}{\sqrt[3]{c}}}\right) - b\right)}\\ \end{array}\\ \mathbf{elif}\;b \le 1.7007433694472029 \cdot 10^{75}:\\ \;\;\;\;\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{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}{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 -1.4465906485348473 \cdot 10^{93}:\\
\;\;\;\;\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) + \left(2 \cdot \left(\left(\left(\sqrt[3]{\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}}}} \cdot \sqrt[3]{\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}}}}\right) \cdot \sqrt[3]{\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}}}}\right) \cdot \frac{\sqrt[3]{a}}{\frac{\sqrt[3]{b}}{\sqrt[3]{c}}}\right) - b\right)}\\

\end{array}\\

\mathbf{elif}\;b \le 1.7007433694472029 \cdot 10^{75}:\\
\;\;\;\;\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{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\

\end{array}\\

\mathbf{elif}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}{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 = ((-b - sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a));
	} else {
		VAR = ((2.0 * c) / (-b + sqrt(((b * b) - ((4.0 * a) * c)))));
	}
	return VAR;
}
double code(double a, double b, double c) {
	double VAR;
	if ((b <= -1.4465906485348473e+93)) {
		double VAR_1;
		if ((b >= 0.0)) {
			VAR_1 = ((-b - sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a));
		} else {
			VAR_1 = ((2.0 * c) / (-b + ((2.0 * (((cbrt(((cbrt(a) * cbrt(a)) / ((cbrt(b) * cbrt(b)) / (cbrt(c) * cbrt(c))))) * cbrt(((cbrt(a) * cbrt(a)) / ((cbrt(b) * cbrt(b)) / (cbrt(c) * cbrt(c)))))) * cbrt(((cbrt(a) * cbrt(a)) / ((cbrt(b) * cbrt(b)) / (cbrt(c) * cbrt(c)))))) * (cbrt(a) / (cbrt(b) / cbrt(c))))) - b)));
		}
		VAR = VAR_1;
	} else {
		double VAR_2;
		if ((b <= 1.700743369447203e+75)) {
			double VAR_3;
			if ((b >= 0.0)) {
				VAR_3 = ((-b - sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a));
			} else {
				VAR_3 = ((2.0 * c) / (-b + (sqrt(sqrt(((b * b) - ((4.0 * a) * c)))) * sqrt(sqrt(((b * b) - ((4.0 * a) * c)))))));
			}
			VAR_2 = VAR_3;
		} else {
			double VAR_4;
			if ((b >= 0.0)) {
				VAR_4 = (((2.0 * ((a * c) / b)) - (2.0 * b)) / (2.0 * a));
			} else {
				VAR_4 = ((2.0 * c) / (-b + sqrt(((b * b) - ((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 < -1.4465906485348473e+93

    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 6.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}{\color{blue}{\left(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}}\\ \end{array}\]
    3. Using strategy rm
    4. Applied associate-/l*2.6

      \[\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}{\left(-b\right) + \left(2 \cdot \frac{a}{\frac{b}{c}} - b\right)}\\ \end{array}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt2.6

      \[\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}{\left(-b\right) + \left(2 \cdot \frac{a}{\frac{b}{\left(\sqrt[3]{c} \cdot \sqrt[3]{c}\right) \cdot \sqrt[3]{c}}} - b\right)}\\ \end{array}\]
    7. Applied add-cube-cbrt2.6

      \[\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}{\left(-b\right) + \left(2 \cdot \frac{a}{\frac{\left(\sqrt[3]{b} \cdot \sqrt[3]{b}\right) \cdot \sqrt[3]{b}}{\left(\sqrt[3]{c} \cdot \sqrt[3]{c}\right) \cdot \sqrt[3]{c}}} - b\right)}\\ \end{array}\]
    8. Applied times-frac2.6

      \[\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}{\left(-b\right) + \left(2 \cdot \frac{a}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}} \cdot \frac{\sqrt[3]{b}}{\sqrt[3]{c}}} - b\right)}\\ \end{array}\]
    9. Applied add-cube-cbrt2.6

      \[\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}{\left(-b\right) + \left(2 \cdot \frac{\left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right) \cdot \sqrt[3]{a}}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}} \cdot \frac{\sqrt[3]{b}}{\sqrt[3]{c}}} - b\right)}\\ \end{array}\]
    10. Applied times-frac2.6

      \[\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}{\left(-b\right) + \left(2 \cdot \left(\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}}} \cdot \frac{\sqrt[3]{a}}{\frac{\sqrt[3]{b}}{\sqrt[3]{c}}}\right) - b\right)}\\ \end{array}\]
    11. Using strategy rm
    12. Applied add-cube-cbrt2.6

      \[\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}{\left(-b\right) + \left(2 \cdot \left(\left(\left(\sqrt[3]{\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}}}} \cdot \sqrt[3]{\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}}}}\right) \cdot \sqrt[3]{\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}}}}\right) \cdot \frac{\sqrt[3]{a}}{\frac{\sqrt[3]{b}}{\sqrt[3]{c}}}\right) - b\right)}\\ \end{array}\]

    if -1.4465906485348473e+93 < b < 1.700743369447203e+75

    1. Initial program 9.0

      \[\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.0

      \[\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}{\color{blue}{\left(-b\right)} + \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \end{array}\]
    4. Applied sqrt-prod9.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}:\\ \;\;\;\;\frac{2 \cdot c}{\color{blue}{\left(-b\right) + \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\\ \end{array}\]

    if 1.700743369447203e+75 < b

    1. Initial program 41.1

      \[\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 11.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}{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 simplification7.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.4465906485348473 \cdot 10^{93}:\\ \;\;\;\;\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) + \left(2 \cdot \left(\left(\left(\sqrt[3]{\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}}}} \cdot \sqrt[3]{\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}}}}\right) \cdot \sqrt[3]{\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\frac{\sqrt[3]{b} \cdot \sqrt[3]{b}}{\sqrt[3]{c} \cdot \sqrt[3]{c}}}}\right) \cdot \frac{\sqrt[3]{a}}{\frac{\sqrt[3]{b}}{\sqrt[3]{c}}}\right) - b\right)}\\ \end{array}\\ \mathbf{elif}\;b \le 1.7007433694472029 \cdot 10^{75}:\\ \;\;\;\;\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{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}{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 2020091 +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)))))))