Average Error: 29.4 → 0.1
Time: 14.1s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.35359945303142865:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{elif}\;-2 \cdot x \le 1.360762104871435 \cdot 10^{-06}:\\ \;\;\;\;\mathsf{fma}\left({x}^{5}, \frac{2}{15}, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \frac{-1}{3}, x, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.35359945303142865:\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\

\mathbf{elif}\;-2 \cdot x \le 1.360762104871435 \cdot 10^{-06}:\\
\;\;\;\;\mathsf{fma}\left({x}^{5}, \frac{2}{15}, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \frac{-1}{3}, x, x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r2138470 = 2.0;
        double r2138471 = 1.0;
        double r2138472 = -2.0;
        double r2138473 = x;
        double r2138474 = r2138472 * r2138473;
        double r2138475 = exp(r2138474);
        double r2138476 = r2138471 + r2138475;
        double r2138477 = r2138470 / r2138476;
        double r2138478 = r2138477 - r2138471;
        return r2138478;
}

double f(double x, double __attribute__((unused)) y) {
        double r2138479 = -2.0;
        double r2138480 = x;
        double r2138481 = r2138479 * r2138480;
        double r2138482 = -0.35359945303142865;
        bool r2138483 = r2138481 <= r2138482;
        double r2138484 = 2.0;
        double r2138485 = 1.0;
        double r2138486 = exp(r2138481);
        double r2138487 = r2138485 + r2138486;
        double r2138488 = r2138484 / r2138487;
        double r2138489 = r2138488 - r2138485;
        double r2138490 = 1.360762104871435e-06;
        bool r2138491 = r2138481 <= r2138490;
        double r2138492 = 5.0;
        double r2138493 = pow(r2138480, r2138492);
        double r2138494 = 0.13333333333333333;
        double r2138495 = r2138480 * r2138480;
        double r2138496 = -0.3333333333333333;
        double r2138497 = r2138495 * r2138496;
        double r2138498 = fma(r2138497, r2138480, r2138480);
        double r2138499 = fma(r2138493, r2138494, r2138498);
        double r2138500 = r2138491 ? r2138499 : r2138489;
        double r2138501 = r2138483 ? r2138489 : r2138500;
        return r2138501;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2 x) < -0.35359945303142865 or 1.360762104871435e-06 < (* -2 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 -0.35359945303142865 < (* -2 x) < 1.360762104871435e-06

    1. Initial program 59.3

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

      \[\leadsto \color{blue}{\left(x + \frac{2}{15} \cdot {x}^{5}\right) - \frac{1}{3} \cdot {x}^{3}}\]
    3. Simplified0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.35359945303142865:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{elif}\;-2 \cdot x \le 1.360762104871435 \cdot 10^{-06}:\\ \;\;\;\;\mathsf{fma}\left({x}^{5}, \frac{2}{15}, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \frac{-1}{3}, x, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \end{array}\]

Reproduce

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