Average Error: 29.2 → 0.1
Time: 3.8s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.51276026561008892 \lor \neg \left(-2 \cdot x \le 2.74394031375103407 \cdot 10^{-8}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.51276026561008892 \lor \neg \left(-2 \cdot x \le 2.74394031375103407 \cdot 10^{-8}\right):\\
\;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r54957 = 2.0;
        double r54958 = 1.0;
        double r54959 = -2.0;
        double r54960 = x;
        double r54961 = r54959 * r54960;
        double r54962 = exp(r54961);
        double r54963 = r54958 + r54962;
        double r54964 = r54957 / r54963;
        double r54965 = r54964 - r54958;
        return r54965;
}

double f(double x, double __attribute__((unused)) y) {
        double r54966 = -2.0;
        double r54967 = x;
        double r54968 = r54966 * r54967;
        double r54969 = -0.5127602656100889;
        bool r54970 = r54968 <= r54969;
        double r54971 = 2.743940313751034e-08;
        bool r54972 = r54968 <= r54971;
        double r54973 = !r54972;
        bool r54974 = r54970 || r54973;
        double r54975 = 2.0;
        double r54976 = 1.0;
        double r54977 = exp(r54968);
        double r54978 = r54976 + r54977;
        double r54979 = r54975 / r54978;
        double r54980 = r54979 - r54976;
        double r54981 = exp(r54980);
        double r54982 = log(r54981);
        double r54983 = 5.551115123125783e-17;
        double r54984 = 4.0;
        double r54985 = pow(r54967, r54984);
        double r54986 = 0.33333333333333337;
        double r54987 = 3.0;
        double r54988 = pow(r54967, r54987);
        double r54989 = r54986 * r54988;
        double r54990 = fma(r54983, r54985, r54989);
        double r54991 = -r54990;
        double r54992 = fma(r54976, r54967, r54991);
        double r54993 = r54974 ? r54982 : r54992;
        return r54993;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -0.5127602656100889 or 2.743940313751034e-08 < (* -2.0 x)

    1. Initial program 0.1

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied add-log-exp0.1

      \[\leadsto \frac{2}{1 + e^{-2 \cdot x}} - \color{blue}{\log \left(e^{1}\right)}\]
    4. Applied add-log-exp0.2

      \[\leadsto \color{blue}{\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right)} - \log \left(e^{1}\right)\]
    5. Applied diff-log0.1

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

      \[\leadsto \log \color{blue}{\left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)}\]

    if -0.5127602656100889 < (* -2.0 x) < 2.743940313751034e-08

    1. Initial program 59.4

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

      \[\leadsto \color{blue}{1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)}\]
    3. Simplified0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.51276026561008892 \lor \neg \left(-2 \cdot x \le 2.74394031375103407 \cdot 10^{-8}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\ \end{array}\]

Reproduce

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