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

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r1489412 = 2.0;
        double r1489413 = 1.0;
        double r1489414 = -2.0;
        double r1489415 = x;
        double r1489416 = r1489414 * r1489415;
        double r1489417 = exp(r1489416);
        double r1489418 = r1489413 + r1489417;
        double r1489419 = r1489412 / r1489418;
        double r1489420 = r1489419 - r1489413;
        return r1489420;
}

double f(double x, double __attribute__((unused)) y) {
        double r1489421 = x;
        double r1489422 = -0.006716681295444204;
        bool r1489423 = r1489421 <= r1489422;
        double r1489424 = 2.0;
        double r1489425 = -2.0;
        double r1489426 = r1489425 * r1489421;
        double r1489427 = exp(r1489426);
        double r1489428 = 1.0;
        double r1489429 = r1489427 + r1489428;
        double r1489430 = r1489424 / r1489429;
        double r1489431 = r1489430 - r1489428;
        double r1489432 = 0.005632491014509446;
        bool r1489433 = r1489421 <= r1489432;
        double r1489434 = r1489421 * r1489421;
        double r1489435 = r1489434 * r1489421;
        double r1489436 = -0.3333333333333333;
        double r1489437 = 5.0;
        double r1489438 = pow(r1489421, r1489437);
        double r1489439 = 0.13333333333333333;
        double r1489440 = fma(r1489438, r1489439, r1489421);
        double r1489441 = fma(r1489435, r1489436, r1489440);
        double r1489442 = r1489433 ? r1489441 : r1489431;
        double r1489443 = r1489423 ? r1489431 : r1489442;
        return r1489443;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if x < -0.006716681295444204 or 0.005632491014509446 < x

    1. Initial program 0.0

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

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

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

    if -0.006716681295444204 < x < 0.005632491014509446

    1. Initial program 59.1

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

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

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

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

Reproduce

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