Average Error: 29.6 → 1.3
Time: 20.6s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -864984669564619502649344 \lor \neg \left(-2 \cdot x \le 4.629032879111215459799953089899127167683 \cdot 10^{-8}\right):\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -864984669564619502649344 \lor \neg \left(-2 \cdot x \le 4.629032879111215459799953089899127167683 \cdot 10^{-8}\right):\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r35188 = 2.0;
        double r35189 = 1.0;
        double r35190 = -2.0;
        double r35191 = x;
        double r35192 = r35190 * r35191;
        double r35193 = exp(r35192);
        double r35194 = r35189 + r35193;
        double r35195 = r35188 / r35194;
        double r35196 = r35195 - r35189;
        return r35196;
}

double f(double x, double __attribute__((unused)) y) {
        double r35197 = -2.0;
        double r35198 = x;
        double r35199 = r35197 * r35198;
        double r35200 = -8.649846695646195e+23;
        bool r35201 = r35199 <= r35200;
        double r35202 = 4.6290328791112155e-08;
        bool r35203 = r35199 <= r35202;
        double r35204 = !r35203;
        bool r35205 = r35201 || r35204;
        double r35206 = 2.0;
        double r35207 = 1.0;
        double r35208 = exp(r35199);
        double r35209 = r35207 + r35208;
        double r35210 = r35206 / r35209;
        double r35211 = r35210 - r35207;
        double r35212 = log1p(r35211);
        double r35213 = expm1(r35212);
        double r35214 = r35207 * r35198;
        double r35215 = 5.551115123125783e-17;
        double r35216 = 4.0;
        double r35217 = pow(r35198, r35216);
        double r35218 = 0.33333333333333337;
        double r35219 = 3.0;
        double r35220 = pow(r35198, r35219);
        double r35221 = r35218 * r35220;
        double r35222 = fma(r35215, r35217, r35221);
        double r35223 = r35214 - r35222;
        double r35224 = r35205 ? r35213 : r35223;
        return r35224;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -8.649846695646195e+23 or 4.6290328791112155e-08 < (* -2.0 x)

    1. Initial program 0.1

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

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

    if -8.649846695646195e+23 < (* -2.0 x) < 4.6290328791112155e-08

    1. Initial program 57.2

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

      \[\leadsto \color{blue}{1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)}\]
    3. Simplified2.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -864984669564619502649344 \lor \neg \left(-2 \cdot x \le 4.629032879111215459799953089899127167683 \cdot 10^{-8}\right):\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \end{array}\]

Reproduce

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