Average Error: 29.1 → 1.6
Time: 31.2s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -2.8120200043225174 \cdot 10^{+29}:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{elif}\;-2 \cdot x \le 3.9392690718862813 \cdot 10^{-07}:\\ \;\;\;\;\left({x}^{5} \cdot \frac{2}{15} + \left(x \cdot x\right) \cdot \left(x \cdot \frac{-1}{3}\right)\right) + x\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -2.8120200043225174 \cdot 10^{+29}:\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r2157334 = 2.0;
        double r2157335 = 1.0;
        double r2157336 = -2.0;
        double r2157337 = x;
        double r2157338 = r2157336 * r2157337;
        double r2157339 = exp(r2157338);
        double r2157340 = r2157335 + r2157339;
        double r2157341 = r2157334 / r2157340;
        double r2157342 = r2157341 - r2157335;
        return r2157342;
}

double f(double x, double __attribute__((unused)) y) {
        double r2157343 = -2.0;
        double r2157344 = x;
        double r2157345 = r2157343 * r2157344;
        double r2157346 = -2.8120200043225174e+29;
        bool r2157347 = r2157345 <= r2157346;
        double r2157348 = 2.0;
        double r2157349 = 1.0;
        double r2157350 = exp(r2157345);
        double r2157351 = r2157349 + r2157350;
        double r2157352 = r2157348 / r2157351;
        double r2157353 = r2157352 - r2157349;
        double r2157354 = 3.9392690718862813e-07;
        bool r2157355 = r2157345 <= r2157354;
        double r2157356 = 5.0;
        double r2157357 = pow(r2157344, r2157356);
        double r2157358 = 0.13333333333333333;
        double r2157359 = r2157357 * r2157358;
        double r2157360 = r2157344 * r2157344;
        double r2157361 = -0.3333333333333333;
        double r2157362 = r2157344 * r2157361;
        double r2157363 = r2157360 * r2157362;
        double r2157364 = r2157359 + r2157363;
        double r2157365 = r2157364 + r2157344;
        double r2157366 = r2157355 ? r2157365 : r2157353;
        double r2157367 = r2157347 ? r2157353 : r2157366;
        return r2157367;
}

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) < -2.8120200043225174e+29 or 3.9392690718862813e-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}{\frac{2}{e^{-2 \cdot x} + 1}} - 1\]

    if -2.8120200043225174e+29 < (* -2 x) < 3.9392690718862813e-07

    1. Initial program 56.4

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

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

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

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

Reproduce

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