Average Error: 29.1 → 0.4
Time: 3.4s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -14207516.1141591389 \lor \neg \left(-2 \cdot x \le 3.6425271859424674 \cdot 10^{-6}\right):\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\ \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 -14207516.1141591389 \lor \neg \left(-2 \cdot x \le 3.6425271859424674 \cdot 10^{-6}\right):\\
\;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\

\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 r47655 = 2.0;
        double r47656 = 1.0;
        double r47657 = -2.0;
        double r47658 = x;
        double r47659 = r47657 * r47658;
        double r47660 = exp(r47659);
        double r47661 = r47656 + r47660;
        double r47662 = r47655 / r47661;
        double r47663 = r47662 - r47656;
        return r47663;
}

double f(double x, double __attribute__((unused)) y) {
        double r47664 = -2.0;
        double r47665 = x;
        double r47666 = r47664 * r47665;
        double r47667 = -14207516.114159139;
        bool r47668 = r47666 <= r47667;
        double r47669 = 3.6425271859424674e-06;
        bool r47670 = r47666 <= r47669;
        double r47671 = !r47670;
        bool r47672 = r47668 || r47671;
        double r47673 = 2.0;
        double r47674 = 1.0;
        double r47675 = exp(r47666);
        double r47676 = r47674 + r47675;
        double r47677 = sqrt(r47676);
        double r47678 = r47673 / r47677;
        double r47679 = r47678 / r47677;
        double r47680 = r47679 - r47674;
        double r47681 = r47674 * r47665;
        double r47682 = 5.551115123125783e-17;
        double r47683 = 4.0;
        double r47684 = pow(r47665, r47683);
        double r47685 = r47682 * r47684;
        double r47686 = 0.33333333333333337;
        double r47687 = 3.0;
        double r47688 = pow(r47665, r47687);
        double r47689 = r47686 * r47688;
        double r47690 = r47685 + r47689;
        double r47691 = r47681 - r47690;
        double r47692 = r47672 ? r47680 : r47691;
        return r47692;
}

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) < -14207516.114159139 or 3.6425271859424674e-06 < (* -2.0 x)

    1. Initial program 0.1

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

      \[\leadsto \frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    4. Applied associate-/r*0.1

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

    if -14207516.114159139 < (* -2.0 x) < 3.6425271859424674e-06

    1. Initial program 58.3

      \[\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 -14207516.1141591389 \lor \neg \left(-2 \cdot x \le 3.6425271859424674 \cdot 10^{-6}\right):\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\ \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 2020060 
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  :precision binary64
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))