Average Error: 29.0 → 0.7
Time: 9.2s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -15476529172.2573032 \lor \neg \left(-2 \cdot x \le 1.11971615771184669 \cdot 10^{-4}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -15476529172.2573032 \lor \neg \left(-2 \cdot x \le 1.11971615771184669 \cdot 10^{-4}\right):\\
\;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r46788 = 2.0;
        double r46789 = 1.0;
        double r46790 = -2.0;
        double r46791 = x;
        double r46792 = r46790 * r46791;
        double r46793 = exp(r46792);
        double r46794 = r46789 + r46793;
        double r46795 = r46788 / r46794;
        double r46796 = r46795 - r46789;
        return r46796;
}

double f(double x, double __attribute__((unused)) y) {
        double r46797 = -2.0;
        double r46798 = x;
        double r46799 = r46797 * r46798;
        double r46800 = -15476529172.257303;
        bool r46801 = r46799 <= r46800;
        double r46802 = 0.00011197161577118467;
        bool r46803 = r46799 <= r46802;
        double r46804 = !r46803;
        bool r46805 = r46801 || r46804;
        double r46806 = 2.0;
        double r46807 = 1.0;
        double r46808 = exp(r46799);
        double r46809 = r46807 + r46808;
        double r46810 = r46806 / r46809;
        double r46811 = r46810 - r46807;
        double r46812 = exp(r46811);
        double r46813 = log(r46812);
        double r46814 = r46807 * r46798;
        double r46815 = 5.551115123125783e-17;
        double r46816 = 4.0;
        double r46817 = pow(r46798, r46816);
        double r46818 = r46815 * r46817;
        double r46819 = 0.33333333333333337;
        double r46820 = 3.0;
        double r46821 = pow(r46798, r46820);
        double r46822 = r46819 * r46821;
        double r46823 = r46818 + r46822;
        double r46824 = r46814 - r46823;
        double r46825 = r46805 ? r46813 : r46824;
        return r46825;
}

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) < -15476529172.257303 or 0.00011197161577118467 < (* -2.0 x)

    1. Initial program 0.0

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

      \[\leadsto \frac{2}{1 + e^{-2 \cdot x}} - \color{blue}{\log \left(e^{1}\right)}\]
    4. Applied add-log-exp0.0

      \[\leadsto \color{blue}{\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right)} - \log \left(e^{1}\right)\]
    5. Applied diff-log0.0

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

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

    if -15476529172.257303 < (* -2.0 x) < 0.00011197161577118467

    1. Initial program 57.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -15476529172.2573032 \lor \neg \left(-2 \cdot x \le 1.11971615771184669 \cdot 10^{-4}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)\\ \end{array}\]

Reproduce

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