Average Error: 34.0 → 8.8
Time: 11.7s
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 -2.537327432321044 \cdot 10^{+141}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.434416530792524 \cdot 10^{-278}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 17575646688649824000:\\ \;\;\;\;\frac{\left(c \cdot \left(a \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 -2.537327432321044 \cdot 10^{+141}:\\
\;\;\;\;\frac{-b}{a}\\

\mathbf{elif}\;b \leq 1.434416530792524 \cdot 10^{-278}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\

\mathbf{elif}\;b \leq 17575646688649824000:\\
\;\;\;\;\frac{\left(c \cdot \left(a \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 -2.537327432321044e+141)
   (/ (- b) a)
   (if (<= b 1.434416530792524e-278)
     (/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
     (if (<= b 17575646688649824000.0)
       (/
        (* (* c (* a -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 <= -2.537327432321044e+141) {
		tmp = -b / a;
	} else if (b <= 1.434416530792524e-278) {
		tmp = (sqrt((b * b) - ((a * 4.0) * c)) - b) / (a * 2.0);
	} else if (b <= 17575646688649824000.0) {
		tmp = ((c * (a * -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 < -2.53732743232104416e141

    1. Initial program 59.4

      \[\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.7

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    3. Simplified2.7

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

    if -2.53732743232104416e141 < b < 1.434416530792524e-278

    1. Initial program 8.4

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

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

    if 1.434416530792524e-278 < b < 17575646688649824300

    1. Initial program 28.9

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

      \[\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--_binary6429.0

      \[\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/_binary6429.0

      \[\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. Simplified18.1

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

    if 17575646688649824300 < b

    1. Initial program 56.0

      \[\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.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.537327432321044 \cdot 10^{+141}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.434416530792524 \cdot 10^{-278}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 17575646688649824000:\\ \;\;\;\;\frac{\left(c \cdot \left(a \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 2021280 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))