Average Error: 29.1 → 0.1
Time: 15.2s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.008574052355382087:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{elif}\;-2 \cdot x \le 1.4278659301426067 \cdot 10^{-07}:\\ \;\;\;\;\left(x + \frac{2}{15} \cdot {x}^{5}\right) + \left(\left(x \cdot x\right) \cdot x\right) \cdot \frac{-1}{3}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{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 -0.008574052355382087:\\
\;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\

\mathbf{elif}\;-2 \cdot x \le 1.4278659301426067 \cdot 10^{-07}:\\
\;\;\;\;\left(x + \frac{2}{15} \cdot {x}^{5}\right) + \left(\left(x \cdot x\right) \cdot x\right) \cdot \frac{-1}{3}\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r807404 = 2.0;
        double r807405 = 1.0;
        double r807406 = -2.0;
        double r807407 = x;
        double r807408 = r807406 * r807407;
        double r807409 = exp(r807408);
        double r807410 = r807405 + r807409;
        double r807411 = r807404 / r807410;
        double r807412 = r807411 - r807405;
        return r807412;
}

double f(double x, double __attribute__((unused)) y) {
        double r807413 = -2.0;
        double r807414 = x;
        double r807415 = r807413 * r807414;
        double r807416 = -0.008574052355382087;
        bool r807417 = r807415 <= r807416;
        double r807418 = 2.0;
        double r807419 = exp(r807415);
        double r807420 = 1.0;
        double r807421 = r807419 + r807420;
        double r807422 = r807418 / r807421;
        double r807423 = r807422 - r807420;
        double r807424 = 1.4278659301426067e-07;
        bool r807425 = r807415 <= r807424;
        double r807426 = 0.13333333333333333;
        double r807427 = 5.0;
        double r807428 = pow(r807414, r807427);
        double r807429 = r807426 * r807428;
        double r807430 = r807414 + r807429;
        double r807431 = r807414 * r807414;
        double r807432 = r807431 * r807414;
        double r807433 = -0.3333333333333333;
        double r807434 = r807432 * r807433;
        double r807435 = r807430 + r807434;
        double r807436 = r807425 ? r807435 : r807423;
        double r807437 = r807417 ? r807423 : r807436;
        return r807437;
}

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 x) < -0.008574052355382087 or 1.4278659301426067e-07 < (* -2 x)

    1. Initial program 0.1

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

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

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

    if -0.008574052355382087 < (* -2 x) < 1.4278659301426067e-07

    1. Initial program 59.3

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

      \[\leadsto \color{blue}{\left(x + \frac{2}{15} \cdot {x}^{5}\right) - \frac{1}{3} \cdot {x}^{3}}\]
    3. Simplified0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.008574052355382087:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{elif}\;-2 \cdot x \le 1.4278659301426067 \cdot 10^{-07}:\\ \;\;\;\;\left(x + \frac{2}{15} \cdot {x}^{5}\right) + \left(\left(x \cdot x\right) \cdot x\right) \cdot \frac{-1}{3}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \end{array}\]

Reproduce

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