Average Error: 29.6 → 1.3
Time: 31.3s
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 r39651 = 2.0;
        double r39652 = 1.0;
        double r39653 = -2.0;
        double r39654 = x;
        double r39655 = r39653 * r39654;
        double r39656 = exp(r39655);
        double r39657 = r39652 + r39656;
        double r39658 = r39651 / r39657;
        double r39659 = r39658 - r39652;
        return r39659;
}

double f(double x, double __attribute__((unused)) y) {
        double r39660 = -2.0;
        double r39661 = x;
        double r39662 = r39660 * r39661;
        double r39663 = -8.649846695646195e+23;
        bool r39664 = r39662 <= r39663;
        double r39665 = 4.6290328791112155e-08;
        bool r39666 = r39662 <= r39665;
        double r39667 = !r39666;
        bool r39668 = r39664 || r39667;
        double r39669 = 2.0;
        double r39670 = 1.0;
        double r39671 = exp(r39662);
        double r39672 = r39670 + r39671;
        double r39673 = r39669 / r39672;
        double r39674 = r39673 - r39670;
        double r39675 = log1p(r39674);
        double r39676 = expm1(r39675);
        double r39677 = r39670 * r39661;
        double r39678 = 5.551115123125783e-17;
        double r39679 = 4.0;
        double r39680 = pow(r39661, r39679);
        double r39681 = 0.33333333333333337;
        double r39682 = 3.0;
        double r39683 = pow(r39661, r39682);
        double r39684 = r39681 * r39683;
        double r39685 = fma(r39678, r39680, r39684);
        double r39686 = r39677 - r39685;
        double r39687 = r39668 ? r39676 : r39686;
        return r39687;
}

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