Average Error: 28.5 → 0.1
Time: 2.7s
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):\\ \;\;\;\;1 \cdot \frac{2}{1 + e^{-2 \cdot x}} - 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 -18.22988475174580713655814179219305515289 \lor \neg \left(-2 \cdot x \le 9.548568372105133931354581378059265261982 \cdot 10^{-4}\right):\\
\;\;\;\;1 \cdot \frac{2}{1 + e^{-2 \cdot x}} - 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 r37452 = 2.0;
        double r37453 = 1.0;
        double r37454 = -2.0;
        double r37455 = x;
        double r37456 = r37454 * r37455;
        double r37457 = exp(r37456);
        double r37458 = r37453 + r37457;
        double r37459 = r37452 / r37458;
        double r37460 = r37459 - r37453;
        return r37460;
}

double f(double x, double __attribute__((unused)) y) {
        double r37461 = -2.0;
        double r37462 = x;
        double r37463 = r37461 * r37462;
        double r37464 = -18.229884751745807;
        bool r37465 = r37463 <= r37464;
        double r37466 = 0.0009548568372105134;
        bool r37467 = r37463 <= r37466;
        double r37468 = !r37467;
        bool r37469 = r37465 || r37468;
        double r37470 = 1.0;
        double r37471 = 2.0;
        double r37472 = 1.0;
        double r37473 = exp(r37463);
        double r37474 = r37472 + r37473;
        double r37475 = r37471 / r37474;
        double r37476 = r37470 * r37475;
        double r37477 = r37476 - r37472;
        double r37478 = r37472 * r37462;
        double r37479 = 5.551115123125783e-17;
        double r37480 = 4.0;
        double r37481 = pow(r37462, r37480);
        double r37482 = r37479 * r37481;
        double r37483 = 0.33333333333333337;
        double r37484 = 3.0;
        double r37485 = pow(r37462, r37484);
        double r37486 = r37483 * r37485;
        double r37487 = r37482 + r37486;
        double r37488 = r37478 - r37487;
        double r37489 = r37469 ? r37477 : r37488;
        return r37489;
}

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) < -18.229884751745807 or 0.0009548568372105134 < (* -2.0 x)

    1. Initial program 0.0

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied *-un-lft-identity0.0

      \[\leadsto \color{blue}{1 \cdot \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. 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):\\ \;\;\;\;1 \cdot \frac{2}{1 + e^{-2 \cdot x}} - 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 2020002 
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  :precision binary64
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))