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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r78018 = 2.0;
        double r78019 = 1.0;
        double r78020 = -2.0;
        double r78021 = x;
        double r78022 = r78020 * r78021;
        double r78023 = exp(r78022);
        double r78024 = r78019 + r78023;
        double r78025 = r78018 / r78024;
        double r78026 = r78025 - r78019;
        return r78026;
}

double f(double x, double __attribute__((unused)) y) {
        double r78027 = -2.0;
        double r78028 = x;
        double r78029 = r78027 * r78028;
        double r78030 = -18.229884751745807;
        bool r78031 = r78029 <= r78030;
        double r78032 = 0.0009548568372105134;
        bool r78033 = r78029 <= r78032;
        double r78034 = !r78033;
        bool r78035 = r78031 || r78034;
        double r78036 = 2.0;
        double r78037 = 1.0;
        double r78038 = exp(r78029);
        double r78039 = r78037 + r78038;
        double r78040 = r78036 / r78039;
        double r78041 = r78040 - r78037;
        double r78042 = 5.551115123125783e-17;
        double r78043 = 4.0;
        double r78044 = pow(r78028, r78043);
        double r78045 = 0.33333333333333337;
        double r78046 = 3.0;
        double r78047 = pow(r78028, r78046);
        double r78048 = r78045 * r78047;
        double r78049 = fma(r78042, r78044, r78048);
        double r78050 = -r78049;
        double r78051 = fma(r78037, r78028, r78050);
        double r78052 = r78035 ? r78041 : r78051;
        return r78052;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0.0

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

    if -18.229884751745807 < (* -2.0 x) < 0.0009548568372105134

    1. Initial program 59.0

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \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 -18.22988475174580713655814179219305515289 \lor \neg \left(-2 \cdot x \le 9.548568372105133931354581378059265261982 \cdot 10^{-4}\right):\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\right)\\ \end{array}\]

Reproduce

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