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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r37046 = 2.0;
        double r37047 = 1.0;
        double r37048 = -2.0;
        double r37049 = x;
        double r37050 = r37048 * r37049;
        double r37051 = exp(r37050);
        double r37052 = r37047 + r37051;
        double r37053 = r37046 / r37052;
        double r37054 = r37053 - r37047;
        return r37054;
}

double f(double x, double __attribute__((unused)) y) {
        double r37055 = -2.0;
        double r37056 = x;
        double r37057 = r37055 * r37056;
        double r37058 = -10.591343368072506;
        bool r37059 = r37057 <= r37058;
        double r37060 = 0.00024327647890187443;
        bool r37061 = r37057 <= r37060;
        double r37062 = !r37061;
        bool r37063 = r37059 || r37062;
        double r37064 = 2.0;
        double r37065 = 1.0;
        double r37066 = exp(r37057);
        double r37067 = r37065 + r37066;
        double r37068 = r37064 / r37067;
        double r37069 = 3.0;
        double r37070 = pow(r37068, r37069);
        double r37071 = cbrt(r37070);
        double r37072 = r37071 - r37065;
        double r37073 = r37065 * r37056;
        double r37074 = 5.551115123125783e-17;
        double r37075 = 4.0;
        double r37076 = pow(r37056, r37075);
        double r37077 = 0.33333333333333337;
        double r37078 = pow(r37056, r37069);
        double r37079 = r37077 * r37078;
        double r37080 = fma(r37074, r37076, r37079);
        double r37081 = r37073 - r37080;
        double r37082 = r37063 ? r37072 : r37081;
        return r37082;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0.0

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

      \[\leadsto \frac{2}{\color{blue}{\sqrt[3]{\left(\left(1 + e^{-2 \cdot x}\right) \cdot \left(1 + e^{-2 \cdot x}\right)\right) \cdot \left(1 + e^{-2 \cdot x}\right)}}} - 1\]
    4. Applied add-cbrt-cube0.0

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(2 \cdot 2\right) \cdot 2}}}{\sqrt[3]{\left(\left(1 + e^{-2 \cdot x}\right) \cdot \left(1 + e^{-2 \cdot x}\right)\right) \cdot \left(1 + e^{-2 \cdot x}\right)}} - 1\]
    5. Applied cbrt-undiv0.0

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

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

    if -10.591343368072506 < (* -2.0 x) < 0.00024327647890187443

    1. Initial program 59.0

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

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

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

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

Reproduce

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