Average Error: 29.0 → 0.7
Time: 3.5s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -15476529172.2573032 \lor \neg \left(-2 \cdot x \le 1.11971615771184669 \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 -15476529172.2573032 \lor \neg \left(-2 \cdot x \le 1.11971615771184669 \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 r48598 = 2.0;
        double r48599 = 1.0;
        double r48600 = -2.0;
        double r48601 = x;
        double r48602 = r48600 * r48601;
        double r48603 = exp(r48602);
        double r48604 = r48599 + r48603;
        double r48605 = r48598 / r48604;
        double r48606 = r48605 - r48599;
        return r48606;
}

double f(double x, double __attribute__((unused)) y) {
        double r48607 = -2.0;
        double r48608 = x;
        double r48609 = r48607 * r48608;
        double r48610 = -15476529172.257303;
        bool r48611 = r48609 <= r48610;
        double r48612 = 0.00011197161577118467;
        bool r48613 = r48609 <= r48612;
        double r48614 = !r48613;
        bool r48615 = r48611 || r48614;
        double r48616 = 2.0;
        double r48617 = 1.0;
        double r48618 = exp(r48609);
        double r48619 = r48617 + r48618;
        double r48620 = r48616 / r48619;
        double r48621 = r48620 - r48617;
        double r48622 = exp(r48621);
        double r48623 = log(r48622);
        double r48624 = r48617 * r48608;
        double r48625 = 5.551115123125783e-17;
        double r48626 = 4.0;
        double r48627 = pow(r48608, r48626);
        double r48628 = r48625 * r48627;
        double r48629 = 0.33333333333333337;
        double r48630 = 3.0;
        double r48631 = pow(r48608, r48630);
        double r48632 = r48629 * r48631;
        double r48633 = r48628 + r48632;
        double r48634 = r48624 - r48633;
        double r48635 = r48615 ? r48623 : r48634;
        return r48635;
}

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) < -15476529172.257303 or 0.00011197161577118467 < (* -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 -15476529172.257303 < (* -2.0 x) < 0.00011197161577118467

    1. Initial program 57.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -15476529172.2573032 \lor \neg \left(-2 \cdot x \le 1.11971615771184669 \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 2020046 
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  :precision binary64
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))