Average Error: 29.4 → 0.1
Time: 28.3s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.3535994530314286454775185575272189453244:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{elif}\;-2 \cdot x \le 1.360762104871435039234140937369765822496 \cdot 10^{-6}:\\ \;\;\;\;\left(-\left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot 5.5511151231257827021181583404541015625 \cdot 10^{-17} + 0.3333333333333333703407674875052180141211 \cdot x\right)\right) + 1 \cdot x\\ \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.3535994530314286454775185575272189453244:\\
\;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r1602351 = 2.0;
        double r1602352 = 1.0;
        double r1602353 = -2.0;
        double r1602354 = x;
        double r1602355 = r1602353 * r1602354;
        double r1602356 = exp(r1602355);
        double r1602357 = r1602352 + r1602356;
        double r1602358 = r1602351 / r1602357;
        double r1602359 = r1602358 - r1602352;
        return r1602359;
}

double f(double x, double __attribute__((unused)) y) {
        double r1602360 = -2.0;
        double r1602361 = x;
        double r1602362 = r1602360 * r1602361;
        double r1602363 = -0.35359945303142865;
        bool r1602364 = r1602362 <= r1602363;
        double r1602365 = 2.0;
        double r1602366 = exp(r1602362);
        double r1602367 = 1.0;
        double r1602368 = r1602366 + r1602367;
        double r1602369 = r1602365 / r1602368;
        double r1602370 = r1602369 - r1602367;
        double r1602371 = 1.360762104871435e-06;
        bool r1602372 = r1602362 <= r1602371;
        double r1602373 = r1602361 * r1602361;
        double r1602374 = 5.551115123125783e-17;
        double r1602375 = r1602373 * r1602374;
        double r1602376 = 0.33333333333333337;
        double r1602377 = r1602376 * r1602361;
        double r1602378 = r1602375 + r1602377;
        double r1602379 = r1602373 * r1602378;
        double r1602380 = -r1602379;
        double r1602381 = r1602367 * r1602361;
        double r1602382 = r1602380 + r1602381;
        double r1602383 = r1602372 ? r1602382 : r1602370;
        double r1602384 = r1602364 ? r1602370 : r1602383;
        return r1602384;
}

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.35359945303142865 or 1.360762104871435e-06 < (* -2.0 x)

    1. Initial program 0.1

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

    if -0.35359945303142865 < (* -2.0 x) < 1.360762104871435e-06

    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 - 0.3333333333333333703407674875052180141211 \cdot \left(x \cdot x\right)\right) - \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot 5.5511151231257827021181583404541015625 \cdot 10^{-17}}\]
    4. Using strategy rm
    5. Applied sub-neg0.1

      \[\leadsto x \cdot \color{blue}{\left(1 + \left(-0.3333333333333333703407674875052180141211 \cdot \left(x \cdot x\right)\right)\right)} - \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot 5.5511151231257827021181583404541015625 \cdot 10^{-17}\]
    6. Applied distribute-rgt-in0.1

      \[\leadsto \color{blue}{\left(1 \cdot x + \left(-0.3333333333333333703407674875052180141211 \cdot \left(x \cdot x\right)\right) \cdot x\right)} - \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot 5.5511151231257827021181583404541015625 \cdot 10^{-17}\]
    7. Applied associate--l+0.1

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

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

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

Reproduce

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