Average Error: 28.9 → 0.1
Time: 19.2s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.2905948704643001034853000419388990849257:\\ \;\;\;\;\frac{\frac{2}{e^{-2 \cdot x} + 1} \cdot \frac{2}{e^{-2 \cdot x} + 1} - 1 \cdot 1}{1 + \frac{2}{e^{-2 \cdot x} + 1}}\\ \mathbf{elif}\;-2 \cdot x \le 1.627379555188875196866448791591097666753 \cdot 10^{-8}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(x \cdot \left(x \cdot x\right), 0.3333333333333333703407674875052180141211, 5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{e^{-2 \cdot x} + 1} \cdot \frac{2}{e^{-2 \cdot x} + 1} - 1 \cdot 1}{1 + \frac{2}{e^{-2 \cdot x} + 1}}\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.2905948704643001034853000419388990849257:\\
\;\;\;\;\frac{\frac{2}{e^{-2 \cdot x} + 1} \cdot \frac{2}{e^{-2 \cdot x} + 1} - 1 \cdot 1}{1 + \frac{2}{e^{-2 \cdot x} + 1}}\\

\mathbf{elif}\;-2 \cdot x \le 1.627379555188875196866448791591097666753 \cdot 10^{-8}:\\
\;\;\;\;1 \cdot x - \mathsf{fma}\left(x \cdot \left(x \cdot x\right), 0.3333333333333333703407674875052180141211, 5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{e^{-2 \cdot x} + 1} \cdot \frac{2}{e^{-2 \cdot x} + 1} - 1 \cdot 1}{1 + \frac{2}{e^{-2 \cdot x} + 1}}\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r2277032 = 2.0;
        double r2277033 = 1.0;
        double r2277034 = -2.0;
        double r2277035 = x;
        double r2277036 = r2277034 * r2277035;
        double r2277037 = exp(r2277036);
        double r2277038 = r2277033 + r2277037;
        double r2277039 = r2277032 / r2277038;
        double r2277040 = r2277039 - r2277033;
        return r2277040;
}

double f(double x, double __attribute__((unused)) y) {
        double r2277041 = -2.0;
        double r2277042 = x;
        double r2277043 = r2277041 * r2277042;
        double r2277044 = -0.2905948704643001;
        bool r2277045 = r2277043 <= r2277044;
        double r2277046 = 2.0;
        double r2277047 = exp(r2277043);
        double r2277048 = 1.0;
        double r2277049 = r2277047 + r2277048;
        double r2277050 = r2277046 / r2277049;
        double r2277051 = r2277050 * r2277050;
        double r2277052 = r2277048 * r2277048;
        double r2277053 = r2277051 - r2277052;
        double r2277054 = r2277048 + r2277050;
        double r2277055 = r2277053 / r2277054;
        double r2277056 = 1.6273795551888752e-08;
        bool r2277057 = r2277043 <= r2277056;
        double r2277058 = r2277048 * r2277042;
        double r2277059 = r2277042 * r2277042;
        double r2277060 = r2277042 * r2277059;
        double r2277061 = 0.33333333333333337;
        double r2277062 = 5.551115123125783e-17;
        double r2277063 = r2277059 * r2277059;
        double r2277064 = r2277062 * r2277063;
        double r2277065 = fma(r2277060, r2277061, r2277064);
        double r2277066 = r2277058 - r2277065;
        double r2277067 = r2277057 ? r2277066 : r2277055;
        double r2277068 = r2277045 ? r2277055 : r2277067;
        return r2277068;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -0.2905948704643001 or 1.6273795551888752e-08 < (* -2.0 x)

    1. Initial program 0.1

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

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

    if -0.2905948704643001 < (* -2.0 x) < 1.6273795551888752e-08

    1. Initial program 59.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.2905948704643001034853000419388990849257:\\ \;\;\;\;\frac{\frac{2}{e^{-2 \cdot x} + 1} \cdot \frac{2}{e^{-2 \cdot x} + 1} - 1 \cdot 1}{1 + \frac{2}{e^{-2 \cdot x} + 1}}\\ \mathbf{elif}\;-2 \cdot x \le 1.627379555188875196866448791591097666753 \cdot 10^{-8}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(x \cdot \left(x \cdot x\right), 0.3333333333333333703407674875052180141211, 5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{e^{-2 \cdot x} + 1} \cdot \frac{2}{e^{-2 \cdot x} + 1} - 1 \cdot 1}{1 + \frac{2}{e^{-2 \cdot x} + 1}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019170 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))