Average Error: 19.7 → 6.6
Time: 5.0s
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 -6.999030654439093 \cdot 10^{+112}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{2 \cdot \left(c \cdot \frac{a}{b}\right) + b \cdot -2}\\ \end{array}\\ \mathbf{elif}\;b \leq 4.6451347271489274 \cdot 10^{-303}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\frac{4 \cdot \left(a \cdot c\right)}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}\\ \mathbf{elif}\;b \leq 2.745617712906307 \cdot 10^{+146}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{2 \cdot \left(c \cdot \frac{a}{b}\right) + b \cdot -2}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{b \cdot -2 + 2 \cdot \left(\sqrt[3]{\frac{a}{b}} \cdot \left(c \cdot \left(\sqrt[3]{\frac{a}{b}} \cdot \sqrt[3]{\frac{a}{b}}\right)\right)\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \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 -6.999030654439093 \cdot 10^{+112}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}\\

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

\end{array}\\

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

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

\end{array}\\

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

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

\end{array}\\

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

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

\end{array}
(FPCore (a b c)
 :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)))))))
(FPCore (a b c)
 :precision binary64
 (if (<= b -6.999030654439093e+112)
   (if (>= b 0.0)
     (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* a 2.0))
     (/ (* c 2.0) (+ (* 2.0 (* c (/ a b))) (* b -2.0))))
   (if (<= b 4.6451347271489274e-303)
     (if (>= b 0.0)
       (/
        (/ (* 4.0 (* a c)) (- (sqrt (- (* b b) (* 4.0 (* a c)))) b))
        (* a 2.0))
       (/ (* c 2.0) (- (sqrt (- (* b b) (* (* 4.0 a) c))) b)))
     (if (<= b 2.745617712906307e+146)
       (if (>= b 0.0)
         (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* a 2.0))
         (/ (* c 2.0) (+ (* 2.0 (* c (/ a b))) (* b -2.0))))
       (if (>= b 0.0)
         (/
          (+
           (* b -2.0)
           (* 2.0 (* (cbrt (/ a b)) (* c (* (cbrt (/ a b)) (cbrt (/ a b)))))))
          (* a 2.0))
         (/ (* c 2.0) (- (sqrt (- (* b b) (* (* 4.0 a) c))) b)))))))
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 <= -6.999030654439093e+112)) {
		double VAR_1;
		if ((b >= 0.0)) {
			VAR_1 = (((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))) / ((double) (a * 2.0)));
		} 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 <= 4.6451347271489274e-303)) {
			double VAR_3;
			if ((b >= 0.0)) {
				VAR_3 = ((((double) (4.0 * ((double) (a * c)))) / ((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (a * c)))))))) - b))) / ((double) (a * 2.0)));
			} else {
				VAR_3 = (((double) (c * 2.0)) / ((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))) - b)));
			}
			VAR_2 = VAR_3;
		} else {
			double VAR_4;
			if ((b <= 2.745617712906307e+146)) {
				double VAR_5;
				if ((b >= 0.0)) {
					VAR_5 = (((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))) / ((double) (a * 2.0)));
				} else {
					VAR_5 = (((double) (c * 2.0)) / ((double) (((double) (2.0 * ((double) (c * (a / b))))) + ((double) (b * -2.0)))));
				}
				VAR_4 = VAR_5;
			} else {
				double VAR_6;
				if ((b >= 0.0)) {
					VAR_6 = (((double) (((double) (b * -2.0)) + ((double) (2.0 * ((double) (((double) cbrt((a / b))) * ((double) (c * ((double) (((double) cbrt((a / b))) * ((double) cbrt((a / b))))))))))))) / ((double) (a * 2.0)));
				} else {
					VAR_6 = (((double) (c * 2.0)) / ((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))) - b)));
				}
				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 < -6.99903065443909297e112 or 4.64513472714892737e-303 < b < 2.745617712906307e146

    1. Initial program 17.6

      \[\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 8.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}:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}\\ \end{array}\]
    3. Simplified6.4

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

    if -6.99903065443909297e112 < b < 4.64513472714892737e-303

    1. Initial program 8.5

      \[\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 flip--8.5

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

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

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

    if 2.745617712906307e146 < b

    1. Initial program 61.0

      \[\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 9.7

      \[\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. Simplified2.2

      \[\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. Using strategy rm
    5. Applied add-cube-cbrt2.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot \left(c \cdot \color{blue}{\left(\left(\sqrt[3]{\frac{a}{b}} \cdot \sqrt[3]{\frac{a}{b}}\right) \cdot \sqrt[3]{\frac{a}{b}}\right)}\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}\]
    6. Applied associate-*r*2.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot \color{blue}{\left(\left(c \cdot \left(\sqrt[3]{\frac{a}{b}} \cdot \sqrt[3]{\frac{a}{b}}\right)\right) \cdot \sqrt[3]{\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}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification6.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -6.999030654439093 \cdot 10^{+112}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{2 \cdot \left(c \cdot \frac{a}{b}\right) + b \cdot -2}\\ \end{array}\\ \mathbf{elif}\;b \leq 4.6451347271489274 \cdot 10^{-303}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\frac{4 \cdot \left(a \cdot c\right)}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}\\ \mathbf{elif}\;b \leq 2.745617712906307 \cdot 10^{+146}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{2 \cdot \left(c \cdot \frac{a}{b}\right) + b \cdot -2}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{b \cdot -2 + 2 \cdot \left(\sqrt[3]{\frac{a}{b}} \cdot \left(c \cdot \left(\sqrt[3]{\frac{a}{b}} \cdot \sqrt[3]{\frac{a}{b}}\right)\right)\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}\]

Reproduce

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