Average Error: 29.7 → 0.4
Time: 4.8s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -752988.461633870495 \lor \neg \left(-2 \cdot x \le 7.72586376053557345 \cdot 10^{-4}\right):\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 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 -752988.461633870495 \lor \neg \left(-2 \cdot x \le 7.72586376053557345 \cdot 10^{-4}\right):\\
\;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 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 r62183 = 2.0;
        double r62184 = 1.0;
        double r62185 = -2.0;
        double r62186 = x;
        double r62187 = r62185 * r62186;
        double r62188 = exp(r62187);
        double r62189 = r62184 + r62188;
        double r62190 = r62183 / r62189;
        double r62191 = r62190 - r62184;
        return r62191;
}

double f(double x, double __attribute__((unused)) y) {
        double r62192 = -2.0;
        double r62193 = x;
        double r62194 = r62192 * r62193;
        double r62195 = -752988.4616338705;
        bool r62196 = r62194 <= r62195;
        double r62197 = 0.0007725863760535573;
        bool r62198 = r62194 <= r62197;
        double r62199 = !r62198;
        bool r62200 = r62196 || r62199;
        double r62201 = 2.0;
        double r62202 = 1.0;
        double r62203 = exp(r62194);
        double r62204 = r62202 + r62203;
        double r62205 = sqrt(r62204);
        double r62206 = r62201 / r62205;
        double r62207 = r62206 / r62205;
        double r62208 = r62207 - r62202;
        double r62209 = 5.551115123125783e-17;
        double r62210 = 4.0;
        double r62211 = pow(r62193, r62210);
        double r62212 = 0.33333333333333337;
        double r62213 = 3.0;
        double r62214 = pow(r62193, r62213);
        double r62215 = r62212 * r62214;
        double r62216 = fma(r62209, r62211, r62215);
        double r62217 = -r62216;
        double r62218 = fma(r62202, r62193, r62217);
        double r62219 = r62200 ? r62208 : r62218;
        return r62219;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0.0

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

      \[\leadsto \frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    4. Applied associate-/r*0.0

      \[\leadsto \color{blue}{\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}}} - 1\]

    if -752988.4616338705 < (* -2.0 x) < 0.0007725863760535573

    1. Initial program 58.4

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

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

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

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