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

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

\end{array}\\

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

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

\end{array}\\

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

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

\end{array}
double code(double a, double b, double c) {
	double VAR;
	if ((b >= 0.0)) {
		VAR = (((double) (2.0 * c)) / ((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))));
	} else {
		VAR = (((double) (((double) -(b)) + ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))) / ((double) (2.0 * a)));
	}
	return VAR;
}
double code(double a, double b, double c) {
	double VAR;
	if ((b <= -1.928713223890362e+137)) {
		double VAR_1;
		if ((b >= 0.0)) {
			VAR_1 = ((double) (2.0 * (c / ((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))))))));
		} else {
			VAR_1 = (((double) (((double) (((double) (2.0 * ((double) (c * (a / b))))) - b)) - b)) / ((double) (2.0 * a)));
		}
		VAR = VAR_1;
	} else {
		double VAR_2;
		if ((b <= 2.517726559601462e+59)) {
			double VAR_3;
			if ((b >= 0.0)) {
				VAR_3 = ((double) (2.0 * (c / ((double) (((double) -(b)) - ((double) (((double) cbrt(((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))))) * ((double) (((double) cbrt(((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))))) * ((double) cbrt(((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))))))))))))));
			} else {
				VAR_3 = (((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))) - b)) / ((double) (2.0 * a)));
			}
			VAR_2 = VAR_3;
		} else {
			double VAR_4;
			if ((b >= 0.0)) {
				VAR_4 = ((double) (2.0 * (c / ((double) (((double) (2.0 * ((double) (c * (a / b))))) + ((double) (b * -2.0)))))));
			} else {
				VAR_4 = (((double) (((double) sqrt(((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))) - b)))) * ((double) sqrt(((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))) - b)))))) / ((double) (2.0 * a)));
			}
			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.92871322389036208e137

    1. Initial program 58.6

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

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

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

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

    if -1.92871322389036208e137 < b < 2.517726559601462e59

    1. Initial program 8.9

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

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

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

    if 2.517726559601462e59 < b

    1. Initial program 27.2

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

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

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

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

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

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

Reproduce

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