Average Error: 29.4 → 0.2
Time: 3.7s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -43.320057343176309 \lor \neg \left(-2 \cdot x \le 1.0366643272928921 \cdot 10^{-5}\right):\\ \;\;\;\;\log \left(\sqrt{e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}}\right) + \log \left(\sqrt{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 -43.320057343176309 \lor \neg \left(-2 \cdot x \le 1.0366643272928921 \cdot 10^{-5}\right):\\
\;\;\;\;\log \left(\sqrt{e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}}\right) + \log \left(\sqrt{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 r57521 = 2.0;
        double r57522 = 1.0;
        double r57523 = -2.0;
        double r57524 = x;
        double r57525 = r57523 * r57524;
        double r57526 = exp(r57525);
        double r57527 = r57522 + r57526;
        double r57528 = r57521 / r57527;
        double r57529 = r57528 - r57522;
        return r57529;
}

double f(double x, double __attribute__((unused)) y) {
        double r57530 = -2.0;
        double r57531 = x;
        double r57532 = r57530 * r57531;
        double r57533 = -43.32005734317631;
        bool r57534 = r57532 <= r57533;
        double r57535 = 1.0366643272928921e-05;
        bool r57536 = r57532 <= r57535;
        double r57537 = !r57536;
        bool r57538 = r57534 || r57537;
        double r57539 = 2.0;
        double r57540 = 1.0;
        double r57541 = exp(r57532);
        double r57542 = r57540 + r57541;
        double r57543 = r57539 / r57542;
        double r57544 = r57543 - r57540;
        double r57545 = exp(r57544);
        double r57546 = sqrt(r57545);
        double r57547 = log(r57546);
        double r57548 = r57547 + r57547;
        double r57549 = 5.551115123125783e-17;
        double r57550 = 4.0;
        double r57551 = pow(r57531, r57550);
        double r57552 = 0.33333333333333337;
        double r57553 = 3.0;
        double r57554 = pow(r57531, r57553);
        double r57555 = r57552 * r57554;
        double r57556 = fma(r57549, r57551, r57555);
        double r57557 = -r57556;
        double r57558 = fma(r57540, r57531, r57557);
        double r57559 = r57538 ? r57548 : r57558;
        return r57559;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -43.32005734317631 or 1.0366643272928921e-05 < (* -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.1

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

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

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

      \[\leadsto \log \color{blue}{\left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt0.1

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

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

    if -43.32005734317631 < (* -2.0 x) < 1.0366643272928921e-05

    1. Initial program 58.9

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

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

      \[\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 -43.320057343176309 \lor \neg \left(-2 \cdot x \le 1.0366643272928921 \cdot 10^{-5}\right):\\ \;\;\;\;\log \left(\sqrt{e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}}\right) + \log \left(\sqrt{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 2020062 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  :precision binary64
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))