Average Error: 20.3 → 6.9
Time: 10.2s
Precision: binary64
\[\begin{array}{l} \mathbf{if}\;b \geq 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 \leq -1.281214642187557 \cdot 10^{+111}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{2 \cdot \left(c \cdot \frac{a}{b}\right) + b \cdot -2}\\ \end{array}\\ \mathbf{elif}\;b \leq 2.517726559601462 \cdot 10^{+59}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\left|\sqrt[3]{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - 4 \cdot \left(c \cdot a\right)}} - b}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{c \cdot \frac{2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}} \cdot \left(\sqrt[3]{c \cdot \frac{2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}} \cdot \sqrt[3]{c \cdot \frac{2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}\right)\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \geq 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 \leq -1.281214642187557 \cdot 10^{+111}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\end{array}\\

\mathbf{elif}\;b \leq 2.517726559601462 \cdot 10^{+59}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2}\\

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

\end{array}\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\end{array}
double code(double a, double b, double c) {
	double VAR;
	if ((b >= 0.0)) {
		VAR = (((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))) / ((double) (2.0 * a)));
	} else {
		VAR = (((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 <= -1.281214642187557e+111)) {
		double VAR_1;
		if ((b >= 0.0)) {
			VAR_1 = ((double) (1.0 * ((double) ((c / b) - (b / a)))));
		} else {
			VAR_1 = (((double) (c * 2.0)) / ((double) (((double) (2.0 * ((double) (c * (a / b))))) + ((double) (b * -2.0)))));
		}
		VAR = VAR_1;
	} else {
		double VAR_2;
		if ((b <= 2.517726559601462e+59)) {
			double VAR_3;
			if ((b >= 0.0)) {
				VAR_3 = (((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (a * 4.0)))))))))) / ((double) (a * 2.0)));
			} else {
				VAR_3 = (((double) (c * 2.0)) / ((double) (((double) (((double) fabs(((double) cbrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (c * a)))))))))) * ((double) sqrt(((double) cbrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (c * a)))))))))))) - b)));
			}
			VAR_2 = VAR_3;
		} else {
			double VAR_4;
			if ((b >= 0.0)) {
				VAR_4 = ((double) (1.0 * ((double) ((c / b) - (b / a)))));
			} else {
				VAR_4 = ((double) (((double) cbrt(((double) (c * (2.0 / ((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (c * a)))))))) - b))))))) * ((double) (((double) cbrt(((double) (c * (2.0 / ((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (c * a)))))))) - b))))))) * ((double) cbrt(((double) (c * (2.0 / ((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (c * a)))))))) - b)))))))))));
			}
			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.28121464218755704e111

    1. Initial program 32.3

      \[\begin{array}{l} \mathbf{if}\;b \geq 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 32.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 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. Simplified32.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\color{blue}{2 \cdot \left(c \cdot \frac{a}{b}\right) + b \cdot -2}}{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}\]
    4. Taylor expanded around 0 32.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    5. Simplified32.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\color{blue}{1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    6. Taylor expanded around -inf 6.8

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}\\ \end{array}\]
    7. Simplified2.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{2 \cdot \left(c \cdot \frac{a}{b}\right) + b \cdot -2}}\\ \end{array}\]

    if -1.28121464218755704e111 < b < 2.517726559601462e59

    1. Initial program 8.9

      \[\begin{array}{l} \mathbf{if}\;b \geq 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-cube-cbrt9.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 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{\left(\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \end{array}\]
    4. Applied sqrt-prod9.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 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[3]{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\\ \end{array}\]
    5. Simplified9.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 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|\sqrt[3]{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \end{array}\]
    6. Simplified9.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 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) + \color{blue}{\left|\sqrt[3]{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\\ \end{array}\]

    if 2.517726559601462e59 < b

    1. Initial program 40.3

      \[\begin{array}{l} \mathbf{if}\;b \geq 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.8

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 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. Simplified5.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\color{blue}{2 \cdot \left(c \cdot \frac{a}{b}\right) + b \cdot -2}}{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}\]
    4. Taylor expanded around 0 5.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    5. Simplified5.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\color{blue}{1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt5.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt[3]{\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}} \cdot \sqrt[3]{\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\right) \cdot \sqrt[3]{\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \end{array}\]
    8. Simplified5.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt[3]{c \cdot \frac{2}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}} \cdot \sqrt[3]{c \cdot \frac{2}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}\right) \cdot \sqrt[3]{\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \end{array}\]
    9. Simplified5.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\color{blue}{\left(\sqrt[3]{c \cdot \frac{2}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}} \cdot \sqrt[3]{c \cdot \frac{2}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}\right) \cdot \sqrt[3]{c \cdot \frac{2}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}}\\ \end{array}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification6.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.281214642187557 \cdot 10^{+111}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{2 \cdot \left(c \cdot \frac{a}{b}\right) + b \cdot -2}\\ \end{array}\\ \mathbf{elif}\;b \leq 2.517726559601462 \cdot 10^{+59}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\left|\sqrt[3]{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - 4 \cdot \left(c \cdot a\right)}} - b}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{c \cdot \frac{2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}} \cdot \left(\sqrt[3]{c \cdot \frac{2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}} \cdot \sqrt[3]{c \cdot \frac{2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020196 
(FPCore (a b c)
  :name "jeff quadratic root 1"
  :precision binary64
  (if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))