Average Error: 44.2 → 9.8
Time: 14.2s
Precision: 64
\[1.1102230246251565 \cdot 10^{-16} \lt a \lt 9007199254740992.0 \land 1.1102230246251565 \cdot 10^{-16} \lt b \lt 9007199254740992.0 \land 1.1102230246251565 \cdot 10^{-16} \lt c \lt 9007199254740992.0\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a} \le -0.000703251181521921:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, \left(c \cdot \left(-4 \cdot a\right)\right)\right) \cdot \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(-4 \cdot a\right)\right)\right)} - b \cdot \left(b \cdot b\right)}{\mathsf{fma}\left(\left(\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(-4 \cdot a\right)\right)\right)}\right), \left(\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(-4 \cdot a\right)\right)\right)} + b\right), \left(b \cdot b\right)\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\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}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a} \le -0.000703251181521921:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, \left(c \cdot \left(-4 \cdot a\right)\right)\right) \cdot \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(-4 \cdot a\right)\right)\right)} - b \cdot \left(b \cdot b\right)}{\mathsf{fma}\left(\left(\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(-4 \cdot a\right)\right)\right)}\right), \left(\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(-4 \cdot a\right)\right)\right)} + b\right), \left(b \cdot b\right)\right)}}{2 \cdot a}\\

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

\end{array}
double f(double a, double b, double c) {
        double r595544 = b;
        double r595545 = -r595544;
        double r595546 = r595544 * r595544;
        double r595547 = 4.0;
        double r595548 = a;
        double r595549 = r595547 * r595548;
        double r595550 = c;
        double r595551 = r595549 * r595550;
        double r595552 = r595546 - r595551;
        double r595553 = sqrt(r595552);
        double r595554 = r595545 + r595553;
        double r595555 = 2.0;
        double r595556 = r595555 * r595548;
        double r595557 = r595554 / r595556;
        return r595557;
}

double f(double a, double b, double c) {
        double r595558 = b;
        double r595559 = r595558 * r595558;
        double r595560 = 4.0;
        double r595561 = a;
        double r595562 = r595560 * r595561;
        double r595563 = c;
        double r595564 = r595562 * r595563;
        double r595565 = r595559 - r595564;
        double r595566 = sqrt(r595565);
        double r595567 = -r595558;
        double r595568 = r595566 + r595567;
        double r595569 = 2.0;
        double r595570 = r595569 * r595561;
        double r595571 = r595568 / r595570;
        double r595572 = -0.000703251181521921;
        bool r595573 = r595571 <= r595572;
        double r595574 = -4.0;
        double r595575 = r595574 * r595561;
        double r595576 = r595563 * r595575;
        double r595577 = fma(r595558, r595558, r595576);
        double r595578 = sqrt(r595577);
        double r595579 = r595577 * r595578;
        double r595580 = r595558 * r595559;
        double r595581 = r595579 - r595580;
        double r595582 = r595578 + r595558;
        double r595583 = fma(r595578, r595582, r595559);
        double r595584 = r595581 / r595583;
        double r595585 = r595584 / r595570;
        double r595586 = r595563 / r595558;
        double r595587 = -r595586;
        double r595588 = r595573 ? r595585 : r595587;
        return r595588;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) < -0.000703251181521921

    1. Initial program 20.5

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

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

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

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

    if -0.000703251181521921 < (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))

    1. Initial program 50.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around inf 7.1

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    3. Simplified7.1

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

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

Reproduce

herbie shell --seed 2019128 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, medium range"
  :pre (and (< 1.1102230246251565e-16 a 9007199254740992.0) (< 1.1102230246251565e-16 b 9007199254740992.0) (< 1.1102230246251565e-16 c 9007199254740992.0))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))