Average Error: 28.5 → 16.5
Time: 7.3s
Precision: 64
\[1.053671212772350866701172186984739043147 \cdot 10^{-8} \lt a \lt 94906265.62425155937671661376953125 \land 1.053671212772350866701172186984739043147 \cdot 10^{-8} \lt b \lt 94906265.62425155937671661376953125 \land 1.053671212772350866701172186984739043147 \cdot 10^{-8} \lt c \lt 94906265.62425155937671661376953125\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le 140.4798093952274200546526117250323295593:\\ \;\;\;\;\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \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 \le 140.4798093952274200546526117250323295593:\\
\;\;\;\;\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}{2 \cdot a}\\

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

\end{array}
double f(double a, double b, double c) {
        double r19385 = b;
        double r19386 = -r19385;
        double r19387 = r19385 * r19385;
        double r19388 = 4.0;
        double r19389 = a;
        double r19390 = r19388 * r19389;
        double r19391 = c;
        double r19392 = r19390 * r19391;
        double r19393 = r19387 - r19392;
        double r19394 = sqrt(r19393);
        double r19395 = r19386 + r19394;
        double r19396 = 2.0;
        double r19397 = r19396 * r19389;
        double r19398 = r19395 / r19397;
        return r19398;
}

double f(double a, double b, double c) {
        double r19399 = b;
        double r19400 = 140.47980939522742;
        bool r19401 = r19399 <= r19400;
        double r19402 = r19399 * r19399;
        double r19403 = 4.0;
        double r19404 = a;
        double r19405 = c;
        double r19406 = r19404 * r19405;
        double r19407 = r19403 * r19406;
        double r19408 = fma(r19399, r19399, r19407);
        double r19409 = r19402 - r19408;
        double r19410 = r19403 * r19404;
        double r19411 = r19410 * r19405;
        double r19412 = r19402 - r19411;
        double r19413 = sqrt(r19412);
        double r19414 = r19413 + r19399;
        double r19415 = r19409 / r19414;
        double r19416 = 2.0;
        double r19417 = r19416 * r19404;
        double r19418 = r19415 / r19417;
        double r19419 = -1.0;
        double r19420 = r19405 / r19399;
        double r19421 = r19419 * r19420;
        double r19422 = r19401 ? r19418 : r19421;
        return r19422;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

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

    1. Initial program 15.1

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied flip--15.1

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

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

    if 140.47980939522742 < b

    1. Initial program 34.7

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Taylor expanded around inf 17.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 140.4798093952274200546526117250323295593:\\ \;\;\;\;\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019351 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, narrow range"
  :precision binary64
  :pre (and (< 1.0536712127723509e-08 a 94906265.62425156) (< 1.0536712127723509e-08 b 94906265.62425156) (< 1.0536712127723509e-08 c 94906265.62425156))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))