Average Error: 29.6 → 1.4
Time: 13.8s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -95920403938297937322311680 \lor \neg \left(-2 \cdot x \le 3.196125594223232866536443808058720605914 \cdot 10^{-4}\right):\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{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 -95920403938297937322311680 \lor \neg \left(-2 \cdot x \le 3.196125594223232866536443808058720605914 \cdot 10^{-4}\right):\\
\;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{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 r41779 = 2.0;
        double r41780 = 1.0;
        double r41781 = -2.0;
        double r41782 = x;
        double r41783 = r41781 * r41782;
        double r41784 = exp(r41783);
        double r41785 = r41780 + r41784;
        double r41786 = r41779 / r41785;
        double r41787 = r41786 - r41780;
        return r41787;
}

double f(double x, double __attribute__((unused)) y) {
        double r41788 = -2.0;
        double r41789 = x;
        double r41790 = r41788 * r41789;
        double r41791 = -9.592040393829794e+25;
        bool r41792 = r41790 <= r41791;
        double r41793 = 0.0003196125594223233;
        bool r41794 = r41790 <= r41793;
        double r41795 = !r41794;
        bool r41796 = r41792 || r41795;
        double r41797 = 2.0;
        double r41798 = 1.0;
        double r41799 = exp(r41790);
        double r41800 = r41798 + r41799;
        double r41801 = sqrt(r41800);
        double r41802 = r41797 / r41801;
        double r41803 = r41802 / r41801;
        double r41804 = r41803 - r41798;
        double r41805 = r41798 * r41789;
        double r41806 = 5.551115123125783e-17;
        double r41807 = 4.0;
        double r41808 = pow(r41789, r41807);
        double r41809 = r41806 * r41808;
        double r41810 = 0.33333333333333337;
        double r41811 = 3.0;
        double r41812 = pow(r41789, r41811);
        double r41813 = r41810 * r41812;
        double r41814 = r41809 + r41813;
        double r41815 = r41805 - r41814;
        double r41816 = r41796 ? r41804 : r41815;
        return r41816;
}

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) < -9.592040393829794e+25 or 0.0003196125594223233 < (* -2.0 x)

    1. Initial program 0.0

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

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

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

    if -9.592040393829794e+25 < (* -2.0 x) < 0.0003196125594223233

    1. Initial program 56.8

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

      \[\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 simplification1.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -95920403938297937322311680 \lor \neg \left(-2 \cdot x \le 3.196125594223232866536443808058720605914 \cdot 10^{-4}\right):\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{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 2019305 
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  :precision binary64
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))