Average Error: 19.5 → 6.9
Time: 5.2s
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{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\left(2 \cdot \left(\left(c \cdot \left(\sqrt[3]{\frac{a}{b}} \cdot \sqrt[3]{\frac{a}{b}}\right)\right) \cdot \left(\sqrt[3]{\frac{1}{\sqrt[3]{b} \cdot \sqrt[3]{b}}} \cdot \sqrt[3]{\frac{a}{\sqrt[3]{b}}}\right)\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 - \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.079179133751072 \cdot 10^{+38}:\\
\;\;\;\;\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}{\left(2 \cdot \left(\left(c \cdot \left(\sqrt[3]{\frac{a}{b}} \cdot \sqrt[3]{\frac{a}{b}}\right)\right) \cdot \left(\sqrt[3]{\frac{1}{\sqrt[3]{b} \cdot \sqrt[3]{b}}} \cdot \sqrt[3]{\frac{a}{\sqrt[3]{b}}}\right)\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 - \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.079179133751072e+38)
   (if (>= b 0.0)
     (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* a 2.0))
     (/
      (* c 2.0)
      (-
       (-
        (*
         2.0
         (*
          (* c (* (cbrt (/ a b)) (cbrt (/ a b))))
          (* (cbrt (/ 1.0 (* (cbrt b) (cbrt b)))) (cbrt (/ a (cbrt 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) (* (* 4.0 a) c))) 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) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))) / ((double) (a * 2.0)));
		} else {
			tmp_1 = (((double) (c * 2.0)) / ((double) (((double) (((double) (2.0 * ((double) (((double) (c * ((double) (((double) cbrt((a / b))) * ((double) cbrt((a / b))))))) * ((double) (((double) cbrt((1.0 / ((double) (((double) cbrt(b)) * ((double) cbrt(b))))))) * ((double) cbrt((a / ((double) cbrt(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) (((double) (4.0 * a)) * c)))))) - 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 add-cube-cbrtError: 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}{\left(-b\right) + \left(2 \cdot \left(c \cdot \left(\left(\sqrt[3]{\frac{a}{b}} \cdot \sqrt[3]{\frac{a}{b}}\right) \cdot \sqrt[3]{\frac{a}{b}}\right)\right) - b\right)}\\ \end{array}\]
    6. Applied associate-*r*Error: 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}{\left(-b\right) + \left(2 \cdot \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\right)}\\ \end{array}\]
    7. Using strategy rm
    8. Applied add-cube-cbrtError: 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}{\left(-b\right) + \left(2 \cdot \left(\left(c \cdot \left(\sqrt[3]{\frac{a}{b}} \cdot \sqrt[3]{\frac{a}{b}}\right)\right) \cdot \sqrt[3]{\frac{a}{\left(\sqrt[3]{b} \cdot \sqrt[3]{b}\right) \cdot \sqrt[3]{b}}}\right) - b\right)}\\ \end{array}\]
    9. Applied *-un-lft-identityError: 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}{\left(-b\right) + \left(2 \cdot \left(\left(c \cdot \left(\sqrt[3]{\frac{a}{b}} \cdot \sqrt[3]{\frac{a}{b}}\right)\right) \cdot \sqrt[3]{\frac{1 \cdot a}{\left(\sqrt[3]{b} \cdot \sqrt[3]{b}\right) \cdot \sqrt[3]{b}}}\right) - b\right)}\\ \end{array}\]
    10. Applied times-fracError: 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}{\left(-b\right) + \left(2 \cdot \left(\left(c \cdot \left(\sqrt[3]{\frac{a}{b}} \cdot \sqrt[3]{\frac{a}{b}}\right)\right) \cdot \sqrt[3]{\frac{1}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{a}{\sqrt[3]{b}}}\right) - b\right)}\\ \end{array}\]
    11. Applied cbrt-prodError: 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}{\left(-b\right) + \left(2 \cdot \left(\left(c \cdot \left(\sqrt[3]{\frac{a}{b}} \cdot \sqrt[3]{\frac{a}{b}}\right)\right) \cdot \left(\sqrt[3]{\frac{1}{\sqrt[3]{b} \cdot \sqrt[3]{b}}} \cdot \sqrt[3]{\frac{a}{\sqrt[3]{b}}}\right)\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{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\left(2 \cdot \left(\left(c \cdot \left(\sqrt[3]{\frac{a}{b}} \cdot \sqrt[3]{\frac{a}{b}}\right)\right) \cdot \left(\sqrt[3]{\frac{1}{\sqrt[3]{b} \cdot \sqrt[3]{b}}} \cdot \sqrt[3]{\frac{a}{\sqrt[3]{b}}}\right)\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 - \left(4 \cdot a\right) \cdot c} - 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)))))))