Average Error: 28.3 → 16.8
Time: 21.2s
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 60.51244836482759836826517130248248577118:\\ \;\;\;\;\frac{\frac{\frac{\left(b \cdot b - 4 \cdot \left(c \cdot a\right)\right) \cdot \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - \left(b \cdot b\right) \cdot b}{\mathsf{fma}\left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}, b, b \cdot b + \left(b \cdot b - 4 \cdot \left(c \cdot a\right)\right)\right)}}{2}}{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 60.51244836482759836826517130248248577118:\\
\;\;\;\;\frac{\frac{\frac{\left(b \cdot b - 4 \cdot \left(c \cdot a\right)\right) \cdot \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - \left(b \cdot b\right) \cdot b}{\mathsf{fma}\left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}, b, b \cdot b + \left(b \cdot b - 4 \cdot \left(c \cdot a\right)\right)\right)}}{2}}{a}\\

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

\end{array}
double f(double a, double b, double c) {
        double r1872364 = b;
        double r1872365 = -r1872364;
        double r1872366 = r1872364 * r1872364;
        double r1872367 = 4.0;
        double r1872368 = a;
        double r1872369 = r1872367 * r1872368;
        double r1872370 = c;
        double r1872371 = r1872369 * r1872370;
        double r1872372 = r1872366 - r1872371;
        double r1872373 = sqrt(r1872372);
        double r1872374 = r1872365 + r1872373;
        double r1872375 = 2.0;
        double r1872376 = r1872375 * r1872368;
        double r1872377 = r1872374 / r1872376;
        return r1872377;
}

double f(double a, double b, double c) {
        double r1872378 = b;
        double r1872379 = 60.5124483648276;
        bool r1872380 = r1872378 <= r1872379;
        double r1872381 = r1872378 * r1872378;
        double r1872382 = 4.0;
        double r1872383 = c;
        double r1872384 = a;
        double r1872385 = r1872383 * r1872384;
        double r1872386 = r1872382 * r1872385;
        double r1872387 = r1872381 - r1872386;
        double r1872388 = sqrt(r1872387);
        double r1872389 = r1872387 * r1872388;
        double r1872390 = r1872381 * r1872378;
        double r1872391 = r1872389 - r1872390;
        double r1872392 = r1872381 + r1872387;
        double r1872393 = fma(r1872388, r1872378, r1872392);
        double r1872394 = r1872391 / r1872393;
        double r1872395 = 2.0;
        double r1872396 = r1872394 / r1872395;
        double r1872397 = r1872396 / r1872384;
        double r1872398 = -1.0;
        double r1872399 = r1872383 / r1872378;
        double r1872400 = r1872398 * r1872399;
        double r1872401 = r1872380 ? r1872397 : r1872400;
        return r1872401;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

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

    1. Initial program 14.3

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

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

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

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

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

    if 60.5124483648276 < b

    1. Initial program 33.9

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

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

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

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

Reproduce

herbie shell --seed 2019172 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, narrow range"
  :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.0 a) c)))) (* 2.0 a)))