Average Error: 33.9 → 8.7
Time: 8.8s
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.738191357919323 \cdot 10^{+116}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\\ \mathbf{if}\;b \leq 3.504400908400674 \cdot 10^{-178}:\\ \;\;\;\;\frac{\left(t_0 - b\right) \cdot 0.5}{a}\\ \mathbf{elif}\;b \leq 2.980663629993403 \cdot 10^{+79}:\\ \;\;\;\;\frac{\left(c \cdot \left(a \cdot -4\right)\right) \cdot \frac{0.5}{a}}{b + t_0}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\\ \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.738191357919323 \cdot 10^{+116}:\\
\;\;\;\;\frac{-b}{a}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\\
\mathbf{if}\;b \leq 3.504400908400674 \cdot 10^{-178}:\\
\;\;\;\;\frac{\left(t_0 - b\right) \cdot 0.5}{a}\\

\mathbf{elif}\;b \leq 2.980663629993403 \cdot 10^{+79}:\\
\;\;\;\;\frac{\left(c \cdot \left(a \cdot -4\right)\right) \cdot \frac{0.5}{a}}{b + t_0}\\

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


\end{array}\\


\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.738191357919323e+116)
   (/ (- b) a)
   (let* ((t_0 (sqrt (fma a (* c -4.0) (* b b)))))
     (if (<= b 3.504400908400674e-178)
       (/ (* (- t_0 b) 0.5) a)
       (if (<= b 2.980663629993403e+79)
         (/ (* (* c (* a -4.0)) (/ 0.5 a)) (+ b t_0))
         (- (/ 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.738191357919323e+116) {
		tmp = -b / a;
	} else {
		double t_0 = sqrt(fma(a, (c * -4.0), (b * b)));
		double tmp_1;
		if (b <= 3.504400908400674e-178) {
			tmp_1 = ((t_0 - b) * 0.5) / a;
		} else if (b <= 2.980663629993403e+79) {
			tmp_1 = ((c * (a * -4.0)) * (0.5 / a)) / (b + t_0);
		} else {
			tmp_1 = -(c / b);
		}
		tmp = tmp_1;
	}
	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.7381913579193229e116

    1. Initial program 51.5

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    4. Simplified4.2

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

    if -3.7381913579193229e116 < b < 3.50440090840067388e-178

    1. Initial program 10.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Simplified10.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 associate-*r/_binary6410.7

      \[\leadsto \color{blue}{\frac{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b\right) \cdot 0.5}{a}} \]
    4. Applied *-un-lft-identity_binary6410.7

      \[\leadsto \frac{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - \color{blue}{1 \cdot b}\right) \cdot 0.5}{a} \]
    5. Applied cancel-sign-sub-inv_binary6410.7

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

    if 3.50440090840067388e-178 < b < 2.9806636299934028e79

    1. Initial program 35.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Simplified35.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--_binary6435.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/_binary6435.5

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

      \[\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 2.9806636299934028e79 < b

    1. Initial program 58.3

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    4. Simplified3.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.738191357919323 \cdot 10^{+116}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 3.504400908400674 \cdot 10^{-178}:\\ \;\;\;\;\frac{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b\right) \cdot 0.5}{a}\\ \mathbf{elif}\;b \leq 2.980663629993403 \cdot 10^{+79}:\\ \;\;\;\;\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 2022019 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))