Average Error: 29.3 → 0.2
Time: 14.5s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -107280.0323081880924291908740997314453125:\\ \;\;\;\;\frac{\frac{2}{\sqrt{e^{-2 \cdot x} + 1}}}{\sqrt{e^{-2 \cdot x} + 1}} - 1\\ \mathbf{elif}\;-2 \cdot x \le 9.922166503853619421490067642466215147579 \cdot 10^{-5}:\\ \;\;\;\;1 \cdot x - \left(x \cdot x\right) \cdot \left(0.3333333333333333703407674875052180141211 \cdot x + \left(x \cdot x\right) \cdot 5.5511151231257827021181583404541015625 \cdot 10^{-17}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{\sqrt{e^{-2 \cdot x} + 1}}}{\sqrt{e^{-2 \cdot x} + 1}} - 1\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -107280.0323081880924291908740997314453125:\\
\;\;\;\;\frac{\frac{2}{\sqrt{e^{-2 \cdot x} + 1}}}{\sqrt{e^{-2 \cdot x} + 1}} - 1\\

\mathbf{elif}\;-2 \cdot x \le 9.922166503853619421490067642466215147579 \cdot 10^{-5}:\\
\;\;\;\;1 \cdot x - \left(x \cdot x\right) \cdot \left(0.3333333333333333703407674875052180141211 \cdot x + \left(x \cdot x\right) \cdot 5.5511151231257827021181583404541015625 \cdot 10^{-17}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{\sqrt{e^{-2 \cdot x} + 1}}}{\sqrt{e^{-2 \cdot x} + 1}} - 1\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r2114686 = 2.0;
        double r2114687 = 1.0;
        double r2114688 = -2.0;
        double r2114689 = x;
        double r2114690 = r2114688 * r2114689;
        double r2114691 = exp(r2114690);
        double r2114692 = r2114687 + r2114691;
        double r2114693 = r2114686 / r2114692;
        double r2114694 = r2114693 - r2114687;
        return r2114694;
}

double f(double x, double __attribute__((unused)) y) {
        double r2114695 = -2.0;
        double r2114696 = x;
        double r2114697 = r2114695 * r2114696;
        double r2114698 = -107280.03230818809;
        bool r2114699 = r2114697 <= r2114698;
        double r2114700 = 2.0;
        double r2114701 = exp(r2114697);
        double r2114702 = 1.0;
        double r2114703 = r2114701 + r2114702;
        double r2114704 = sqrt(r2114703);
        double r2114705 = r2114700 / r2114704;
        double r2114706 = r2114705 / r2114704;
        double r2114707 = r2114706 - r2114702;
        double r2114708 = 9.92216650385362e-05;
        bool r2114709 = r2114697 <= r2114708;
        double r2114710 = r2114702 * r2114696;
        double r2114711 = r2114696 * r2114696;
        double r2114712 = 0.33333333333333337;
        double r2114713 = r2114712 * r2114696;
        double r2114714 = 5.551115123125783e-17;
        double r2114715 = r2114711 * r2114714;
        double r2114716 = r2114713 + r2114715;
        double r2114717 = r2114711 * r2114716;
        double r2114718 = r2114710 - r2114717;
        double r2114719 = r2114709 ? r2114718 : r2114707;
        double r2114720 = r2114699 ? r2114707 : r2114719;
        return r2114720;
}

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) < -107280.03230818809 or 9.92216650385362e-05 < (* -2.0 x)

    1. Initial program 0.0

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

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

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

    if -107280.03230818809 < (* -2.0 x) < 9.92216650385362e-05

    1. Initial program 58.9

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

      \[\leadsto \color{blue}{1 \cdot x - \left(0.3333333333333333703407674875052180141211 \cdot {x}^{3} + 5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4}\right)}\]
    3. Simplified0.4

      \[\leadsto \color{blue}{x \cdot 1 - \left(x \cdot x\right) \cdot \left(0.3333333333333333703407674875052180141211 \cdot x + 5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot \left(x \cdot x\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -107280.0323081880924291908740997314453125:\\ \;\;\;\;\frac{\frac{2}{\sqrt{e^{-2 \cdot x} + 1}}}{\sqrt{e^{-2 \cdot x} + 1}} - 1\\ \mathbf{elif}\;-2 \cdot x \le 9.922166503853619421490067642466215147579 \cdot 10^{-5}:\\ \;\;\;\;1 \cdot x - \left(x \cdot x\right) \cdot \left(0.3333333333333333703407674875052180141211 \cdot x + \left(x \cdot x\right) \cdot 5.5511151231257827021181583404541015625 \cdot 10^{-17}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{\sqrt{e^{-2 \cdot x} + 1}}}{\sqrt{e^{-2 \cdot x} + 1}} - 1\\ \end{array}\]

Reproduce

herbie shell --seed 2019171 
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))