Average Error: 20.2 → 6.6
Time: 16.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} t_0 := \frac{b \cdot -2}{2 \cdot a}\\ t_1 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\ t_2 := \frac{t_1 - b}{2 \cdot a}\\ t_3 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t_1}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ \mathbf{if}\;t_3 \leq -\infty:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2}{\frac{\left(-b\right) - \mathsf{hypot}\left(b, \sqrt{-4 \cdot \left(c \cdot a\right)}\right)}{c}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array}\\ \mathbf{elif}\;t_3 \leq -5.712850829085573 \cdot 10^{-247}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_3 \leq 0:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ \mathbf{elif}\;t_3 \leq 2.4004568677540924 \cdot 10^{+233}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(-\sqrt{b}, \sqrt{b}, -t_1\right)}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \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}
t_0 := \frac{b \cdot -2}{2 \cdot a}\\
t_1 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\
t_2 := \frac{t_1 - b}{2 \cdot a}\\
t_3 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t_1}\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2}{\frac{\left(-b\right) - \mathsf{hypot}\left(b, \sqrt{-4 \cdot \left(c \cdot a\right)}\right)}{c}}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}\\

\mathbf{elif}\;t_3 \leq -5.712850829085573 \cdot 10^{-247}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_3 \leq 0:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}\\

\mathbf{elif}\;t_3 \leq 2.4004568677540924 \cdot 10^{+233}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(-\sqrt{b}, \sqrt{b}, -t_1\right)}\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-\frac{c}{b}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\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
 (let* ((t_0 (/ (* b -2.0) (* 2.0 a)))
        (t_1 (sqrt (- (* b b) (* c (* 4.0 a)))))
        (t_2 (/ (- t_1 b) (* 2.0 a)))
        (t_3 (if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_1)) t_2)))
   (if (<= t_3 (- INFINITY))
     (if (>= b 0.0)
       (/ 2.0 (/ (- (- b) (hypot b (sqrt (* -4.0 (* c a))))) c))
       t_0)
     (if (<= t_3 -5.712850829085573e-247)
       t_3
       (if (<= t_3 0.0)
         (if (>= b 0.0) (/ (* 2.0 c) (- (- b) b)) t_2)
         (if (<= t_3 2.4004568677540924e+233)
           (if (>= b 0.0)
             (/ (* 2.0 c) (fma (- (sqrt b)) (sqrt b) (- t_1)))
             t_2)
           (if (>= b 0.0) (- (/ c b)) t_0)))))))
double code(double a, double b, double c) {
	double tmp;
	if (b >= 0.0) {
		tmp = (2.0 * c) / (-b - sqrt((b * b) - ((4.0 * a) * c)));
	} else {
		tmp = (-b + sqrt((b * b) - ((4.0 * a) * c))) / (2.0 * a);
	}
	return tmp;
}
double code(double a, double b, double c) {
	double t_0 = (b * -2.0) / (2.0 * a);
	double t_1 = sqrt((b * b) - (c * (4.0 * a)));
	double t_2 = (t_1 - b) / (2.0 * a);
	double tmp;
	if (b >= 0.0) {
		tmp = (2.0 * c) / (-b - t_1);
	} else {
		tmp = t_2;
	}
	double t_3 = tmp;
	double tmp_2;
	if (t_3 <= -((double) INFINITY)) {
		double tmp_3;
		if (b >= 0.0) {
			tmp_3 = 2.0 / ((-b - hypot(b, sqrt(-4.0 * (c * a)))) / c);
		} else {
			tmp_3 = t_0;
		}
		tmp_2 = tmp_3;
	} else if (t_3 <= -5.712850829085573e-247) {
		tmp_2 = t_3;
	} else if (t_3 <= 0.0) {
		double tmp_4;
		if (b >= 0.0) {
			tmp_4 = (2.0 * c) / (-b - b);
		} else {
			tmp_4 = t_2;
		}
		tmp_2 = tmp_4;
	} else if (t_3 <= 2.4004568677540924e+233) {
		double tmp_5;
		if (b >= 0.0) {
			tmp_5 = (2.0 * c) / fma(-sqrt(b), sqrt(b), -t_1);
		} else {
			tmp_5 = t_2;
		}
		tmp_2 = tmp_5;
	} else if (b >= 0.0) {
		tmp_2 = -(c / b);
	} else {
		tmp_2 = t_0;
	}
	return tmp_2;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 5 regimes
  2. if (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < -inf.0

    1. Initial program 64.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. Taylor expanded in b around -inf 16.7

      \[\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 b}{2 \cdot a}\\ \end{array} \]
    3. Applied associate-/l*_binary6416.7

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

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

    if -inf.0 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < -5.71285082908557312e-247

    1. Initial program 2.6

      \[\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} \]

    if -5.71285082908557312e-247 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < 0.0

    1. Initial program 35.1

      \[\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 in b around inf 9.7

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

    if 0.0 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < 2.40045686775409245e233

    1. Initial program 2.9

      \[\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. Applied add-sqr-sqrt_binary642.9

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-\color{blue}{\sqrt{b} \cdot \sqrt{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} \]
    3. Applied distribute-lft-neg-in_binary642.9

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

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

    if 2.40045686775409245e233 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)))

    1. Initial program 53.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. Taylor expanded in b around -inf 17.9

      \[\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 b}{2 \cdot a}\\ \end{array} \]
    3. Taylor expanded in c around 0 13.7

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\color{blue}{-1 \cdot \frac{c}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot b}{2 \cdot a}\\ \end{array} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification6.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\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{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array} \leq -\infty:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2}{\frac{\left(-b\right) - \mathsf{hypot}\left(b, \sqrt{-4 \cdot \left(c \cdot a\right)}\right)}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;\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{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array} \leq -5.712850829085573 \cdot 10^{-247}:\\ \;\;\;\;\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{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;\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{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array} \leq 0:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;\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{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array} \leq 2.4004568677540924 \cdot 10^{+233}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(-\sqrt{b}, \sqrt{b}, -\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\ \end{array} \]

Reproduce

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