Average Error: 29.7 → 0.4
Time: 4.5s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -1222736.67909369827 \lor \neg \left(-2 \cdot x \le 7.2664552112817958 \cdot 10^{-8}\right):\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -1222736.67909369827 \lor \neg \left(-2 \cdot x \le 7.2664552112817958 \cdot 10^{-8}\right):\\
\;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r53522 = 2.0;
        double r53523 = 1.0;
        double r53524 = -2.0;
        double r53525 = x;
        double r53526 = r53524 * r53525;
        double r53527 = exp(r53526);
        double r53528 = r53523 + r53527;
        double r53529 = r53522 / r53528;
        double r53530 = r53529 - r53523;
        return r53530;
}

double f(double x, double __attribute__((unused)) y) {
        double r53531 = -2.0;
        double r53532 = x;
        double r53533 = r53531 * r53532;
        double r53534 = -1222736.6790936983;
        bool r53535 = r53533 <= r53534;
        double r53536 = 7.266455211281796e-08;
        bool r53537 = r53533 <= r53536;
        double r53538 = !r53537;
        bool r53539 = r53535 || r53538;
        double r53540 = 2.0;
        double r53541 = 1.0;
        double r53542 = exp(r53533);
        double r53543 = r53541 + r53542;
        double r53544 = sqrt(r53543);
        double r53545 = r53540 / r53544;
        double r53546 = r53545 / r53544;
        double r53547 = r53546 - r53541;
        double r53548 = 5.551115123125783e-17;
        double r53549 = 4.0;
        double r53550 = pow(r53532, r53549);
        double r53551 = 0.33333333333333337;
        double r53552 = 3.0;
        double r53553 = pow(r53532, r53552);
        double r53554 = r53551 * r53553;
        double r53555 = fma(r53548, r53550, r53554);
        double r53556 = -r53555;
        double r53557 = fma(r53541, r53532, r53556);
        double r53558 = r53539 ? r53547 : r53557;
        return r53558;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -1222736.6790936983 or 7.266455211281796e-08 < (* -2.0 x)

    1. Initial program 0.1

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.1

      \[\leadsto \frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    4. Applied associate-/r*0.1

      \[\leadsto \color{blue}{\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}}} - 1\]

    if -1222736.6790936983 < (* -2.0 x) < 7.266455211281796e-08

    1. Initial program 58.8

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Taylor expanded around 0 0.6

      \[\leadsto \color{blue}{1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)}\]
    3. Simplified0.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -1222736.67909369827 \lor \neg \left(-2 \cdot x \le 7.2664552112817958 \cdot 10^{-8}\right):\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020021 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  :precision binary64
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))