Average Error: 29.0 → 0.1
Time: 14.2s
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 r49281 = 2.0;
        double r49282 = 1.0;
        double r49283 = -2.0;
        double r49284 = x;
        double r49285 = r49283 * r49284;
        double r49286 = exp(r49285);
        double r49287 = r49282 + r49286;
        double r49288 = r49281 / r49287;
        double r49289 = r49288 - r49282;
        return r49289;
}

double f(double x, double __attribute__((unused)) y) {
        double r49290 = -2.0;
        double r49291 = x;
        double r49292 = r49290 * r49291;
        double r49293 = -0.16694293117624887;
        bool r49294 = r49292 <= r49293;
        double r49295 = 1.3471487435038969e-08;
        bool r49296 = r49292 <= r49295;
        double r49297 = !r49296;
        bool r49298 = r49294 || r49297;
        double r49299 = 2.0;
        double r49300 = 1.0;
        double r49301 = exp(r49292);
        double r49302 = r49300 + r49301;
        double r49303 = r49299 / r49302;
        double r49304 = r49303 * r49303;
        double r49305 = r49300 * r49300;
        double r49306 = r49304 - r49305;
        double r49307 = 1.0;
        double r49308 = r49303 + r49300;
        double r49309 = r49307 / r49308;
        double r49310 = r49306 * r49309;
        double r49311 = 4.996003610813204e-16;
        double r49312 = 4.0;
        double r49313 = pow(r49291, r49312);
        double r49314 = 0.3333333333333335;
        double r49315 = 3.0;
        double r49316 = pow(r49291, r49315);
        double r49317 = r49314 * r49316;
        double r49318 = fma(r49311, r49313, r49317);
        double r49319 = -r49318;
        double r49320 = fma(r49300, r49291, r49319);
        double r49321 = r49298 ? r49310 : r49320;
        return r49321;
}

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