Average Error: 28.5 → 16.7
Time: 14.6s
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 176.1804748497357593350898241624236106873:\\ \;\;\;\;\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}:\\ \;\;\;\;\frac{-2 \cdot \left(a \cdot c\right)}{b \cdot \left(2 \cdot a\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 \le 176.1804748497357593350898241624236106873:\\
\;\;\;\;\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}:\\
\;\;\;\;\frac{-2 \cdot \left(a \cdot c\right)}{b \cdot \left(2 \cdot a\right)}\\

\end{array}
double f(double a, double b, double c) {
        double r30332 = b;
        double r30333 = -r30332;
        double r30334 = r30332 * r30332;
        double r30335 = 4.0;
        double r30336 = a;
        double r30337 = r30335 * r30336;
        double r30338 = c;
        double r30339 = r30337 * r30338;
        double r30340 = r30334 - r30339;
        double r30341 = sqrt(r30340);
        double r30342 = r30333 + r30341;
        double r30343 = 2.0;
        double r30344 = r30343 * r30336;
        double r30345 = r30342 / r30344;
        return r30345;
}

double f(double a, double b, double c) {
        double r30346 = b;
        double r30347 = 176.18047484973576;
        bool r30348 = r30346 <= r30347;
        double r30349 = r30346 * r30346;
        double r30350 = 4.0;
        double r30351 = a;
        double r30352 = c;
        double r30353 = r30351 * r30352;
        double r30354 = r30350 * r30353;
        double r30355 = fma(r30346, r30346, r30354);
        double r30356 = r30349 - r30355;
        double r30357 = r30350 * r30351;
        double r30358 = r30357 * r30352;
        double r30359 = r30349 - r30358;
        double r30360 = sqrt(r30359);
        double r30361 = r30360 + r30346;
        double r30362 = r30356 / r30361;
        double r30363 = 2.0;
        double r30364 = r30363 * r30351;
        double r30365 = r30362 / r30364;
        double r30366 = -2.0;
        double r30367 = r30366 * r30353;
        double r30368 = r30346 * r30364;
        double r30369 = r30367 / r30368;
        double r30370 = r30348 ? r30365 : r30369;
        return r30370;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

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

    1. Initial program 15.5

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

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

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

      \[\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 176.18047484973576 < b

    1. Initial program 34.6

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

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

      \[\leadsto \frac{\color{blue}{-2 \cdot \frac{a \cdot c}{b}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt17.7

      \[\leadsto \frac{-2 \cdot \frac{a \cdot c}{\color{blue}{\sqrt{b} \cdot \sqrt{b}}}}{2 \cdot a}\]
    6. Applied times-frac17.7

      \[\leadsto \frac{-2 \cdot \color{blue}{\left(\frac{a}{\sqrt{b}} \cdot \frac{c}{\sqrt{b}}\right)}}{2 \cdot a}\]
    7. Using strategy rm
    8. Applied frac-times17.7

      \[\leadsto \frac{-2 \cdot \color{blue}{\frac{a \cdot c}{\sqrt{b} \cdot \sqrt{b}}}}{2 \cdot a}\]
    9. Applied associate-*r/17.7

      \[\leadsto \frac{\color{blue}{\frac{-2 \cdot \left(a \cdot c\right)}{\sqrt{b} \cdot \sqrt{b}}}}{2 \cdot a}\]
    10. Applied associate-/l/17.7

      \[\leadsto \color{blue}{\frac{-2 \cdot \left(a \cdot c\right)}{\left(2 \cdot a\right) \cdot \left(\sqrt{b} \cdot \sqrt{b}\right)}}\]
    11. Simplified17.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 176.1804748497357593350898241624236106873:\\ \;\;\;\;\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}:\\ \;\;\;\;\frac{-2 \cdot \left(a \cdot c\right)}{b \cdot \left(2 \cdot a\right)}\\ \end{array}\]

Reproduce

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