Average Error: 29.0 → 0.2
Time: 3.7s
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):\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\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):\\
\;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r51298 = 2.0;
        double r51299 = 1.0;
        double r51300 = -2.0;
        double r51301 = x;
        double r51302 = r51300 * r51301;
        double r51303 = exp(r51302);
        double r51304 = r51299 + r51303;
        double r51305 = r51298 / r51304;
        double r51306 = r51305 - r51299;
        return r51306;
}

double f(double x, double __attribute__((unused)) y) {
        double r51307 = -2.0;
        double r51308 = x;
        double r51309 = r51307 * r51308;
        double r51310 = -220.3193758652155;
        bool r51311 = r51309 <= r51310;
        double r51312 = 3.5641667088244574e-06;
        bool r51313 = r51309 <= r51312;
        double r51314 = !r51313;
        bool r51315 = r51311 || r51314;
        double r51316 = 2.0;
        double r51317 = exp(r51309);
        double r51318 = 1.0;
        double r51319 = r51317 + r51318;
        double r51320 = r51316 / r51319;
        double r51321 = r51320 - r51318;
        double r51322 = 5.551115123125783e-17;
        double r51323 = 4.0;
        double r51324 = pow(r51308, r51323);
        double r51325 = 0.33333333333333337;
        double r51326 = 3.0;
        double r51327 = pow(r51308, r51326);
        double r51328 = r51325 * r51327;
        double r51329 = fma(r51322, r51324, r51328);
        double r51330 = -r51329;
        double r51331 = fma(r51318, r51308, r51330);
        double r51332 = r51315 ? r51321 : r51331;
        return r51332;
}

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. 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 -220.3193758652155 < (* -2.0 x) < 3.5641667088244574e-06

    1. Initial program 58.9

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. 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)}\]
    3. Simplified0.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\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):\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\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))