Average Error: 29.6 → 1.3
Time: 20.6s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -864984669564619502649344 \lor \neg \left(-2 \cdot x \le 4.629032879111215459799953089899127167683 \cdot 10^{-8}\right):\\ \;\;\;\;\frac{1}{\frac{1 + e^{-2 \cdot x}}{2}} - 1\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - {x}^{3} \cdot \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot x + 0.3333333333333333703407674875052180141211\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -864984669564619502649344 \lor \neg \left(-2 \cdot x \le 4.629032879111215459799953089899127167683 \cdot 10^{-8}\right):\\
\;\;\;\;\frac{1}{\frac{1 + e^{-2 \cdot x}}{2}} - 1\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r31960 = 2.0;
        double r31961 = 1.0;
        double r31962 = -2.0;
        double r31963 = x;
        double r31964 = r31962 * r31963;
        double r31965 = exp(r31964);
        double r31966 = r31961 + r31965;
        double r31967 = r31960 / r31966;
        double r31968 = r31967 - r31961;
        return r31968;
}

double f(double x, double __attribute__((unused)) y) {
        double r31969 = -2.0;
        double r31970 = x;
        double r31971 = r31969 * r31970;
        double r31972 = -8.649846695646195e+23;
        bool r31973 = r31971 <= r31972;
        double r31974 = 4.6290328791112155e-08;
        bool r31975 = r31971 <= r31974;
        double r31976 = !r31975;
        bool r31977 = r31973 || r31976;
        double r31978 = 1.0;
        double r31979 = 1.0;
        double r31980 = exp(r31971);
        double r31981 = r31979 + r31980;
        double r31982 = 2.0;
        double r31983 = r31981 / r31982;
        double r31984 = r31978 / r31983;
        double r31985 = r31984 - r31979;
        double r31986 = r31979 * r31970;
        double r31987 = 3.0;
        double r31988 = pow(r31970, r31987);
        double r31989 = 5.551115123125783e-17;
        double r31990 = r31989 * r31970;
        double r31991 = 0.33333333333333337;
        double r31992 = r31990 + r31991;
        double r31993 = r31988 * r31992;
        double r31994 = r31986 - r31993;
        double r31995 = r31977 ? r31985 : r31994;
        return r31995;
}

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) < -8.649846695646195e+23 or 4.6290328791112155e-08 < (* -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.2

      \[\leadsto \frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    4. Applied associate-/r*0.1

      \[\leadsto \color{blue}{\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    5. Using strategy rm
    6. Applied clear-num0.1

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

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

    if -8.649846695646195e+23 < (* -2.0 x) < 4.6290328791112155e-08

    1. Initial program 57.2

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt58.2

      \[\leadsto \frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    4. Applied associate-/r*58.1

      \[\leadsto \color{blue}{\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    5. Using strategy rm
    6. Applied clear-num58.2

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

      \[\leadsto \frac{1}{\color{blue}{\frac{1 + e^{-2 \cdot x}}{2}}} - 1\]
    8. Taylor expanded around 0 2.3

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

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

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

Reproduce

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