Average Error: 34.0 → 9.2
Time: 7.5s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -3.5922101775304284 \cdot 10^{+129}:\\ \;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\ \mathbf{elif}\;b \leq 3.5099172996677927 \cdot 10^{-102}:\\ \;\;\;\;\frac{\mathsf{fma}\left(1, -b, \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}\right)}{2 \cdot a}\\ \mathbf{elif}\;b \leq 25822214016469920:\\ \;\;\;\;\frac{\left(a \cdot \left(c \cdot -4\right)\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} \]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -3.5922101775304284 \cdot 10^{+129}:\\
\;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\

\mathbf{elif}\;b \leq 3.5099172996677927 \cdot 10^{-102}:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, -b, \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}\right)}{2 \cdot a}\\

\mathbf{elif}\;b \leq 25822214016469920:\\
\;\;\;\;\frac{\left(a \cdot \left(c \cdot -4\right)\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}
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (if (<= b -3.5922101775304284e+129)
   (/ (* b -2.0) (* 2.0 a))
   (if (<= b 3.5099172996677927e-102)
     (/ (fma 1.0 (- b) (sqrt (- (* b b) (* (* a 4.0) c)))) (* 2.0 a))
     (if (<= b 25822214016469920.0)
       (/
        (* (* a (* c -4.0)) (/ 0.5 a))
        (+ b (sqrt (fma a (* c -4.0) (* b b)))))
       (- (/ c b))))))
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 tmp;
	if (b <= -3.5922101775304284e+129) {
		tmp = (b * -2.0) / (2.0 * a);
	} else if (b <= 3.5099172996677927e-102) {
		tmp = fma(1.0, -b, sqrt((b * b) - ((a * 4.0) * c))) / (2.0 * a);
	} else if (b <= 25822214016469920.0) {
		tmp = ((a * (c * -4.0)) * (0.5 / a)) / (b + sqrt(fma(a, (c * -4.0), (b * b))));
	} else {
		tmp = -(c / b);
	}
	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 < -3.592210177530428e129

    1. Initial program 55.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Taylor expanded in b around -inf 2.8

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

    if -3.592210177530428e129 < b < 3.50991729966779272e-102

    1. Initial program 12.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Applied *-un-lft-identity_binary6412.1

      \[\leadsto \frac{\color{blue}{1 \cdot \left(-b\right)} + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    3. Applied fma-def_binary6412.1

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

    if 3.50991729966779272e-102 < b < 25822214016469920

    1. Initial program 36.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Simplified36.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. Applied flip--_binary6436.4

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} \cdot \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b \cdot b}{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} + b}} \cdot \frac{0.5}{a} \]
    4. Applied associate-*l/_binary6436.4

      \[\leadsto \color{blue}{\frac{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} \cdot \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b \cdot b\right) \cdot \frac{0.5}{a}}{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} + b}} \]
    5. Simplified15.7

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

    if 25822214016469920 < b

    1. Initial program 56.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Taylor expanded in b around inf 5.6

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification9.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.5922101775304284 \cdot 10^{+129}:\\ \;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\ \mathbf{elif}\;b \leq 3.5099172996677927 \cdot 10^{-102}:\\ \;\;\;\;\frac{\mathsf{fma}\left(1, -b, \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}\right)}{2 \cdot a}\\ \mathbf{elif}\;b \leq 25822214016469920:\\ \;\;\;\;\frac{\left(a \cdot \left(c \cdot -4\right)\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 2022095 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))