Average Error: 29.0 → 0.1
Time: 4.7s
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 r51972 = 2.0;
        double r51973 = 1.0;
        double r51974 = -2.0;
        double r51975 = x;
        double r51976 = r51974 * r51975;
        double r51977 = exp(r51976);
        double r51978 = r51973 + r51977;
        double r51979 = r51972 / r51978;
        double r51980 = r51979 - r51973;
        return r51980;
}

double f(double x, double __attribute__((unused)) y) {
        double r51981 = -2.0;
        double r51982 = x;
        double r51983 = r51981 * r51982;
        double r51984 = -0.16694293117624887;
        bool r51985 = r51983 <= r51984;
        double r51986 = 1.3471487435038969e-08;
        bool r51987 = r51983 <= r51986;
        double r51988 = !r51987;
        bool r51989 = r51985 || r51988;
        double r51990 = 2.0;
        double r51991 = 1.0;
        double r51992 = exp(r51983);
        double r51993 = r51991 + r51992;
        double r51994 = r51990 / r51993;
        double r51995 = r51994 * r51994;
        double r51996 = r51991 * r51991;
        double r51997 = r51995 - r51996;
        double r51998 = 1.0;
        double r51999 = r51994 + r51991;
        double r52000 = r51998 / r51999;
        double r52001 = r51997 * r52000;
        double r52002 = 4.996003610813204e-16;
        double r52003 = 4.0;
        double r52004 = pow(r51982, r52003);
        double r52005 = 0.3333333333333335;
        double r52006 = 3.0;
        double r52007 = pow(r51982, r52006);
        double r52008 = r52005 * r52007;
        double r52009 = fma(r52002, r52004, r52008);
        double r52010 = -r52009;
        double r52011 = fma(r51991, r51982, r52010);
        double r52012 = r51989 ? r52001 : r52011;
        return r52012;
}

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))