Average Error: 29.1 → 0.2
Time: 2.7s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.131451077507048347 \lor \neg \left(-2 \cdot x \le 5.1372741302039926 \cdot 10^{-14}\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 -0.131451077507048347 \lor \neg \left(-2 \cdot x \le 5.1372741302039926 \cdot 10^{-14}\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 r41667 = 2.0;
        double r41668 = 1.0;
        double r41669 = -2.0;
        double r41670 = x;
        double r41671 = r41669 * r41670;
        double r41672 = exp(r41671);
        double r41673 = r41668 + r41672;
        double r41674 = r41667 / r41673;
        double r41675 = r41674 - r41668;
        return r41675;
}

double f(double x, double __attribute__((unused)) y) {
        double r41676 = -2.0;
        double r41677 = x;
        double r41678 = r41676 * r41677;
        double r41679 = -0.13145107750704835;
        bool r41680 = r41678 <= r41679;
        double r41681 = 5.1372741302039926e-14;
        bool r41682 = r41678 <= r41681;
        double r41683 = !r41682;
        bool r41684 = r41680 || r41683;
        double r41685 = 2.0;
        double r41686 = 1.0;
        double r41687 = exp(r41678);
        double r41688 = r41686 + r41687;
        double r41689 = r41685 / r41688;
        double r41690 = r41689 - r41686;
        double r41691 = exp(r41690);
        double r41692 = log(r41691);
        double r41693 = r41686 * r41677;
        double r41694 = 5.551115123125783e-17;
        double r41695 = 4.0;
        double r41696 = pow(r41677, r41695);
        double r41697 = r41694 * r41696;
        double r41698 = 0.33333333333333337;
        double r41699 = 3.0;
        double r41700 = pow(r41677, r41699);
        double r41701 = r41698 * r41700;
        double r41702 = r41697 + r41701;
        double r41703 = r41693 - r41702;
        double r41704 = r41684 ? r41692 : r41703;
        return r41704;
}

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) < -0.13145107750704835 or 5.1372741302039926e-14 < (* -2.0 x)

    1. Initial program 0.4

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

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

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

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

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

    if -0.13145107750704835 < (* -2.0 x) < 5.1372741302039926e-14

    1. Initial program 59.5

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

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

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