Average Error: 29.0 → 0.2
Time: 2.6s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -220.3193758652155054278409807011485099792 \lor \neg \left(-2 \cdot x \le 3.564166708824457449394582098101125211542 \cdot 10^{-6}\right):\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {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 -220.3193758652155054278409807011485099792 \lor \neg \left(-2 \cdot x \le 3.564166708824457449394582098101125211542 \cdot 10^{-6}\right):\\
\;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r45253 = 2.0;
        double r45254 = 1.0;
        double r45255 = -2.0;
        double r45256 = x;
        double r45257 = r45255 * r45256;
        double r45258 = exp(r45257);
        double r45259 = r45254 + r45258;
        double r45260 = r45253 / r45259;
        double r45261 = r45260 - r45254;
        return r45261;
}

double f(double x, double __attribute__((unused)) y) {
        double r45262 = -2.0;
        double r45263 = x;
        double r45264 = r45262 * r45263;
        double r45265 = -220.3193758652155;
        bool r45266 = r45264 <= r45265;
        double r45267 = 3.5641667088244574e-06;
        bool r45268 = r45264 <= r45267;
        double r45269 = !r45268;
        bool r45270 = r45266 || r45269;
        double r45271 = 2.0;
        double r45272 = exp(r45264);
        double r45273 = 1.0;
        double r45274 = r45272 + r45273;
        double r45275 = r45271 / r45274;
        double r45276 = r45275 - r45273;
        double r45277 = r45273 * r45263;
        double r45278 = 5.551115123125783e-17;
        double r45279 = 4.0;
        double r45280 = pow(r45263, r45279);
        double r45281 = r45278 * r45280;
        double r45282 = 0.33333333333333337;
        double r45283 = 3.0;
        double r45284 = pow(r45263, r45283);
        double r45285 = r45282 * r45284;
        double r45286 = r45281 + r45285;
        double r45287 = r45277 - r45286;
        double r45288 = r45270 ? r45276 : r45287;
        return r45288;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

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

    1. Initial program 0.1

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

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

    if -220.3193758652155 < (* -2.0 x) < 3.5641667088244574e-06

    1. Initial program 58.9

      \[\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. Recombined 2 regimes into one program.
  4. Final simplification0.2

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

Reproduce

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