Average Error: 29.2 → 0.3
Time: 17.8s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -7479.799764354564103996381163597106933594 \lor \neg \left(-2 \cdot x \le 8.70697753800674634828830743637595283857 \cdot 10^{-11}\right):\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 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 -7479.799764354564103996381163597106933594 \lor \neg \left(-2 \cdot x \le 8.70697753800674634828830743637595283857 \cdot 10^{-11}\right):\\
\;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 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 r43031 = 2.0;
        double r43032 = 1.0;
        double r43033 = -2.0;
        double r43034 = x;
        double r43035 = r43033 * r43034;
        double r43036 = exp(r43035);
        double r43037 = r43032 + r43036;
        double r43038 = r43031 / r43037;
        double r43039 = r43038 - r43032;
        return r43039;
}

double f(double x, double __attribute__((unused)) y) {
        double r43040 = -2.0;
        double r43041 = x;
        double r43042 = r43040 * r43041;
        double r43043 = -7479.799764354564;
        bool r43044 = r43042 <= r43043;
        double r43045 = 8.706977538006746e-11;
        bool r43046 = r43042 <= r43045;
        double r43047 = !r43046;
        bool r43048 = r43044 || r43047;
        double r43049 = 2.0;
        double r43050 = 1.0;
        double r43051 = exp(r43042);
        double r43052 = r43050 + r43051;
        double r43053 = sqrt(r43052);
        double r43054 = r43049 / r43053;
        double r43055 = r43054 / r43053;
        double r43056 = r43055 - r43050;
        double r43057 = r43050 * r43041;
        double r43058 = 5.551115123125783e-17;
        double r43059 = 4.0;
        double r43060 = pow(r43041, r43059);
        double r43061 = 0.33333333333333337;
        double r43062 = 3.0;
        double r43063 = pow(r43041, r43062);
        double r43064 = r43061 * r43063;
        double r43065 = fma(r43058, r43060, r43064);
        double r43066 = r43057 - r43065;
        double r43067 = r43048 ? r43056 : r43066;
        return r43067;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -7479.799764354564 or 8.706977538006746e-11 < (* -2.0 x)

    1. Initial program 0.3

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

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

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

    if -7479.799764354564 < (* -2.0 x) < 8.706977538006746e-11

    1. Initial program 59.1

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

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

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

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