Average Error: 29.8 → 0.2
Time: 26.8s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -7725.496628004181:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{elif}\;-2 \cdot x \le 0.0012862461380189684:\\ \;\;\;\;\mathsf{fma}\left(x \cdot \left(x \cdot x\right), \frac{-1}{3}, \mathsf{fma}\left({x}^{5}, \frac{2}{15}, 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 -7725.496628004181:\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r1852907 = 2.0;
        double r1852908 = 1.0;
        double r1852909 = -2.0;
        double r1852910 = x;
        double r1852911 = r1852909 * r1852910;
        double r1852912 = exp(r1852911);
        double r1852913 = r1852908 + r1852912;
        double r1852914 = r1852907 / r1852913;
        double r1852915 = r1852914 - r1852908;
        return r1852915;
}

double f(double x, double __attribute__((unused)) y) {
        double r1852916 = -2.0;
        double r1852917 = x;
        double r1852918 = r1852916 * r1852917;
        double r1852919 = -7725.496628004181;
        bool r1852920 = r1852918 <= r1852919;
        double r1852921 = 2.0;
        double r1852922 = 1.0;
        double r1852923 = exp(r1852918);
        double r1852924 = r1852922 + r1852923;
        double r1852925 = r1852921 / r1852924;
        double r1852926 = r1852925 - r1852922;
        double r1852927 = 0.0012862461380189684;
        bool r1852928 = r1852918 <= r1852927;
        double r1852929 = r1852917 * r1852917;
        double r1852930 = r1852917 * r1852929;
        double r1852931 = -0.3333333333333333;
        double r1852932 = 5.0;
        double r1852933 = pow(r1852917, r1852932);
        double r1852934 = 0.13333333333333333;
        double r1852935 = fma(r1852933, r1852934, r1852917);
        double r1852936 = fma(r1852930, r1852931, r1852935);
        double r1852937 = r1852928 ? r1852936 : r1852926;
        double r1852938 = r1852920 ? r1852926 : r1852937;
        return r1852938;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2 x) < -7725.496628004181 or 0.0012862461380189684 < (* -2 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\]

    if -7725.496628004181 < (* -2 x) < 0.0012862461380189684

    1. Initial program 58.9

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

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

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

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

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

Reproduce

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