Average Error: 29.0 → 0.1
Time: 11.5s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.16694293117624887 \lor \neg \left(-2 \cdot x \le 1.3471487435038969 \cdot 10^{-8}\right):\\ \;\;\;\;\left(\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1\right) \cdot \frac{1}{\frac{2}{1 + e^{-2 \cdot x}} + 1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(4.996 \cdot 10^{-16}, {x}^{4}, 0.33333333333333348 \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.16694293117624887 \lor \neg \left(-2 \cdot x \le 1.3471487435038969 \cdot 10^{-8}\right):\\
\;\;\;\;\left(\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1\right) \cdot \frac{1}{\frac{2}{1 + e^{-2 \cdot x}} + 1}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(4.996 \cdot 10^{-16}, {x}^{4}, 0.33333333333333348 \cdot {x}^{3}\right)\right)\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r74920 = 2.0;
        double r74921 = 1.0;
        double r74922 = -2.0;
        double r74923 = x;
        double r74924 = r74922 * r74923;
        double r74925 = exp(r74924);
        double r74926 = r74921 + r74925;
        double r74927 = r74920 / r74926;
        double r74928 = r74927 - r74921;
        return r74928;
}

double f(double x, double __attribute__((unused)) y) {
        double r74929 = -2.0;
        double r74930 = x;
        double r74931 = r74929 * r74930;
        double r74932 = -0.16694293117624887;
        bool r74933 = r74931 <= r74932;
        double r74934 = 1.3471487435038969e-08;
        bool r74935 = r74931 <= r74934;
        double r74936 = !r74935;
        bool r74937 = r74933 || r74936;
        double r74938 = 2.0;
        double r74939 = 1.0;
        double r74940 = exp(r74931);
        double r74941 = r74939 + r74940;
        double r74942 = r74938 / r74941;
        double r74943 = r74942 * r74942;
        double r74944 = r74939 * r74939;
        double r74945 = r74943 - r74944;
        double r74946 = 1.0;
        double r74947 = r74942 + r74939;
        double r74948 = r74946 / r74947;
        double r74949 = r74945 * r74948;
        double r74950 = 4.996003610813204e-16;
        double r74951 = 4.0;
        double r74952 = pow(r74930, r74951);
        double r74953 = 0.3333333333333335;
        double r74954 = 3.0;
        double r74955 = pow(r74930, r74954);
        double r74956 = r74953 * r74955;
        double r74957 = fma(r74950, r74952, r74956);
        double r74958 = -r74957;
        double r74959 = fma(r74939, r74930, r74958);
        double r74960 = r74937 ? r74949 : r74959;
        return r74960;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0.2

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

      \[\leadsto \color{blue}{\frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\frac{2}{1 + e^{-2 \cdot x}} + 1}}\]
    4. Using strategy rm
    5. Applied div-inv0.2

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

    if -0.16694293117624887 < (* -2.0 x) < 1.3471487435038969e-08

    1. Initial program 59.4

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

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

      \[\leadsto \color{blue}{1 \cdot x - \left(4.996 \cdot 10^{-16} \cdot {x}^{4} + 0.33333333333333348 \cdot {x}^{3}\right)}\]
    5. Simplified0.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, x, -\mathsf{fma}\left(4.996 \cdot 10^{-16}, {x}^{4}, 0.33333333333333348 \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.16694293117624887 \lor \neg \left(-2 \cdot x \le 1.3471487435038969 \cdot 10^{-8}\right):\\ \;\;\;\;\left(\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1\right) \cdot \frac{1}{\frac{2}{1 + e^{-2 \cdot x}} + 1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(4.996 \cdot 10^{-16}, {x}^{4}, 0.33333333333333348 \cdot {x}^{3}\right)\right)\\ \end{array}\]

Reproduce

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