Average Error: 19.8 → 7.3
Time: 4.2s
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.3298367139250566 \cdot 10^{153}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \frac{1}{\frac{\frac{b}{a}}{c}} - 2 \cdot b}\\ \end{array}\\ \mathbf{elif}\;b \le -5.637140105170702 \cdot 10^{-310}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;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}\\ \mathbf{elif}\;b \le 4.43096079410457192 \cdot 10^{110}:\\ \;\;\;\;\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}{\frac{\mathsf{fma}\left(4, a \cdot c, 0\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \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 -1.3298367139250566 \cdot 10^{153}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{2 \cdot a}\\

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

\end{array}\\

\mathbf{elif}\;b \le -5.637140105170702 \cdot 10^{-310}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;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}\\

\mathbf{elif}\;b \le 4.43096079410457192 \cdot 10^{110}:\\
\;\;\;\;\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}{\frac{\mathsf{fma}\left(4, a \cdot c, 0\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\

\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 = ((-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.3298367139250566e+153)) {
		double VAR_1;
		if ((b >= 0.0)) {
			VAR_1 = ((fma(b, b, -((b * b) - ((4.0 * a) * c))) / (sqrt(((b * b) - ((4.0 * a) * c))) - b)) / (2.0 * a));
		} else {
			VAR_1 = ((2.0 * c) / ((2.0 * (1.0 / ((b / a) / c))) - (2.0 * b)));
		}
		VAR = VAR_1;
	} else {
		double VAR_2;
		if ((b <= -5.6371401051707e-310)) {
			double VAR_3;
			if ((b >= 0.0)) {
				VAR_3 = ((-b - (b - (2.0 * ((a * c) / b)))) / (2.0 * a));
			} else {
				VAR_3 = ((2.0 * c) / (-b + sqrt(((b * b) - ((4.0 * a) * c)))));
			}
			VAR_2 = VAR_3;
		} else {
			double VAR_4;
			if ((b <= 4.430960794104572e+110)) {
				double VAR_5;
				if ((b >= 0.0)) {
					VAR_5 = ((-b - sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a));
				} else {
					VAR_5 = ((2.0 * c) / (fma(4.0, (a * c), 0.0) / (-b - sqrt(((b * b) - ((4.0 * a) * c))))));
				}
				VAR_4 = VAR_5;
			} else {
				double VAR_6;
				if ((b >= 0.0)) {
					VAR_6 = ((-b - (b - (2.0 * ((a * c) / b)))) / (2.0 * a));
				} else {
					VAR_6 = ((2.0 * c) / (-b + sqrt(((b * b) - ((4.0 * a) * c)))));
				}
				VAR_4 = VAR_6;
			}
			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.3298367139250566e+153

    1. Initial program 38.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}:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}\\ \end{array}\]
    3. Using strategy rm
    4. Applied *-commutative6.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}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}\\ \end{array}\]
    5. Applied associate-/l*1.7

      \[\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 \color{blue}{c}}{2 \cdot \frac{c}{\frac{b}{a}} - 2 \cdot b}\\ \end{array}\]
    6. Using strategy rm
    7. Applied clear-num1.7

      \[\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 \color{blue}{c}}{2 \cdot \frac{1}{\frac{\frac{b}{a}}{c}} - 2 \cdot b}\\ \end{array}\]
    8. Using strategy rm
    9. Applied flip--1.7

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\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{1}{\frac{\frac{b}{a}}{c}} - 2 \cdot b}\\ \end{array}\]
    10. Simplified1.7

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\frac{\color{blue}{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}}{\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{1}{\frac{\frac{b}{a}}{c}} - 2 \cdot b}\\ \end{array}\]
    11. Simplified1.7

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

    if -1.3298367139250566e+153 < b < -5.6371401051707e-310 or 4.430960794104572e+110 < b

    1. Initial program 19.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 8.2

      \[\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}\]

    if -5.6371401051707e-310 < b < 4.430960794104572e+110

    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 flip-+9.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}:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\\ \end{array}\]
    4. Simplified9.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{\color{blue}{2 \cdot c}}{\frac{\mathsf{fma}\left(4, a \cdot c, 0\right)}{\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.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.3298367139250566 \cdot 10^{153}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \frac{1}{\frac{\frac{b}{a}}{c}} - 2 \cdot b}\\ \end{array}\\ \mathbf{elif}\;b \le -5.637140105170702 \cdot 10^{-310}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;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}\\ \mathbf{elif}\;b \le 4.43096079410457192 \cdot 10^{110}:\\ \;\;\;\;\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}{\frac{\mathsf{fma}\left(4, a \cdot c, 0\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \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 2020071 +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)))))))