Average Error: 28.7 → 5.1
Time: 11.2s
Precision: binary64
\[1.0536712127723509 \cdot 10^{-8} < a \land a < 94906265.62425156 \land 1.0536712127723509 \cdot 10^{-8} < b \land b < 94906265.62425156 \land 1.0536712127723509 \cdot 10^{-8} < c \land c < 94906265.62425156\]
\[\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 0.06736950397042363:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} \cdot -2 - \left(5 \cdot \frac{{c}^{4} \cdot {a}^{3}}{{b}^{7}} + \left(\frac{a \cdot {c}^{2}}{{b}^{3}} + \frac{c}{b}\right)\right)\\ \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 0.06736950397042363:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)} - b}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;\frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} \cdot -2 - \left(5 \cdot \frac{{c}^{4} \cdot {a}^{3}}{{b}^{7}} + \left(\frac{a \cdot {c}^{2}}{{b}^{3}} + \frac{c}{b}\right)\right)\\


\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 0.06736950397042363)
   (/
    (-
     (sqrt
      (+ (fma b b (* c (* a -4.0))) (fma (- c) (* 4.0 a) (* c (* 4.0 a)))))
     b)
    (* a 2.0))
   (-
    (* (/ (* (pow c 3.0) (pow a 2.0)) (pow b 5.0)) -2.0)
    (+
     (* 5.0 (/ (* (pow c 4.0) (pow a 3.0)) (pow b 7.0)))
     (+ (/ (* a (pow c 2.0)) (pow b 3.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 <= 0.06736950397042363) {
		tmp = (sqrt(fma(b, b, (c * (a * -4.0))) + fma(-c, (4.0 * a), (c * (4.0 * a)))) - b) / (a * 2.0);
	} else {
		tmp = (((pow(c, 3.0) * pow(a, 2.0)) / pow(b, 5.0)) * -2.0) - ((5.0 * ((pow(c, 4.0) * pow(a, 3.0)) / pow(b, 7.0))) + (((a * pow(c, 2.0)) / pow(b, 3.0)) + (c / b)));
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 0.067369503970423628

    1. Initial program 9.5

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

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

    if 0.067369503970423628 < b

    1. Initial program 30.8

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

      \[\leadsto \color{blue}{-\left(2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} + \left(5 \cdot \frac{{c}^{4} \cdot {a}^{3}}{{b}^{7}} + \left(\frac{{c}^{2} \cdot a}{{b}^{3}} + \frac{c}{b}\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification5.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 0.06736950397042363:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} \cdot -2 - \left(5 \cdot \frac{{c}^{4} \cdot {a}^{3}}{{b}^{7}} + \left(\frac{a \cdot {c}^{2}}{{b}^{3}} + \frac{c}{b}\right)\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2021224 
(FPCore (a b c)
  :name "Quadratic roots, narrow range"
  :precision binary64
  :pre (and (< 1.0536712127723509e-8 a 94906265.62425156) (< 1.0536712127723509e-8 b 94906265.62425156) (< 1.0536712127723509e-8 c 94906265.62425156))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))