Average Error: 19.8 → 7.3
Time: 4.4s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le -5.7956926409099789 \cdot 10^{153}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 4.591188790043355 \cdot 10^{-310}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;c \cdot \frac{2}{\left(-b\right) - \left(b - 2 \cdot \frac{c}{\frac{b}{a}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 6.78594296272638531 \cdot 10^{101}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{c}{\frac{\left(-b\right) - \left(b - 2 \cdot \frac{c}{\frac{b}{a}}\right)}{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \frac{\sqrt{{\left(b \cdot b\right)}^{3} - {\left(\left(4 \cdot a\right) \cdot c\right)}^{3}}}{\sqrt{\left(b \cdot b\right) \cdot \left(b \cdot b\right) + \left(\left(\left(4 \cdot a\right) \cdot c\right) \cdot \left(\left(4 \cdot a\right) \cdot c\right) + \left(b \cdot b\right) \cdot \left(\left(4 \cdot a\right) \cdot c\right)\right)}}}{2 \cdot a}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

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

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

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

\end{array}\\

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

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

\end{array}\\

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

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

\end{array}\\

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

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

\end{array}
double code(double a, double b, double c) {
	double VAR;
	if ((b >= 0.0)) {
		VAR = ((2.0 * c) / (-b - sqrt(((b * b) - ((4.0 * a) * c)))));
	} else {
		VAR = ((-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a));
	}
	return VAR;
}
double code(double a, double b, double c) {
	double VAR;
	if ((b <= -5.795692640909979e+153)) {
		double VAR_1;
		if ((b >= 0.0)) {
			VAR_1 = ((2.0 * c) / (-b - sqrt(((b * b) - ((4.0 * a) * c)))));
		} else {
			VAR_1 = ((-b + ((2.0 * ((a * c) / b)) - b)) / (2.0 * a));
		}
		VAR = VAR_1;
	} else {
		double VAR_2;
		if ((b <= 4.59118879004335e-310)) {
			double VAR_3;
			if ((b >= 0.0)) {
				VAR_3 = (c * (2.0 / (-b - (b - (2.0 * (c / (b / a)))))));
			} else {
				VAR_3 = ((-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a));
			}
			VAR_2 = VAR_3;
		} else {
			double VAR_4;
			if ((b <= 6.785942962726385e+101)) {
				double VAR_5;
				if ((b >= 0.0)) {
					VAR_5 = ((2.0 * c) / (-b - sqrt(((b * b) - ((4.0 * a) * c)))));
				} else {
					VAR_5 = ((-b + ((2.0 * ((a * c) / b)) - b)) / (2.0 * a));
				}
				VAR_4 = VAR_5;
			} else {
				double VAR_6;
				if ((b >= 0.0)) {
					VAR_6 = (c / ((-b - (b - (2.0 * (c / (b / a))))) / 2.0));
				} else {
					VAR_6 = ((-b + (sqrt((pow((b * b), 3.0) - pow(((4.0 * a) * c), 3.0))) / sqrt((((b * b) * (b * b)) + ((((4.0 * a) * c) * ((4.0 * a) * c)) + ((b * b) * ((4.0 * a) * c))))))) / (2.0 * a));
				}
				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 < -5.795692640909979e+153 or 4.59118879004335e-310 < b < 6.785942962726385e+101

    1. Initial program 23.2

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

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

    if -5.795692640909979e+153 < b < 4.59118879004335e-310

    1. Initial program 8.0

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b - 2 \cdot \color{blue}{\frac{c}{\frac{b}{a}}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    6. Using strategy rm
    7. Applied *-commutative8.0

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\color{blue}{\frac{c}{\frac{\left(-b\right) - \left(b - 2 \cdot \frac{c}{\frac{b}{a}}\right)}{2}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    9. Using strategy rm
    10. Applied clear-num8.0

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

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

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

    if 6.785942962726385e+101 < b

    1. Initial program 30.5

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b - 2 \cdot \color{blue}{\frac{c}{\frac{b}{a}}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    6. Using strategy rm
    7. Applied *-commutative2.3

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\color{blue}{\frac{c}{\frac{\left(-b\right) - \left(b - 2 \cdot \frac{c}{\frac{b}{a}}\right)}{2}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    9. Using strategy rm
    10. Applied flip3--2.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.7956926409099789 \cdot 10^{153}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 4.591188790043355 \cdot 10^{-310}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;c \cdot \frac{2}{\left(-b\right) - \left(b - 2 \cdot \frac{c}{\frac{b}{a}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 6.78594296272638531 \cdot 10^{101}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{c}{\frac{\left(-b\right) - \left(b - 2 \cdot \frac{c}{\frac{b}{a}}\right)}{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \frac{\sqrt{{\left(b \cdot b\right)}^{3} - {\left(\left(4 \cdot a\right) \cdot c\right)}^{3}}}{\sqrt{\left(b \cdot b\right) \cdot \left(b \cdot b\right) + \left(\left(\left(4 \cdot a\right) \cdot c\right) \cdot \left(\left(4 \cdot a\right) \cdot c\right) + \left(b \cdot b\right) \cdot \left(\left(4 \cdot a\right) \cdot c\right)\right)}}}{2 \cdot a}\\ \end{array}\]

Reproduce

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