Average Error: 43.7 → 11.5
Time: 13.1s
Precision: 64
\[1.1102230246251565404236316680908203125 \cdot 10^{-16} \lt a \lt 9007199254740992 \land 1.1102230246251565404236316680908203125 \cdot 10^{-16} \lt b \lt 9007199254740992 \land 1.1102230246251565404236316680908203125 \cdot 10^{-16} \lt c \lt 9007199254740992\]
\[\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 0.1273142573446926772984255649134865961969:\\ \;\;\;\;\frac{\frac{b \cdot b - \mathsf{fma}\left(c, 4 \cdot a, b \cdot b\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 0.1273142573446926772984255649134865961969:\\
\;\;\;\;\frac{\frac{b \cdot b - \mathsf{fma}\left(c, 4 \cdot a, b \cdot b\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 r31418 = b;
        double r31419 = -r31418;
        double r31420 = r31418 * r31418;
        double r31421 = 4.0;
        double r31422 = a;
        double r31423 = r31421 * r31422;
        double r31424 = c;
        double r31425 = r31423 * r31424;
        double r31426 = r31420 - r31425;
        double r31427 = sqrt(r31426);
        double r31428 = r31419 + r31427;
        double r31429 = 2.0;
        double r31430 = r31429 * r31422;
        double r31431 = r31428 / r31430;
        return r31431;
}

double f(double a, double b, double c) {
        double r31432 = b;
        double r31433 = 0.12731425734469268;
        bool r31434 = r31432 <= r31433;
        double r31435 = r31432 * r31432;
        double r31436 = c;
        double r31437 = 4.0;
        double r31438 = a;
        double r31439 = r31437 * r31438;
        double r31440 = fma(r31436, r31439, r31435);
        double r31441 = r31435 - r31440;
        double r31442 = r31439 * r31436;
        double r31443 = r31435 - r31442;
        double r31444 = sqrt(r31443);
        double r31445 = r31444 + r31432;
        double r31446 = r31441 / r31445;
        double r31447 = 2.0;
        double r31448 = r31447 * r31438;
        double r31449 = r31446 / r31448;
        double r31450 = -1.0;
        double r31451 = r31436 / r31432;
        double r31452 = r31450 * r31451;
        double r31453 = r31434 ? r31449 : r31452;
        return r31453;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

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

    1. Initial program 23.3

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

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

      \[\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. Simplified22.4

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

    if 0.12731425734469268 < b

    1. Initial program 46.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified46.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 9.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 0.1273142573446926772984255649134865961969:\\ \;\;\;\;\frac{\frac{b \cdot b - \mathsf{fma}\left(c, 4 \cdot a, b \cdot b\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 2019209 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, medium range"
  :precision binary64
  :pre (and (< 1.11022e-16 a 9.0072e15) (< 1.11022e-16 b 9.0072e15) (< 1.11022e-16 c 9.0072e15))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))