Average Error: 29.6 → 0.0
Time: 18.4s
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 - \left(0.33333333333333337 \cdot {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 - \left(0.33333333333333337 \cdot {x}^{3} + 5.55112 \cdot 10^{-17} \cdot {x}^{4}\right)\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r45941 = 2.0;
        double r45942 = 1.0;
        double r45943 = -2.0;
        double r45944 = x;
        double r45945 = r45943 * r45944;
        double r45946 = exp(r45945);
        double r45947 = r45942 + r45946;
        double r45948 = r45941 / r45947;
        double r45949 = r45948 - r45942;
        return r45949;
}

double f(double x, double __attribute__((unused)) y) {
        double r45950 = -2.0;
        double r45951 = x;
        double r45952 = r45950 * r45951;
        double r45953 = -0.007024781297796352;
        bool r45954 = r45952 <= r45953;
        double r45955 = 0.00021090889322443695;
        bool r45956 = r45952 <= r45955;
        double r45957 = !r45956;
        bool r45958 = r45954 || r45957;
        double r45959 = 2.0;
        double r45960 = 1.0;
        double r45961 = exp(r45952);
        double r45962 = r45960 + r45961;
        double r45963 = r45959 / r45962;
        double r45964 = r45963 - r45960;
        double r45965 = exp(r45964);
        double r45966 = log(r45965);
        double r45967 = r45960 * r45951;
        double r45968 = 0.33333333333333337;
        double r45969 = 3.0;
        double r45970 = pow(r45951, r45969);
        double r45971 = r45968 * r45970;
        double r45972 = 5.551115123125783e-17;
        double r45973 = 4.0;
        double r45974 = pow(r45951, r45973);
        double r45975 = r45972 * r45974;
        double r45976 = r45971 + r45975;
        double r45977 = r45967 - r45976;
        double r45978 = r45958 ? r45966 : r45977;
        return r45978;
}

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) < -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. 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 - \left(0.33333333333333337 \cdot {x}^{3} + 5.55112 \cdot 10^{-17} \cdot {x}^{4}\right)\\ \end{array}\]

Reproduce

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