Average Error: 29.1 → 0.1
Time: 3.4s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -3.0753079396749081 \lor \neg \left(-2 \cdot x \le 1.57433485675177446 \cdot 10^{-9}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{e^{-2 \cdot x} + 1}}\right) - 1\\ \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 -3.0753079396749081 \lor \neg \left(-2 \cdot x \le 1.57433485675177446 \cdot 10^{-9}\right):\\
\;\;\;\;\log \left(e^{\frac{2}{e^{-2 \cdot x} + 1}}\right) - 1\\

\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 r66527 = 2.0;
        double r66528 = 1.0;
        double r66529 = -2.0;
        double r66530 = x;
        double r66531 = r66529 * r66530;
        double r66532 = exp(r66531);
        double r66533 = r66528 + r66532;
        double r66534 = r66527 / r66533;
        double r66535 = r66534 - r66528;
        return r66535;
}

double f(double x, double __attribute__((unused)) y) {
        double r66536 = -2.0;
        double r66537 = x;
        double r66538 = r66536 * r66537;
        double r66539 = -3.075307939674908;
        bool r66540 = r66538 <= r66539;
        double r66541 = 1.5743348567517745e-09;
        bool r66542 = r66538 <= r66541;
        double r66543 = !r66542;
        bool r66544 = r66540 || r66543;
        double r66545 = 2.0;
        double r66546 = exp(r66538);
        double r66547 = 1.0;
        double r66548 = r66546 + r66547;
        double r66549 = r66545 / r66548;
        double r66550 = exp(r66549);
        double r66551 = log(r66550);
        double r66552 = r66551 - r66547;
        double r66553 = 5.551115123125783e-17;
        double r66554 = 4.0;
        double r66555 = pow(r66537, r66554);
        double r66556 = 0.33333333333333337;
        double r66557 = 3.0;
        double r66558 = pow(r66537, r66557);
        double r66559 = r66556 * r66558;
        double r66560 = fma(r66553, r66555, r66559);
        double r66561 = -r66560;
        double r66562 = fma(r66547, r66537, r66561);
        double r66563 = r66544 ? r66552 : r66562;
        return r66563;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -3.075307939674908 or 1.5743348567517745e-09 < (* -2.0 x)

    1. Initial program 0.1

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

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

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

    if -3.075307939674908 < (* -2.0 x) < 1.5743348567517745e-09

    1. Initial program 59.4

      \[\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.1

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