Average Error: 29.1 → 0.2
Time: 3.0s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.131451077507048347 \lor \neg \left(-2 \cdot x \le 5.1372741302039926 \cdot 10^{-14}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \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.131451077507048347 \lor \neg \left(-2 \cdot x \le 5.1372741302039926 \cdot 10^{-14}\right):\\
\;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r48109 = 2.0;
        double r48110 = 1.0;
        double r48111 = -2.0;
        double r48112 = x;
        double r48113 = r48111 * r48112;
        double r48114 = exp(r48113);
        double r48115 = r48110 + r48114;
        double r48116 = r48109 / r48115;
        double r48117 = r48116 - r48110;
        return r48117;
}

double f(double x, double __attribute__((unused)) y) {
        double r48118 = -2.0;
        double r48119 = x;
        double r48120 = r48118 * r48119;
        double r48121 = -0.13145107750704835;
        bool r48122 = r48120 <= r48121;
        double r48123 = 5.1372741302039926e-14;
        bool r48124 = r48120 <= r48123;
        double r48125 = !r48124;
        bool r48126 = r48122 || r48125;
        double r48127 = 2.0;
        double r48128 = 1.0;
        double r48129 = exp(r48120);
        double r48130 = r48128 + r48129;
        double r48131 = r48127 / r48130;
        double r48132 = r48131 - r48128;
        double r48133 = exp(r48132);
        double r48134 = log(r48133);
        double r48135 = 5.551115123125783e-17;
        double r48136 = 4.0;
        double r48137 = pow(r48119, r48136);
        double r48138 = 0.33333333333333337;
        double r48139 = 3.0;
        double r48140 = pow(r48119, r48139);
        double r48141 = r48138 * r48140;
        double r48142 = fma(r48135, r48137, r48141);
        double r48143 = -r48142;
        double r48144 = fma(r48128, r48119, r48143);
        double r48145 = r48126 ? r48134 : r48144;
        return r48145;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -0.13145107750704835 or 5.1372741302039926e-14 < (* -2.0 x)

    1. Initial program 0.4

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied add-log-exp0.4

      \[\leadsto \frac{2}{1 + e^{-2 \cdot x}} - \color{blue}{\log \left(e^{1}\right)}\]
    4. Applied add-log-exp0.4

      \[\leadsto \color{blue}{\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right)} - \log \left(e^{1}\right)\]
    5. Applied diff-log0.4

      \[\leadsto \color{blue}{\log \left(\frac{e^{\frac{2}{1 + e^{-2 \cdot x}}}}{e^{1}}\right)}\]
    6. Simplified0.4

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

    if -0.13145107750704835 < (* -2.0 x) < 5.1372741302039926e-14

    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.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)}\]
    3. Simplified0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.131451077507048347 \lor \neg \left(-2 \cdot x \le 5.1372741302039926 \cdot 10^{-14}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\ \end{array}\]

Reproduce

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