Average Error: 19.5 → 6.9
Time: 4.9s
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.079179133751072 \cdot 10^{+38}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\frac{{b}^{4} - 4 \cdot \left(a \cdot \left(c \cdot \left(4 \cdot \left(a \cdot c\right)\right)\right)\right)}{4 \cdot \left(a \cdot c\right) + b \cdot b}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\ \end{array}\\ \mathbf{elif}\;b \leq 4.864845683402437 \cdot 10^{+77}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{2}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - 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.079179133751072 \cdot 10^{+38}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\frac{{b}^{4} - 4 \cdot \left(a \cdot \left(c \cdot \left(4 \cdot \left(a \cdot c\right)\right)\right)\right)}{4 \cdot \left(a \cdot c\right) + b \cdot b}}}{a \cdot 2}\\

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

\end{array}\\

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

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

\end{array}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - 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.079179133751072e+38)
   (if (>= b 0.0)
     (/
      (-
       (- b)
       (sqrt
        (/
         (- (pow b 4.0) (* 4.0 (* a (* c (* 4.0 (* a c))))))
         (+ (* 4.0 (* a c)) (* b b)))))
      (* a 2.0))
     (/ (* c 2.0) (- (- (* 2.0 (* c (/ a b))) b) b)))
   (if (<= b 4.864845683402437e+77)
     (if (>= b 0.0)
       (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* a 2.0))
       (* c (/ 2.0 (- (sqrt (- (* b b) (* 4.0 (* a c)))) b))))
     (if (>= b 0.0)
       (/ (- (- (* 2.0 (* c (/ a b))) b) b) (* a 2.0))
       (/ (* c 2.0) (- (sqrt (- (* b b) (* c (* 4.0 a)))) b))))))
double code(double a, double b, double c) {
	double tmp;
	if ((b >= 0.0)) {
		tmp = (((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))) / ((double) (2.0 * a)));
	} else {
		tmp = (((double) (2.0 * c)) / ((double) (((double) -(b)) + ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))));
	}
	return tmp;
}
double code(double a, double b, double c) {
	double tmp;
	if ((b <= -6.079179133751072e+38)) {
		double tmp_1;
		if ((b >= 0.0)) {
			tmp_1 = (((double) (((double) -(b)) - ((double) sqrt((((double) (((double) pow(b, 4.0)) - ((double) (4.0 * ((double) (a * ((double) (c * ((double) (4.0 * ((double) (a * c)))))))))))) / ((double) (((double) (4.0 * ((double) (a * c)))) + ((double) (b * b))))))))) / ((double) (a * 2.0)));
		} else {
			tmp_1 = (((double) (c * 2.0)) / ((double) (((double) (((double) (2.0 * ((double) (c * (a / b))))) - b)) - b)));
		}
		tmp = tmp_1;
	} else {
		double tmp_2;
		if ((b <= 4.864845683402437e+77)) {
			double tmp_3;
			if ((b >= 0.0)) {
				tmp_3 = (((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (a * c)))))))))) / ((double) (a * 2.0)));
			} else {
				tmp_3 = ((double) (c * (2.0 / ((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (a * c)))))))) - b)))));
			}
			tmp_2 = tmp_3;
		} else {
			double tmp_4;
			if ((b >= 0.0)) {
				tmp_4 = (((double) (((double) (((double) (2.0 * ((double) (c * (a / b))))) - b)) - b)) / ((double) (a * 2.0)));
			} else {
				tmp_4 = (((double) (c * 2.0)) / ((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))) - b)));
			}
			tmp_2 = tmp_4;
		}
		tmp = tmp_2;
	}
	return tmp;
}

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.07917913375107167e38

    1. Initial program Error: 24.6 bits

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

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

      \[\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}:\\ \;\;\;\;\frac{2 \cdot c}{\color{blue}{\left(-b\right) + \left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right)}}\\ \end{array}\]
    4. Using strategy rm
    5. Applied flip--Error: 4.1 bits

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

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

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

    if -6.07917913375107167e38 < b < 4.86484568340243746e77

    1. Initial program Error: 9.2 bits

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

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

    if 4.86484568340243746e77 < b

    1. Initial program Error: 41.3 bits

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -6.079179133751072 \cdot 10^{+38}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\frac{{b}^{4} - 4 \cdot \left(a \cdot \left(c \cdot \left(4 \cdot \left(a \cdot c\right)\right)\right)\right)}{4 \cdot \left(a \cdot c\right) + b \cdot b}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\ \end{array}\\ \mathbf{elif}\;b \leq 4.864845683402437 \cdot 10^{+77}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{2}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}\\ \end{array}\]

Reproduce

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