Average Error: 29.4 → 0.1
Time: 11.1s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.35359945303142865:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{elif}\;-2 \cdot x \le 1.360762104871435 \cdot 10^{-06}:\\ \;\;\;\;\left(x + \frac{2}{15} \cdot {x}^{5}\right) + \left(x \cdot \left(x \cdot x\right)\right) \cdot \frac{-1}{3}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.35359945303142865:\\
\;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\

\mathbf{elif}\;-2 \cdot x \le 1.360762104871435 \cdot 10^{-06}:\\
\;\;\;\;\left(x + \frac{2}{15} \cdot {x}^{5}\right) + \left(x \cdot \left(x \cdot x\right)\right) \cdot \frac{-1}{3}\\

\mathbf{else}:\\
\;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r2013182 = 2.0;
        double r2013183 = 1.0;
        double r2013184 = -2.0;
        double r2013185 = x;
        double r2013186 = r2013184 * r2013185;
        double r2013187 = exp(r2013186);
        double r2013188 = r2013183 + r2013187;
        double r2013189 = r2013182 / r2013188;
        double r2013190 = r2013189 - r2013183;
        return r2013190;
}

double f(double x, double __attribute__((unused)) y) {
        double r2013191 = -2.0;
        double r2013192 = x;
        double r2013193 = r2013191 * r2013192;
        double r2013194 = -0.35359945303142865;
        bool r2013195 = r2013193 <= r2013194;
        double r2013196 = 2.0;
        double r2013197 = exp(r2013193);
        double r2013198 = 1.0;
        double r2013199 = r2013197 + r2013198;
        double r2013200 = r2013196 / r2013199;
        double r2013201 = r2013200 - r2013198;
        double r2013202 = 1.360762104871435e-06;
        bool r2013203 = r2013193 <= r2013202;
        double r2013204 = 0.13333333333333333;
        double r2013205 = 5.0;
        double r2013206 = pow(r2013192, r2013205);
        double r2013207 = r2013204 * r2013206;
        double r2013208 = r2013192 + r2013207;
        double r2013209 = r2013192 * r2013192;
        double r2013210 = r2013192 * r2013209;
        double r2013211 = -0.3333333333333333;
        double r2013212 = r2013210 * r2013211;
        double r2013213 = r2013208 + r2013212;
        double r2013214 = r2013203 ? r2013213 : r2013201;
        double r2013215 = r2013195 ? r2013201 : r2013214;
        return r2013215;
}

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 x) < -0.35359945303142865 or 1.360762104871435e-06 < (* -2 x)

    1. Initial program 0.1

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]

    if -0.35359945303142865 < (* -2 x) < 1.360762104871435e-06

    1. Initial program 59.3

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

      \[\leadsto \color{blue}{\left(x + \frac{2}{15} \cdot {x}^{5}\right) - \frac{1}{3} \cdot {x}^{3}}\]
    3. Simplified0.1

      \[\leadsto \color{blue}{\left(x + {x}^{5} \cdot \frac{2}{15}\right) + \left(\left(x \cdot x\right) \cdot x\right) \cdot \frac{-1}{3}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.35359945303142865:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{elif}\;-2 \cdot x \le 1.360762104871435 \cdot 10^{-06}:\\ \;\;\;\;\left(x + \frac{2}{15} \cdot {x}^{5}\right) + \left(x \cdot \left(x \cdot x\right)\right) \cdot \frac{-1}{3}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \end{array}\]

Reproduce

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