Average Error: 20.1 → 7.8
Time: 9.6s
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} t_0 := -4 \cdot \left(a \cdot c\right)\\ t_1 := \frac{\left(-b\right) - b}{2 \cdot a}\\ t_2 := \left(4 \cdot a\right) \cdot c\\ t_3 := \sqrt{b \cdot b - t_2}\\ t_4 := \frac{\left(-b\right) - t_3}{2 \cdot a}\\ t_5 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + t_3}\\ \end{array}\\ t_6 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{\mathsf{fma}\left(b, b, -t_2\right)}}\\ \end{array}\\ \mathbf{if}\;t_5 \leq -2.0441723957830525 \cdot 10^{+163}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(b, \frac{c}{t_0}, \frac{c}{\sqrt{t_0}}\right)\\ \end{array}\\ \mathbf{elif}\;t_5 \leq -2.7283497524080452 \cdot 10^{-189}:\\ \;\;\;\;t_6\\ \mathbf{elif}\;t_5 \leq 0:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{-b \cdot 2}\\ \end{array}\\ \mathbf{elif}\;t_5 \leq 1.4800849406987464 \cdot 10^{+262}:\\ \;\;\;\;t_6\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{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}
t_0 := -4 \cdot \left(a \cdot c\right)\\
t_1 := \frac{\left(-b\right) - b}{2 \cdot a}\\
t_2 := \left(4 \cdot a\right) \cdot c\\
t_3 := \sqrt{b \cdot b - t_2}\\
t_4 := \frac{\left(-b\right) - t_3}{2 \cdot a}\\
t_5 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_4\\

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


\end{array}\\
t_6 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_4\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{\mathsf{fma}\left(b, b, -t_2\right)}}\\


\end{array}\\
\mathbf{if}\;t_5 \leq -2.0441723957830525 \cdot 10^{+163}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(b, \frac{c}{t_0}, \frac{c}{\sqrt{t_0}}\right)\\


\end{array}\\

\mathbf{elif}\;t_5 \leq -2.7283497524080452 \cdot 10^{-189}:\\
\;\;\;\;t_6\\

\mathbf{elif}\;t_5 \leq 0:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_4\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{-b \cdot 2}\\


\end{array}\\

\mathbf{elif}\;t_5 \leq 1.4800849406987464 \cdot 10^{+262}:\\
\;\;\;\;t_6\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{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
 (let* ((t_0 (- (* 4.0 (* a c))))
        (t_1 (/ (- (- b) b) (* 2.0 a)))
        (t_2 (* (* 4.0 a) c))
        (t_3 (sqrt (- (* b b) t_2)))
        (t_4 (/ (- (- b) t_3) (* 2.0 a)))
        (t_5 (if (>= b 0.0) t_4 (/ (* 2.0 c) (+ (- b) t_3))))
        (t_6
         (if (>= b 0.0) t_4 (/ (* 2.0 c) (+ (- b) (sqrt (fma b b (- t_2))))))))
   (if (<= t_5 -2.0441723957830525e+163)
     (if (>= b 0.0) t_1 (* 2.0 (fma b (/ c t_0) (/ c (sqrt t_0)))))
     (if (<= t_5 -2.7283497524080452e-189)
       t_6
       (if (<= t_5 0.0)
         (if (>= b 0.0) t_4 (/ (* 2.0 c) (- (* b 2.0))))
         (if (<= t_5 1.4800849406987464e+262)
           t_6
           (if (>= b 0.0) t_1 (* -1.0 (/ c b)))))))))
double code(double a, double b, double c) {
	double tmp;
	if (b >= 0.0) {
		tmp = (-b - sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
	} else {
		tmp = (2.0 * c) / (-b + sqrt(((b * b) - ((4.0 * a) * c))));
	}
	return tmp;
}
double code(double a, double b, double c) {
	double t_0 = -(4.0 * (a * c));
	double t_1 = (-b - b) / (2.0 * a);
	double t_2 = (4.0 * a) * c;
	double t_3 = sqrt(((b * b) - t_2));
	double t_4 = (-b - t_3) / (2.0 * a);
	double tmp;
	if (b >= 0.0) {
		tmp = t_4;
	} else {
		tmp = (2.0 * c) / (-b + t_3);
	}
	double t_5 = tmp;
	double tmp_1;
	if (b >= 0.0) {
		tmp_1 = t_4;
	} else {
		tmp_1 = (2.0 * c) / (-b + sqrt(fma(b, b, -t_2)));
	}
	double t_6 = tmp_1;
	double tmp_3;
	if (t_5 <= -2.0441723957830525e+163) {
		double tmp_4;
		if (b >= 0.0) {
			tmp_4 = t_1;
		} else {
			tmp_4 = 2.0 * fma(b, (c / t_0), (c / sqrt(t_0)));
		}
		tmp_3 = tmp_4;
	} else if (t_5 <= -2.7283497524080452e-189) {
		tmp_3 = t_6;
	} else if (t_5 <= 0.0) {
		double tmp_5;
		if (b >= 0.0) {
			tmp_5 = t_4;
		} else {
			tmp_5 = (2.0 * c) / -(b * 2.0);
		}
		tmp_3 = tmp_5;
	} else if (t_5 <= 1.4800849406987464e+262) {
		tmp_3 = t_6;
	} else if (b >= 0.0) {
		tmp_3 = t_1;
	} else {
		tmp_3 = -1.0 * (c / b);
	}
	return tmp_3;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

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

    1. Initial program 37.2

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{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. Taylor expanded in b around 0 17.6

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

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

    if -2.04417239578305246e163 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < -2.72834975240804524e-189 or 0.0 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < 1.4800849406987464e262

    1. Initial program 3.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. Applied egg-rr3.0

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

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

    1. Initial program 32.8

      \[\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. Applied egg-rr32.8

      \[\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}{\mathsf{fma}\left({\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}^{0.25}, {\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}^{0.25}, -b\right)}}\\ \end{array} \]
    3. Taylor expanded in b around -inf 10.8

      \[\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 b}}\\ \end{array} \]
    4. Simplified10.8

      \[\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}{-b \cdot 2}}\\ \end{array} \]

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

    1. Initial program 57.7

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{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. Taylor expanded in b around -inf 14.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\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} \leq -2.0441723957830525 \cdot 10^{+163}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(b, \frac{c}{-4 \cdot \left(a \cdot c\right)}, \frac{c}{\sqrt{-4 \cdot \left(a \cdot c\right)}}\right)\\ \end{array}\\ \mathbf{elif}\;\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} \leq -2.7283497524080452 \cdot 10^{-189}:\\ \;\;\;\;\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{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}}\\ \end{array}\\ \mathbf{elif}\;\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} \leq 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}{-b \cdot 2}\\ \end{array}\\ \mathbf{elif}\;\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} \leq 1.4800849406987464 \cdot 10^{+262}:\\ \;\;\;\;\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{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array} \]

Reproduce

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