Average Error: 29.6 → 1.3
Time: 21.1s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -864984669564619502649344 \lor \neg \left(-2 \cdot x \le 4.629032879111215459799953089899127167683 \cdot 10^{-8}\right):\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(1 \cdot x - \mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\right)\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -864984669564619502649344 \lor \neg \left(-2 \cdot x \le 4.629032879111215459799953089899127167683 \cdot 10^{-8}\right):\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r41368 = 2.0;
        double r41369 = 1.0;
        double r41370 = -2.0;
        double r41371 = x;
        double r41372 = r41370 * r41371;
        double r41373 = exp(r41372);
        double r41374 = r41369 + r41373;
        double r41375 = r41368 / r41374;
        double r41376 = r41375 - r41369;
        return r41376;
}

double f(double x, double __attribute__((unused)) y) {
        double r41377 = -2.0;
        double r41378 = x;
        double r41379 = r41377 * r41378;
        double r41380 = -8.649846695646195e+23;
        bool r41381 = r41379 <= r41380;
        double r41382 = 4.6290328791112155e-08;
        bool r41383 = r41379 <= r41382;
        double r41384 = !r41383;
        bool r41385 = r41381 || r41384;
        double r41386 = 2.0;
        double r41387 = 1.0;
        double r41388 = exp(r41379);
        double r41389 = r41387 + r41388;
        double r41390 = r41386 / r41389;
        double r41391 = r41390 - r41387;
        double r41392 = log1p(r41391);
        double r41393 = expm1(r41392);
        double r41394 = r41387 * r41378;
        double r41395 = 5.551115123125783e-17;
        double r41396 = 4.0;
        double r41397 = pow(r41378, r41396);
        double r41398 = 0.33333333333333337;
        double r41399 = 3.0;
        double r41400 = pow(r41378, r41399);
        double r41401 = r41398 * r41400;
        double r41402 = fma(r41395, r41397, r41401);
        double r41403 = r41394 - r41402;
        double r41404 = log1p(r41403);
        double r41405 = expm1(r41404);
        double r41406 = r41385 ? r41393 : r41405;
        return r41406;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -8.649846695646195e+23 or 4.6290328791112155e-08 < (* -2.0 x)

    1. Initial program 0.1

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied expm1-log1p-u0.1

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

    if -8.649846695646195e+23 < (* -2.0 x) < 4.6290328791112155e-08

    1. Initial program 57.2

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied expm1-log1p-u57.2

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

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

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

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

Reproduce

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