Average Error: 34.3 → 10.3
Time: 13.7s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)\\ t_1 := \sqrt{t_0}\\ t_2 := -\frac{c}{b}\\ \mathbf{if}\;b \leq -1.251564096671974 \cdot 10^{+46}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.2846674157042731 \cdot 10^{-107}:\\ \;\;\;\;\frac{t_1}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 1.3948090615163448 \cdot 10^{-71}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 4.4233955990605117 \cdot 10^{-54}:\\ \;\;\;\;\frac{\left(t_0 - b \cdot b\right) \cdot \frac{0.5}{a}}{b + t_1}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
t_0 := \mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)\\
t_1 := \sqrt{t_0}\\
t_2 := -\frac{c}{b}\\
\mathbf{if}\;b \leq -1.251564096671974 \cdot 10^{+46}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq 1.2846674157042731 \cdot 10^{-107}:\\
\;\;\;\;\frac{t_1}{a \cdot 2} - \frac{b}{a \cdot 2}\\

\mathbf{elif}\;b \leq 1.3948090615163448 \cdot 10^{-71}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;b \leq 4.4233955990605117 \cdot 10^{-54}:\\
\;\;\;\;\frac{\left(t_0 - b \cdot b\right) \cdot \frac{0.5}{a}}{b + t_1}\\

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


\end{array}
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (fma a (* c -4.0) (* b b))) (t_1 (sqrt t_0)) (t_2 (- (/ c b))))
   (if (<= b -1.251564096671974e+46)
     (- (/ c b) (/ b a))
     (if (<= b 1.2846674157042731e-107)
       (- (/ t_1 (* a 2.0)) (/ b (* a 2.0)))
       (if (<= b 1.3948090615163448e-71)
         t_2
         (if (<= b 4.4233955990605117e-54)
           (/ (* (- t_0 (* b b)) (/ 0.5 a)) (+ b t_1))
           t_2))))))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
double code(double a, double b, double c) {
	double t_0 = fma(a, (c * -4.0), (b * b));
	double t_1 = sqrt(t_0);
	double t_2 = -(c / b);
	double tmp;
	if (b <= -1.251564096671974e+46) {
		tmp = (c / b) - (b / a);
	} else if (b <= 1.2846674157042731e-107) {
		tmp = (t_1 / (a * 2.0)) - (b / (a * 2.0));
	} else if (b <= 1.3948090615163448e-71) {
		tmp = t_2;
	} else if (b <= 4.4233955990605117e-54) {
		tmp = ((t_0 - (b * b)) * (0.5 / a)) / (b + t_1);
	} else {
		tmp = t_2;
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b < -1.25156409667197408e46

    1. Initial program 38.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Simplified38.4

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b\right) \cdot \frac{0.5}{a}} \]
    3. Taylor expanded in b around -inf 5.2

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}} \]

    if -1.25156409667197408e46 < b < 1.28466741570427313e-107

    1. Initial program 13.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Simplified13.1

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b\right) \cdot \frac{0.5}{a}} \]
    3. Applied egg-rr13.0

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}} \]
    4. Applied egg-rr13.0

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}} \]

    if 1.28466741570427313e-107 < b < 1.3948090615163448e-71 or 4.4233955990605117e-54 < b

    1. Initial program 52.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Simplified52.7

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b\right) \cdot \frac{0.5}{a}} \]
    3. Taylor expanded in a around 0 9.5

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]

    if 1.3948090615163448e-71 < b < 4.4233955990605117e-54

    1. Initial program 33.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Simplified33.8

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b\right) \cdot \frac{0.5}{a}} \]
    3. Applied egg-rr33.8

      \[\leadsto \color{blue}{\frac{\left(\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right) - b \cdot b\right) \cdot \frac{0.5}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification10.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.251564096671974 \cdot 10^{+46}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.2846674157042731 \cdot 10^{-107}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 1.3948090615163448 \cdot 10^{-71}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 4.4233955990605117 \cdot 10^{-54}:\\ \;\;\;\;\frac{\left(\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right) - b \cdot b\right) \cdot \frac{0.5}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]

Reproduce

herbie shell --seed 2022130 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))