Average Error: 28.5 → 16.7
Time: 14.4s
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 r30344 = b;
        double r30345 = -r30344;
        double r30346 = r30344 * r30344;
        double r30347 = 4.0;
        double r30348 = a;
        double r30349 = r30347 * r30348;
        double r30350 = c;
        double r30351 = r30349 * r30350;
        double r30352 = r30346 - r30351;
        double r30353 = sqrt(r30352);
        double r30354 = r30345 + r30353;
        double r30355 = 2.0;
        double r30356 = r30355 * r30348;
        double r30357 = r30354 / r30356;
        return r30357;
}

double f(double a, double b, double c) {
        double r30358 = b;
        double r30359 = 176.18047484973576;
        bool r30360 = r30358 <= r30359;
        double r30361 = r30358 * r30358;
        double r30362 = 4.0;
        double r30363 = a;
        double r30364 = c;
        double r30365 = r30363 * r30364;
        double r30366 = r30362 * r30365;
        double r30367 = fma(r30358, r30358, r30366);
        double r30368 = r30361 - r30367;
        double r30369 = r30362 * r30363;
        double r30370 = r30369 * r30364;
        double r30371 = r30361 - r30370;
        double r30372 = sqrt(r30371);
        double r30373 = r30372 + r30358;
        double r30374 = r30368 / r30373;
        double r30375 = 2.0;
        double r30376 = r30375 * r30363;
        double r30377 = r30374 / r30376;
        double r30378 = -2.0;
        double r30379 = r30378 * r30365;
        double r30380 = r30358 * r30376;
        double r30381 = r30379 / r30380;
        double r30382 = r30360 ? r30377 : r30381;
        return r30382;
}

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)))