Average Error: 29.0 → 0.2
Time: 20.8s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -220.3193758652155054278409807011485099792 \lor \neg \left(-2 \cdot x \le 3.564166708824457449394582098101125211542 \cdot 10^{-6}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right) - 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 -220.3193758652155054278409807011485099792 \lor \neg \left(-2 \cdot x \le 3.564166708824457449394582098101125211542 \cdot 10^{-6}\right):\\
\;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right) - 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 r34412 = 2.0;
        double r34413 = 1.0;
        double r34414 = -2.0;
        double r34415 = x;
        double r34416 = r34414 * r34415;
        double r34417 = exp(r34416);
        double r34418 = r34413 + r34417;
        double r34419 = r34412 / r34418;
        double r34420 = r34419 - r34413;
        return r34420;
}

double f(double x, double __attribute__((unused)) y) {
        double r34421 = -2.0;
        double r34422 = x;
        double r34423 = r34421 * r34422;
        double r34424 = -220.3193758652155;
        bool r34425 = r34423 <= r34424;
        double r34426 = 3.5641667088244574e-06;
        bool r34427 = r34423 <= r34426;
        double r34428 = !r34427;
        bool r34429 = r34425 || r34428;
        double r34430 = 2.0;
        double r34431 = 1.0;
        double r34432 = exp(r34423);
        double r34433 = r34431 + r34432;
        double r34434 = r34430 / r34433;
        double r34435 = exp(r34434);
        double r34436 = log(r34435);
        double r34437 = r34436 - r34431;
        double r34438 = r34431 * r34422;
        double r34439 = 5.551115123125783e-17;
        double r34440 = 4.0;
        double r34441 = pow(r34422, r34440);
        double r34442 = 0.33333333333333337;
        double r34443 = 3.0;
        double r34444 = pow(r34422, r34443);
        double r34445 = r34442 * r34444;
        double r34446 = fma(r34439, r34441, r34445);
        double r34447 = r34438 - r34446;
        double r34448 = r34429 ? r34437 : r34447;
        return r34448;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right)} - 1\]

    if -220.3193758652155 < (* -2.0 x) < 3.5641667088244574e-06

    1. Initial program 58.9

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

      \[\leadsto \color{blue}{\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right)} - 1\]
    4. Taylor expanded around 0 0.3

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

      \[\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.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -220.3193758652155054278409807011485099792 \lor \neg \left(-2 \cdot x \le 3.564166708824457449394582098101125211542 \cdot 10^{-6}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right) - 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 2019347 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  :precision binary64
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))