Average Error: 29.6 → 0.1
Time: 9.4s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -2.824925416399024502567272065789438784122 \lor \neg \left(-2 \cdot x \le 3.433603601045391940976749672875811825179 \cdot 10^{-6}\right):\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -2.824925416399024502567272065789438784122 \lor \neg \left(-2 \cdot x \le 3.433603601045391940976749672875811825179 \cdot 10^{-6}\right):\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\

\mathbf{else}:\\
\;\;\;\;1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r21978 = 2.0;
        double r21979 = 1.0;
        double r21980 = -2.0;
        double r21981 = x;
        double r21982 = r21980 * r21981;
        double r21983 = exp(r21982);
        double r21984 = r21979 + r21983;
        double r21985 = r21978 / r21984;
        double r21986 = r21985 - r21979;
        return r21986;
}

double f(double x, double __attribute__((unused)) y) {
        double r21987 = -2.0;
        double r21988 = x;
        double r21989 = r21987 * r21988;
        double r21990 = -2.8249254163990245;
        bool r21991 = r21989 <= r21990;
        double r21992 = 3.433603601045392e-06;
        bool r21993 = r21989 <= r21992;
        double r21994 = !r21993;
        bool r21995 = r21991 || r21994;
        double r21996 = 2.0;
        double r21997 = 1.0;
        double r21998 = exp(r21989);
        double r21999 = r21997 + r21998;
        double r22000 = r21996 / r21999;
        double r22001 = r22000 - r21997;
        double r22002 = r21997 * r21988;
        double r22003 = 5.551115123125783e-17;
        double r22004 = 4.0;
        double r22005 = pow(r21988, r22004);
        double r22006 = r22003 * r22005;
        double r22007 = 0.33333333333333337;
        double r22008 = 3.0;
        double r22009 = pow(r21988, r22008);
        double r22010 = r22007 * r22009;
        double r22011 = r22006 + r22010;
        double r22012 = r22002 - r22011;
        double r22013 = r21995 ? r22001 : r22012;
        return r22013;
}

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) < -2.8249254163990245 or 3.433603601045392e-06 < (* -2.0 x)

    1. Initial program 0.1

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

    if -2.8249254163990245 < (* -2.0 x) < 3.433603601045392e-06

    1. Initial program 59.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -2.824925416399024502567272065789438784122 \lor \neg \left(-2 \cdot x \le 3.433603601045391940976749672875811825179 \cdot 10^{-6}\right):\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \end{array}\]

Reproduce

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