Average Error: 29.0 → 0.2
Time: 18.3s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -220.3193758652155054278409807011485099792 \lor \neg \left(-2 \cdot x \le 3.564166708824457449394582098101125211542 \cdot 10^{-6}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right) - 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 -220.3193758652155054278409807011485099792 \lor \neg \left(-2 \cdot x \le 3.564166708824457449394582098101125211542 \cdot 10^{-6}\right):\\
\;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right) - 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 r42769 = 2.0;
        double r42770 = 1.0;
        double r42771 = -2.0;
        double r42772 = x;
        double r42773 = r42771 * r42772;
        double r42774 = exp(r42773);
        double r42775 = r42770 + r42774;
        double r42776 = r42769 / r42775;
        double r42777 = r42776 - r42770;
        return r42777;
}

double f(double x, double __attribute__((unused)) y) {
        double r42778 = -2.0;
        double r42779 = x;
        double r42780 = r42778 * r42779;
        double r42781 = -220.3193758652155;
        bool r42782 = r42780 <= r42781;
        double r42783 = 3.5641667088244574e-06;
        bool r42784 = r42780 <= r42783;
        double r42785 = !r42784;
        bool r42786 = r42782 || r42785;
        double r42787 = 2.0;
        double r42788 = 1.0;
        double r42789 = exp(r42780);
        double r42790 = r42788 + r42789;
        double r42791 = r42787 / r42790;
        double r42792 = exp(r42791);
        double r42793 = log(r42792);
        double r42794 = r42793 - r42788;
        double r42795 = r42788 * r42779;
        double r42796 = 5.551115123125783e-17;
        double r42797 = 4.0;
        double r42798 = pow(r42779, r42797);
        double r42799 = r42796 * r42798;
        double r42800 = 0.33333333333333337;
        double r42801 = 3.0;
        double r42802 = pow(r42779, r42801);
        double r42803 = r42800 * r42802;
        double r42804 = r42799 + r42803;
        double r42805 = r42795 - r42804;
        double r42806 = r42786 ? r42794 : r42805;
        return r42806;
}

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

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right)} - 1\]

    if -220.3193758652155 < (* -2.0 x) < 3.5641667088244574e-06

    1. Initial program 58.9

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

      \[\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.2

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