Average Error: 29.1 → 0.4
Time: 4.4s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -14207516.1141591389 \lor \neg \left(-2 \cdot x \le 3.6425271859424674 \cdot 10^{-6}\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 -14207516.1141591389 \lor \neg \left(-2 \cdot x \le 3.6425271859424674 \cdot 10^{-6}\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 r54015 = 2.0;
        double r54016 = 1.0;
        double r54017 = -2.0;
        double r54018 = x;
        double r54019 = r54017 * r54018;
        double r54020 = exp(r54019);
        double r54021 = r54016 + r54020;
        double r54022 = r54015 / r54021;
        double r54023 = r54022 - r54016;
        return r54023;
}

double f(double x, double __attribute__((unused)) y) {
        double r54024 = -2.0;
        double r54025 = x;
        double r54026 = r54024 * r54025;
        double r54027 = -14207516.114159139;
        bool r54028 = r54026 <= r54027;
        double r54029 = 3.6425271859424674e-06;
        bool r54030 = r54026 <= r54029;
        double r54031 = !r54030;
        bool r54032 = r54028 || r54031;
        double r54033 = 2.0;
        double r54034 = 1.0;
        double r54035 = exp(r54026);
        double r54036 = r54034 + r54035;
        double r54037 = sqrt(r54036);
        double r54038 = r54033 / r54037;
        double r54039 = r54038 / r54037;
        double r54040 = r54039 - r54034;
        double r54041 = 5.551115123125783e-17;
        double r54042 = 4.0;
        double r54043 = pow(r54025, r54042);
        double r54044 = 0.33333333333333337;
        double r54045 = 3.0;
        double r54046 = pow(r54025, r54045);
        double r54047 = r54044 * r54046;
        double r54048 = fma(r54041, r54043, r54047);
        double r54049 = -r54048;
        double r54050 = fma(r54034, r54025, r54049);
        double r54051 = r54032 ? r54040 : r54050;
        return r54051;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -14207516.114159139 or 3.6425271859424674e-06 < (* -2.0 x)

    1. Initial program 0.1

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

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

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

    if -14207516.114159139 < (* -2.0 x) < 3.6425271859424674e-06

    1. Initial program 58.3

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

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

      \[\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 -14207516.1141591389 \lor \neg \left(-2 \cdot x \le 3.6425271859424674 \cdot 10^{-6}\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 2020060 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  :precision binary64
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))