Average Error: 28.8 → 0.1
Time: 15.5s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -15.34827695076649511918276402866467833519 \lor \neg \left(-2 \cdot x \le 5.761922114541408743507155953977871831739 \cdot 10^{-4}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{e^{-2 \cdot x} + 1} - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 1, -\mathsf{fma}\left(0.3333333333333333703407674875052180141211, {x}^{3}, {x}^{4} \cdot 5.5511151231257827021181583404541015625 \cdot 10^{-17}\right)\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -15.34827695076649511918276402866467833519 \lor \neg \left(-2 \cdot x \le 5.761922114541408743507155953977871831739 \cdot 10^{-4}\right):\\
\;\;\;\;\log \left(e^{\frac{2}{e^{-2 \cdot x} + 1} - 1}\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r59601 = 2.0;
        double r59602 = 1.0;
        double r59603 = -2.0;
        double r59604 = x;
        double r59605 = r59603 * r59604;
        double r59606 = exp(r59605);
        double r59607 = r59602 + r59606;
        double r59608 = r59601 / r59607;
        double r59609 = r59608 - r59602;
        return r59609;
}

double f(double x, double __attribute__((unused)) y) {
        double r59610 = -2.0;
        double r59611 = x;
        double r59612 = r59610 * r59611;
        double r59613 = -15.348276950766495;
        bool r59614 = r59612 <= r59613;
        double r59615 = 0.0005761922114541409;
        bool r59616 = r59612 <= r59615;
        double r59617 = !r59616;
        bool r59618 = r59614 || r59617;
        double r59619 = 2.0;
        double r59620 = exp(r59612);
        double r59621 = 1.0;
        double r59622 = r59620 + r59621;
        double r59623 = r59619 / r59622;
        double r59624 = r59623 - r59621;
        double r59625 = exp(r59624);
        double r59626 = log(r59625);
        double r59627 = 0.33333333333333337;
        double r59628 = 3.0;
        double r59629 = pow(r59611, r59628);
        double r59630 = 4.0;
        double r59631 = pow(r59611, r59630);
        double r59632 = 5.551115123125783e-17;
        double r59633 = r59631 * r59632;
        double r59634 = fma(r59627, r59629, r59633);
        double r59635 = -r59634;
        double r59636 = fma(r59611, r59621, r59635);
        double r59637 = r59618 ? r59626 : r59636;
        return r59637;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -15.348276950766495 or 0.0005761922114541409 < (* -2.0 x)

    1. Initial program 0.0

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

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

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

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

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

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

    if -15.348276950766495 < (* -2.0 x) < 0.0005761922114541409

    1. Initial program 58.8

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

      \[\leadsto \color{blue}{\frac{2}{1 + {\left(e^{x}\right)}^{-2}} - 1}\]
    3. Taylor expanded around 0 0.3

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

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

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

Reproduce

herbie shell --seed 2019179 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))