Average Error: 29.6 → 0.1
Time: 12.9s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -2.824925416399024502567272065789438784122 \lor \neg \left(-2 \cdot x \le 3.433603601045391940976749672875811825179 \cdot 10^{-6}\right):\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -2.824925416399024502567272065789438784122 \lor \neg \left(-2 \cdot x \le 3.433603601045391940976749672875811825179 \cdot 10^{-6}\right):\\
\;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r39564 = 2.0;
        double r39565 = 1.0;
        double r39566 = -2.0;
        double r39567 = x;
        double r39568 = r39566 * r39567;
        double r39569 = exp(r39568);
        double r39570 = r39565 + r39569;
        double r39571 = r39564 / r39570;
        double r39572 = r39571 - r39565;
        return r39572;
}

double f(double x, double __attribute__((unused)) y) {
        double r39573 = -2.0;
        double r39574 = x;
        double r39575 = r39573 * r39574;
        double r39576 = -2.8249254163990245;
        bool r39577 = r39575 <= r39576;
        double r39578 = 3.433603601045392e-06;
        bool r39579 = r39575 <= r39578;
        double r39580 = !r39579;
        bool r39581 = r39577 || r39580;
        double r39582 = 2.0;
        double r39583 = exp(r39575);
        double r39584 = 1.0;
        double r39585 = r39583 + r39584;
        double r39586 = r39582 / r39585;
        double r39587 = r39586 - r39584;
        double r39588 = r39584 * r39574;
        double r39589 = 5.551115123125783e-17;
        double r39590 = 4.0;
        double r39591 = pow(r39574, r39590);
        double r39592 = 0.33333333333333337;
        double r39593 = 3.0;
        double r39594 = pow(r39574, r39593);
        double r39595 = r39592 * r39594;
        double r39596 = fma(r39589, r39591, r39595);
        double r39597 = r39588 - r39596;
        double r39598 = r39581 ? r39587 : r39597;
        return r39598;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -2.8249254163990245 or 3.433603601045392e-06 < (* -2.0 x)

    1. Initial program 0.1

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

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

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

    if -2.8249254163990245 < (* -2.0 x) < 3.433603601045392e-06

    1. Initial program 59.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -2.824925416399024502567272065789438784122 \lor \neg \left(-2 \cdot x \le 3.433603601045391940976749672875811825179 \cdot 10^{-6}\right):\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \end{array}\]

Reproduce

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