Average Error: 29.6 → 1.3
Time: 20.0s
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 r36821 = 2.0;
        double r36822 = 1.0;
        double r36823 = -2.0;
        double r36824 = x;
        double r36825 = r36823 * r36824;
        double r36826 = exp(r36825);
        double r36827 = r36822 + r36826;
        double r36828 = r36821 / r36827;
        double r36829 = r36828 - r36822;
        return r36829;
}

double f(double x, double __attribute__((unused)) y) {
        double r36830 = -2.0;
        double r36831 = x;
        double r36832 = r36830 * r36831;
        double r36833 = -8.649846695646195e+23;
        bool r36834 = r36832 <= r36833;
        double r36835 = 4.6290328791112155e-08;
        bool r36836 = r36832 <= r36835;
        double r36837 = !r36836;
        bool r36838 = r36834 || r36837;
        double r36839 = 2.0;
        double r36840 = 1.0;
        double r36841 = exp(r36832);
        double r36842 = r36840 + r36841;
        double r36843 = r36839 / r36842;
        double r36844 = r36843 - r36840;
        double r36845 = log1p(r36844);
        double r36846 = expm1(r36845);
        double r36847 = r36840 * r36831;
        double r36848 = 5.551115123125783e-17;
        double r36849 = 4.0;
        double r36850 = pow(r36831, r36849);
        double r36851 = 0.33333333333333337;
        double r36852 = 3.0;
        double r36853 = pow(r36831, r36852);
        double r36854 = r36851 * r36853;
        double r36855 = fma(r36848, r36850, r36854);
        double r36856 = r36847 - r36855;
        double r36857 = r36838 ? r36846 : r36856;
        return r36857;
}

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