Average Error: 19.8 → 6.8
Time: 6.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 -4.118384396451869 \cdot 10^{+91}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot \left(c \cdot \frac{a}{b}\right) + b \cdot -2}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \leq 7.827501062721053 \cdot 10^{+101}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b} \cdot \sqrt{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{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}\]
\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.118384396451869 \cdot 10^{+91}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\

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

\end{array}\\

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

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

\end{array}\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{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}
(FPCore (a b c)
 :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))))
(FPCore (a b c)
 :precision binary64
 (if (<= b -4.118384396451869e+91)
   (if (>= b 0.0)
     (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* c (* 4.0 a))))))
     (/ (+ (* 2.0 (* c (/ a b))) (* b -2.0)) (* 2.0 a)))
   (if (<= b 7.827501062721053e+101)
     (if (>= b 0.0)
       (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* c (* 4.0 a))))))
       (/
        (*
         (sqrt (- (sqrt (- (* b b) (* 4.0 (* c a)))) b))
         (sqrt (- (sqrt (- (* b b) (* 4.0 (* c a)))) b)))
        (* 2.0 a)))
     (if (>= b 0.0)
       (/ (* 2.0 c) (+ (* 2.0 (* c (/ a b))) (* b -2.0)))
       (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* 2.0 a))))))
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.118384396451869e+91)) {
		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) (2.0 * ((double) (c * (a / b))))) + ((double) (b * -2.0)))) / ((double) (2.0 * a)));
		}
		VAR = VAR_1;
	} else {
		double VAR_2;
		if ((b <= 7.827501062721053e+101)) {
			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) sqrt(((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (c * a)))))))) - b)))) * ((double) sqrt(((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (c * 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) (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.11838439645186898e91

    1. Initial program 44.3

      \[\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. Taylor expanded around -inf 10.4

      \[\leadsto \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{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}{2 \cdot a}\\ \end{array}\]
    3. Simplified4.3

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

    if -4.11838439645186898e91 < b < 7.8275010627210526e101

    1. Initial program 9.0

      \[\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. Using strategy rm
    3. Applied add-sqr-sqrt9.2

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

      \[\leadsto \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{\sqrt{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b} \cdot \sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \end{array}\]
    5. Simplified9.1

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

    if 7.8275010627210526e101 < b

    1. Initial program 30.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. Taylor expanded around inf 6.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.118384396451869 \cdot 10^{+91}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot \left(c \cdot \frac{a}{b}\right) + b \cdot -2}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \leq 7.827501062721053 \cdot 10^{+101}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b} \cdot \sqrt{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{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}\]

Reproduce

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