Average Error: 29.6 → 0.0
Time: 19.2s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.00702478129779635172 \lor \neg \left(-2 \cdot x \le 2.1090889322443695 \cdot 10^{-4}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(0.33333333333333337, {x}^{3}, 5.55112 \cdot 10^{-17} \cdot {x}^{4}\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.00702478129779635172 \lor \neg \left(-2 \cdot x \le 2.1090889322443695 \cdot 10^{-4}\right):\\
\;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r42955 = 2.0;
        double r42956 = 1.0;
        double r42957 = -2.0;
        double r42958 = x;
        double r42959 = r42957 * r42958;
        double r42960 = exp(r42959);
        double r42961 = r42956 + r42960;
        double r42962 = r42955 / r42961;
        double r42963 = r42962 - r42956;
        return r42963;
}

double f(double x, double __attribute__((unused)) y) {
        double r42964 = -2.0;
        double r42965 = x;
        double r42966 = r42964 * r42965;
        double r42967 = -0.007024781297796352;
        bool r42968 = r42966 <= r42967;
        double r42969 = 0.00021090889322443695;
        bool r42970 = r42966 <= r42969;
        double r42971 = !r42970;
        bool r42972 = r42968 || r42971;
        double r42973 = 2.0;
        double r42974 = 1.0;
        double r42975 = exp(r42966);
        double r42976 = r42974 + r42975;
        double r42977 = r42973 / r42976;
        double r42978 = r42977 - r42974;
        double r42979 = exp(r42978);
        double r42980 = log(r42979);
        double r42981 = r42974 * r42965;
        double r42982 = 0.33333333333333337;
        double r42983 = 3.0;
        double r42984 = pow(r42965, r42983);
        double r42985 = 5.551115123125783e-17;
        double r42986 = 4.0;
        double r42987 = pow(r42965, r42986);
        double r42988 = r42985 * r42987;
        double r42989 = fma(r42982, r42984, r42988);
        double r42990 = r42981 - r42989;
        double r42991 = r42972 ? r42980 : r42990;
        return r42991;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -0.007024781297796352 or 0.00021090889322443695 < (* -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 \frac{2}{1 + e^{-2 \cdot x}} - \color{blue}{\log \left(e^{1}\right)}\]
    4. Applied add-log-exp0.1

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

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

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

    if -0.007024781297796352 < (* -2.0 x) < 0.00021090889322443695

    1. Initial program 59.1

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

      \[\leadsto \color{blue}{1 \cdot x - \left(0.33333333333333337 \cdot {x}^{3} + 5.55112 \cdot 10^{-17} \cdot {x}^{4}\right)}\]
    3. Simplified0.0

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

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

Reproduce

herbie shell --seed 2019195 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))