Average Error: 29.4 → 0.2
Time: 6.9s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.850333007111792715804199360718484967947 \lor \neg \left(-2 \cdot x \le 7.158249832607255782421567983942815014721 \cdot 10^{-12}\right):\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \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 -0.850333007111792715804199360718484967947 \lor \neg \left(-2 \cdot x \le 7.158249832607255782421567983942815014721 \cdot 10^{-12}\right):\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\

\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 r43815 = 2.0;
        double r43816 = 1.0;
        double r43817 = -2.0;
        double r43818 = x;
        double r43819 = r43817 * r43818;
        double r43820 = exp(r43819);
        double r43821 = r43816 + r43820;
        double r43822 = r43815 / r43821;
        double r43823 = r43822 - r43816;
        return r43823;
}

double f(double x, double __attribute__((unused)) y) {
        double r43824 = -2.0;
        double r43825 = x;
        double r43826 = r43824 * r43825;
        double r43827 = -0.8503330071117927;
        bool r43828 = r43826 <= r43827;
        double r43829 = 7.158249832607256e-12;
        bool r43830 = r43826 <= r43829;
        double r43831 = !r43830;
        bool r43832 = r43828 || r43831;
        double r43833 = 2.0;
        double r43834 = 1.0;
        double r43835 = exp(r43826);
        double r43836 = r43834 + r43835;
        double r43837 = r43833 / r43836;
        double r43838 = r43837 - r43834;
        double r43839 = r43834 * r43825;
        double r43840 = 5.551115123125783e-17;
        double r43841 = 4.0;
        double r43842 = pow(r43825, r43841);
        double r43843 = 0.33333333333333337;
        double r43844 = 3.0;
        double r43845 = pow(r43825, r43844);
        double r43846 = r43843 * r43845;
        double r43847 = fma(r43840, r43842, r43846);
        double r43848 = r43839 - r43847;
        double r43849 = r43832 ? r43838 : r43848;
        return r43849;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -0.8503330071117927 or 7.158249832607256e-12 < (* -2.0 x)

    1. Initial program 0.3

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]

    if -0.8503330071117927 < (* -2.0 x) < 7.158249832607256e-12

    1. Initial program 59.5

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

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

      \[\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 simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.850333007111792715804199360718484967947 \lor \neg \left(-2 \cdot x \le 7.158249832607255782421567983942815014721 \cdot 10^{-12}\right):\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \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 2019350 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  :precision binary64
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))