Average Error: 29.4 → 0.3
Time: 10.7s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -1876086.774165026:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{elif}\;-2 \cdot x \le 7.940217460912 \cdot 10^{-07}:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{3}, x \cdot \left(x \cdot x\right), \mathsf{fma}\left(\frac{2}{15}, {x}^{5}, 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 -1876086.774165026:\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r640875 = 2.0;
        double r640876 = 1.0;
        double r640877 = -2.0;
        double r640878 = x;
        double r640879 = r640877 * r640878;
        double r640880 = exp(r640879);
        double r640881 = r640876 + r640880;
        double r640882 = r640875 / r640881;
        double r640883 = r640882 - r640876;
        return r640883;
}

double f(double x, double __attribute__((unused)) y) {
        double r640884 = -2.0;
        double r640885 = x;
        double r640886 = r640884 * r640885;
        double r640887 = -1876086.774165026;
        bool r640888 = r640886 <= r640887;
        double r640889 = 2.0;
        double r640890 = 1.0;
        double r640891 = exp(r640886);
        double r640892 = r640890 + r640891;
        double r640893 = r640889 / r640892;
        double r640894 = r640893 - r640890;
        double r640895 = 7.940217460912e-07;
        bool r640896 = r640886 <= r640895;
        double r640897 = -0.3333333333333333;
        double r640898 = r640885 * r640885;
        double r640899 = r640885 * r640898;
        double r640900 = 0.13333333333333333;
        double r640901 = 5.0;
        double r640902 = pow(r640885, r640901);
        double r640903 = fma(r640900, r640902, r640885);
        double r640904 = fma(r640897, r640899, r640903);
        double r640905 = r640896 ? r640904 : r640894;
        double r640906 = r640888 ? r640894 : r640905;
        return r640906;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2 x) < -1876086.774165026 or 7.940217460912e-07 < (* -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 -1876086.774165026 < (* -2 x) < 7.940217460912e-07

    1. Initial program 58.5

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

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

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

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

Reproduce

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