Average Error: 19.8 → 7.0
Time: 5.9s
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 -4.993472345130425 \cdot 10^{+132}:\\ \;\;\;\;\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 5.5357752852941396 \cdot 10^{+53}:\\ \;\;\;\;\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{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt{\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]{\left|\sqrt[3]{b \cdot b - c \cdot \left(4 \cdot a\right)}\right| \cdot \sqrt{\sqrt[3]{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}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\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 -4.993472345130425 \cdot 10^{+132}:\\
\;\;\;\;\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 5.5357752852941396 \cdot 10^{+53}:\\
\;\;\;\;\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{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt{\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]{\left|\sqrt[3]{b \cdot b - c \cdot \left(4 \cdot a\right)}\right| \cdot \sqrt{\sqrt[3]{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}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\

\mathbf{else}:\\
\;\;\;\;\frac{\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 <= -4.993472345130425e+132)) {
		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 <= 5.5357752852941396e+53)) {
			double VAR_3;
			if ((b >= 0.0)) {
				VAR_3 = ((double) (2.0 * (c / ((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))))))));
			} else {
				VAR_3 = (((double) (((double) (((double) sqrt(((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))))) * ((double) sqrt(((double) (((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)))))))))))) * ((double) cbrt(((double) (((double) fabs(((double) cbrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))))) * ((double) sqrt(((double) cbrt(((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) (((double) (2.0 * ((double) (c * (a / b))))) - b)) - b)))));
			} else {
				VAR_4 = (((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 < -4.99347234513042528e132

    1. Initial program Error: 56.9 bits

      \[\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. SimplifiedError: 56.9 bits

      \[\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 Error: 10.9 bits

      \[\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. SimplifiedError: 2.7 bits

      \[\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 -4.99347234513042528e132 < b < 5.5357752852941396e53

    1. Initial program Error: 9.1 bits

      \[\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. SimplifiedError: 9.1 bits

      \[\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-sqr-sqrtError: 9.1 bits

      \[\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{\sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} \cdot \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} - b}{2 \cdot a}\\ \end{array}\]
    5. Applied sqrt-prodError: 9.3 bits

      \[\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{\sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} - b}{2 \cdot a}\\ \end{array}\]
    6. Using strategy rm
    7. Applied add-cube-cbrtError: 9.4 bits

      \[\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{\sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt{\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)}}} - b}{2 \cdot a}\\ \end{array}\]
    8. Using strategy rm
    9. Applied add-cube-cbrtError: 9.4 bits

      \[\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{\sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt{\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{\left(\sqrt[3]{b \cdot b - c \cdot \left(4 \cdot a\right)} \cdot \sqrt[3]{b \cdot b - c \cdot \left(4 \cdot a\right)}\right) \cdot \sqrt[3]{b \cdot b - c \cdot \left(4 \cdot a\right)}}}} - b}{2 \cdot a}\\ \end{array}\]
    10. Applied sqrt-prodError: 9.4 bits

      \[\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{\sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt{\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{\sqrt[3]{b \cdot b - c \cdot \left(4 \cdot a\right)} \cdot \sqrt[3]{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt{\sqrt[3]{b \cdot b - c \cdot \left(4 \cdot a\right)}}}} - b}{2 \cdot a}\\ \end{array}\]
    11. SimplifiedError: 9.4 bits

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

    if 5.5357752852941396e53 < b

    1. Initial program Error: 25.8 bits

      \[\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. SimplifiedError: 25.8 bits

      \[\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 Error: 8.2 bits

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{c}{\left(-b\right) - \color{blue}{\left(b - 2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\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 simplificationError: 7.0 bits

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.993472345130425 \cdot 10^{+132}:\\ \;\;\;\;\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 5.5357752852941396 \cdot 10^{+53}:\\ \;\;\;\;\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{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt{\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]{\left|\sqrt[3]{b \cdot b - c \cdot \left(4 \cdot a\right)}\right| \cdot \sqrt{\sqrt[3]{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}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array}\]

Reproduce

herbie shell --seed 2020200 
(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))))