Average Error: 29.2 → 0.1
Time: 33.2s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.3818320007707001750851816268550464883447:\\ \;\;\;\;\frac{1}{\sqrt{1 + e^{-2 \cdot x}}} \cdot \frac{2}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\ \mathbf{elif}\;-2 \cdot x \le 1.537410466881136385719139325622961678164 \cdot 10^{-5}:\\ \;\;\;\;x \cdot \left(1 - \left(x \cdot x\right) \cdot 0.3333333333333333703407674875052180141211\right) - 5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{1 + e^{-2 \cdot x}}} \cdot \frac{2}{\sqrt{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 -0.3818320007707001750851816268550464883447:\\
\;\;\;\;\frac{1}{\sqrt{1 + e^{-2 \cdot x}}} \cdot \frac{2}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r7247354 = 2.0;
        double r7247355 = 1.0;
        double r7247356 = -2.0;
        double r7247357 = x;
        double r7247358 = r7247356 * r7247357;
        double r7247359 = exp(r7247358);
        double r7247360 = r7247355 + r7247359;
        double r7247361 = r7247354 / r7247360;
        double r7247362 = r7247361 - r7247355;
        return r7247362;
}

double f(double x, double __attribute__((unused)) y) {
        double r7247363 = -2.0;
        double r7247364 = x;
        double r7247365 = r7247363 * r7247364;
        double r7247366 = -0.3818320007707002;
        bool r7247367 = r7247365 <= r7247366;
        double r7247368 = 1.0;
        double r7247369 = 1.0;
        double r7247370 = exp(r7247365);
        double r7247371 = r7247369 + r7247370;
        double r7247372 = sqrt(r7247371);
        double r7247373 = r7247368 / r7247372;
        double r7247374 = 2.0;
        double r7247375 = r7247374 / r7247372;
        double r7247376 = r7247373 * r7247375;
        double r7247377 = r7247376 - r7247369;
        double r7247378 = 1.5374104668811364e-05;
        bool r7247379 = r7247365 <= r7247378;
        double r7247380 = r7247364 * r7247364;
        double r7247381 = 0.33333333333333337;
        double r7247382 = r7247380 * r7247381;
        double r7247383 = r7247369 - r7247382;
        double r7247384 = r7247364 * r7247383;
        double r7247385 = 5.551115123125783e-17;
        double r7247386 = r7247380 * r7247380;
        double r7247387 = r7247385 * r7247386;
        double r7247388 = r7247384 - r7247387;
        double r7247389 = r7247379 ? r7247388 : r7247377;
        double r7247390 = r7247367 ? r7247377 : r7247389;
        return r7247390;
}

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.3818320007707002 or 1.5374104668811364e-05 < (* -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 *-un-lft-identity0.1

      \[\leadsto \frac{\color{blue}{1 \cdot 2}}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}} - 1\]
    5. Applied times-frac0.1

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

    if -0.3818320007707002 < (* -2.0 x) < 1.5374104668811364e-05

    1. Initial program 59.3

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

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

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

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

Reproduce

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