Average Error: 29.0 → 0.0
Time: 16.8s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.005906231757156013:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{elif}\;x \le 0.007737245144532784:\\ \;\;\;\;\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}:\\ \;\;\;\;\mathsf{fma}\left(\left(\frac{2}{\mathsf{expm1}\left(\left(-4 \cdot x\right)\right)}\right), \left(\mathsf{expm1}\left(\left(-2 \cdot x\right)\right)\right), -1\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;x \le -0.005906231757156013:\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\

\mathbf{elif}\;x \le 0.007737245144532784:\\
\;\;\;\;\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}:\\
\;\;\;\;\mathsf{fma}\left(\left(\frac{2}{\mathsf{expm1}\left(\left(-4 \cdot x\right)\right)}\right), \left(\mathsf{expm1}\left(\left(-2 \cdot x\right)\right)\right), -1\right)\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r2083044 = 2.0;
        double r2083045 = 1.0;
        double r2083046 = -2.0;
        double r2083047 = x;
        double r2083048 = r2083046 * r2083047;
        double r2083049 = exp(r2083048);
        double r2083050 = r2083045 + r2083049;
        double r2083051 = r2083044 / r2083050;
        double r2083052 = r2083051 - r2083045;
        return r2083052;
}

double f(double x, double __attribute__((unused)) y) {
        double r2083053 = x;
        double r2083054 = -0.005906231757156013;
        bool r2083055 = r2083053 <= r2083054;
        double r2083056 = 2.0;
        double r2083057 = 1.0;
        double r2083058 = -2.0;
        double r2083059 = r2083058 * r2083053;
        double r2083060 = exp(r2083059);
        double r2083061 = r2083057 + r2083060;
        double r2083062 = r2083056 / r2083061;
        double r2083063 = r2083062 - r2083057;
        double r2083064 = 0.007737245144532784;
        bool r2083065 = r2083053 <= r2083064;
        double r2083066 = r2083053 * r2083053;
        double r2083067 = r2083066 * r2083053;
        double r2083068 = -0.3333333333333333;
        double r2083069 = 5.0;
        double r2083070 = pow(r2083053, r2083069);
        double r2083071 = 0.13333333333333333;
        double r2083072 = fma(r2083070, r2083071, r2083053);
        double r2083073 = fma(r2083067, r2083068, r2083072);
        double r2083074 = -4.0;
        double r2083075 = r2083074 * r2083053;
        double r2083076 = expm1(r2083075);
        double r2083077 = r2083056 / r2083076;
        double r2083078 = expm1(r2083059);
        double r2083079 = -1.0;
        double r2083080 = fma(r2083077, r2083078, r2083079);
        double r2083081 = r2083065 ? r2083073 : r2083080;
        double r2083082 = r2083055 ? r2083063 : r2083081;
        return r2083082;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 3 regimes
  2. if x < -0.005906231757156013

    1. Initial program 0.0

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

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

    if -0.005906231757156013 < x < 0.007737245144532784

    1. Initial program 58.9

      \[\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)}\]

    if 0.007737245144532784 < x

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\frac{2}{e^{-2 \cdot x} + 1}} - 1\]
    3. Using strategy rm
    4. Applied *-un-lft-identity0.0

      \[\leadsto \frac{2}{e^{-2 \cdot x} + 1} - \color{blue}{1 \cdot 1}\]
    5. Applied flip-+0.0

      \[\leadsto \frac{2}{\color{blue}{\frac{e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot 1}{e^{-2 \cdot x} - 1}}} - 1 \cdot 1\]
    6. Applied associate-/r/0.0

      \[\leadsto \color{blue}{\frac{2}{e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot 1} \cdot \left(e^{-2 \cdot x} - 1\right)} - 1 \cdot 1\]
    7. Applied prod-diff0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(\frac{2}{e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot 1}\right), \left(e^{-2 \cdot x} - 1\right), \left(-1 \cdot 1\right)\right) + \mathsf{fma}\left(\left(-1\right), 1, \left(1 \cdot 1\right)\right)}\]
    8. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(\frac{2}{\mathsf{expm1}\left(\left(x \cdot -4\right)\right)}\right), \left(\mathsf{expm1}\left(\left(x \cdot -2\right)\right)\right), -1\right)} + \mathsf{fma}\left(\left(-1\right), 1, \left(1 \cdot 1\right)\right)\]
    9. Simplified0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.005906231757156013:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{elif}\;x \le 0.007737245144532784:\\ \;\;\;\;\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}:\\ \;\;\;\;\mathsf{fma}\left(\left(\frac{2}{\mathsf{expm1}\left(\left(-4 \cdot x\right)\right)}\right), \left(\mathsf{expm1}\left(\left(-2 \cdot x\right)\right)\right), -1\right)\\ \end{array}\]

Reproduce

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