Average Error: 44.3 → 10.3
Time: 17.9s
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.23006184402457236:\\ \;\;\;\;\frac{\frac{b \cdot b - \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) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a} \le -7.174313107484387 \cdot 10^{-05}:\\ \;\;\;\;\frac{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\log \left(\frac{c \cdot a}{b}\right)}\right)\right) \cdot -2}{2 \cdot a}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a} \le -7.611140755287658 \cdot 10^{-08}:\\ \;\;\;\;\sqrt[3]{\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{2}}{a} \cdot \left(\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{2}}{a} \cdot \frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{2}}{a}\right)}\\ \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.23006184402457236:\\
\;\;\;\;\frac{\frac{b \cdot b - \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) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\

\mathbf{elif}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a} \le -7.174313107484387 \cdot 10^{-05}:\\
\;\;\;\;\frac{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\log \left(\frac{c \cdot a}{b}\right)}\right)\right) \cdot -2}{2 \cdot a}\\

\mathbf{elif}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a} \le -7.611140755287658 \cdot 10^{-08}:\\
\;\;\;\;\sqrt[3]{\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{2}}{a} \cdot \left(\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{2}}{a} \cdot \frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{2}}{a}\right)}\\

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

\end{array}
double f(double a, double b, double c) {
        double r721411 = b;
        double r721412 = -r721411;
        double r721413 = r721411 * r721411;
        double r721414 = 4.0;
        double r721415 = a;
        double r721416 = r721414 * r721415;
        double r721417 = c;
        double r721418 = r721416 * r721417;
        double r721419 = r721413 - r721418;
        double r721420 = sqrt(r721419);
        double r721421 = r721412 + r721420;
        double r721422 = 2.0;
        double r721423 = r721422 * r721415;
        double r721424 = r721421 / r721423;
        return r721424;
}

double f(double a, double b, double c) {
        double r721425 = b;
        double r721426 = r721425 * r721425;
        double r721427 = 4.0;
        double r721428 = a;
        double r721429 = r721427 * r721428;
        double r721430 = c;
        double r721431 = r721429 * r721430;
        double r721432 = r721426 - r721431;
        double r721433 = sqrt(r721432);
        double r721434 = -r721425;
        double r721435 = r721433 + r721434;
        double r721436 = 2.0;
        double r721437 = r721436 * r721428;
        double r721438 = r721435 / r721437;
        double r721439 = -0.23006184402457236;
        bool r721440 = r721438 <= r721439;
        double r721441 = r721433 * r721433;
        double r721442 = r721426 - r721441;
        double r721443 = r721434 - r721433;
        double r721444 = r721442 / r721443;
        double r721445 = r721444 / r721437;
        double r721446 = -7.174313107484387e-05;
        bool r721447 = r721438 <= r721446;
        double r721448 = r721430 * r721428;
        double r721449 = r721448 / r721425;
        double r721450 = log(r721449);
        double r721451 = exp(r721450);
        double r721452 = log1p(r721451);
        double r721453 = expm1(r721452);
        double r721454 = -2.0;
        double r721455 = r721453 * r721454;
        double r721456 = r721455 / r721437;
        double r721457 = -7.611140755287658e-08;
        bool r721458 = r721438 <= r721457;
        double r721459 = -4.0;
        double r721460 = r721448 * r721459;
        double r721461 = fma(r721425, r721425, r721460);
        double r721462 = sqrt(r721461);
        double r721463 = r721462 - r721425;
        double r721464 = r721463 / r721436;
        double r721465 = r721464 / r721428;
        double r721466 = r721465 * r721465;
        double r721467 = r721465 * r721466;
        double r721468 = cbrt(r721467);
        double r721469 = -r721430;
        double r721470 = r721469 / r721425;
        double r721471 = r721458 ? r721468 : r721470;
        double r721472 = r721447 ? r721456 : r721471;
        double r721473 = r721440 ? r721445 : r721472;
        return r721473;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

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

    1. Initial program 20.3

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

      \[\leadsto \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \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) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2 \cdot a}\]

    if -0.23006184402457236 < (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) < -7.174313107484387e-05

    1. Initial program 23.6

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

      \[\leadsto \frac{\color{blue}{-2 \cdot \frac{a \cdot c}{b}}}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied expm1-log1p-u25.7

      \[\leadsto \frac{-2 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{a \cdot c}{b}\right)\right)}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied add-exp-log25.7

      \[\leadsto \frac{-2 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{a \cdot c}{\color{blue}{e^{\log b}}}\right)\right)}{2 \cdot a}\]
    7. Applied add-exp-log25.8

      \[\leadsto \frac{-2 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{a \cdot \color{blue}{e^{\log c}}}{e^{\log b}}\right)\right)}{2 \cdot a}\]
    8. Applied add-exp-log25.8

      \[\leadsto \frac{-2 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\color{blue}{e^{\log a}} \cdot e^{\log c}}{e^{\log b}}\right)\right)}{2 \cdot a}\]
    9. Applied prod-exp25.8

      \[\leadsto \frac{-2 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\color{blue}{e^{\log a + \log c}}}{e^{\log b}}\right)\right)}{2 \cdot a}\]
    10. Applied div-exp25.8

      \[\leadsto \frac{-2 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{e^{\left(\log a + \log c\right) - \log b}}\right)\right)}{2 \cdot a}\]
    11. Simplified25.7

      \[\leadsto \frac{-2 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(e^{\color{blue}{\log \left(\frac{a \cdot c}{b}\right)}}\right)\right)}{2 \cdot a}\]

    if -7.174313107484387e-05 < (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) < -7.611140755287658e-08

    1. Initial program 25.4

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\sqrt[3]{\left(\left(2 \cdot a\right) \cdot \left(2 \cdot a\right)\right) \cdot \left(2 \cdot a\right)}}}\]
    4. Applied add-cbrt-cube25.4

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

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

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

    if -7.611140755287658e-08 < (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))

    1. Initial program 54.3

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

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

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

    \[\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.23006184402457236:\\ \;\;\;\;\frac{\frac{b \cdot b - \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) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a} \le -7.174313107484387 \cdot 10^{-05}:\\ \;\;\;\;\frac{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\log \left(\frac{c \cdot a}{b}\right)}\right)\right) \cdot -2}{2 \cdot a}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a} \le -7.611140755287658 \cdot 10^{-08}:\\ \;\;\;\;\sqrt[3]{\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{2}}{a} \cdot \left(\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{2}}{a} \cdot \frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{2}}{a}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019151 +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)))