Average Error: 29.2 → 0.4
Time: 4.8s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -515526.411099167482 \lor \neg \left(-2 \cdot x \le 5.8825564052610111 \cdot 10^{-4}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -515526.411099167482 \lor \neg \left(-2 \cdot x \le 5.8825564052610111 \cdot 10^{-4}\right):\\
\;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r53532 = 2.0;
        double r53533 = 1.0;
        double r53534 = -2.0;
        double r53535 = x;
        double r53536 = r53534 * r53535;
        double r53537 = exp(r53536);
        double r53538 = r53533 + r53537;
        double r53539 = r53532 / r53538;
        double r53540 = r53539 - r53533;
        return r53540;
}

double f(double x, double __attribute__((unused)) y) {
        double r53541 = -2.0;
        double r53542 = x;
        double r53543 = r53541 * r53542;
        double r53544 = -515526.4110991675;
        bool r53545 = r53543 <= r53544;
        double r53546 = 0.0005882556405261011;
        bool r53547 = r53543 <= r53546;
        double r53548 = !r53547;
        bool r53549 = r53545 || r53548;
        double r53550 = 2.0;
        double r53551 = 1.0;
        double r53552 = exp(r53543);
        double r53553 = r53551 + r53552;
        double r53554 = r53550 / r53553;
        double r53555 = r53554 - r53551;
        double r53556 = exp(r53555);
        double r53557 = log(r53556);
        double r53558 = r53551 * r53542;
        double r53559 = 5.551115123125783e-17;
        double r53560 = 4.0;
        double r53561 = pow(r53542, r53560);
        double r53562 = r53559 * r53561;
        double r53563 = 0.33333333333333337;
        double r53564 = 3.0;
        double r53565 = pow(r53542, r53564);
        double r53566 = r53563 * r53565;
        double r53567 = r53562 + r53566;
        double r53568 = r53558 - r53567;
        double r53569 = r53549 ? r53557 : r53568;
        return r53569;
}

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) < -515526.4110991675 or 0.0005882556405261011 < (* -2.0 x)

    1. Initial program 0.0

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

      \[\leadsto \frac{2}{1 + e^{-2 \cdot x}} - \color{blue}{\log \left(e^{1}\right)}\]
    4. Applied add-log-exp0.0

      \[\leadsto \color{blue}{\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right)} - \log \left(e^{1}\right)\]
    5. Applied diff-log0.0

      \[\leadsto \color{blue}{\log \left(\frac{e^{\frac{2}{1 + e^{-2 \cdot x}}}}{e^{1}}\right)}\]
    6. Simplified0.0

      \[\leadsto \log \color{blue}{\left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)}\]

    if -515526.4110991675 < (* -2.0 x) < 0.0005882556405261011

    1. Initial program 58.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -515526.411099167482 \lor \neg \left(-2 \cdot x \le 5.8825564052610111 \cdot 10^{-4}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)\\ \end{array}\]

Reproduce

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