Average Error: 29.4 → 0.3
Time: 10.6s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -1876086.774165026:\\ \;\;\;\;\log \left(e^{\frac{2}{e^{-2 \cdot x} + 1} - 1}\right)\\ \mathbf{elif}\;-2 \cdot x \le 7.940217460912 \cdot 10^{-07}:\\ \;\;\;\;{x}^{5} \cdot \frac{2}{15} + \left(x - \left(\left(x \cdot x\right) \cdot x\right) \cdot \frac{1}{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{2}{e^{-2 \cdot x} + 1} - 1}\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -1876086.774165026:\\
\;\;\;\;\log \left(e^{\frac{2}{e^{-2 \cdot x} + 1} - 1}\right)\\

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

\mathbf{else}:\\
\;\;\;\;\log \left(e^{\frac{2}{e^{-2 \cdot x} + 1} - 1}\right)\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r645822 = 2.0;
        double r645823 = 1.0;
        double r645824 = -2.0;
        double r645825 = x;
        double r645826 = r645824 * r645825;
        double r645827 = exp(r645826);
        double r645828 = r645823 + r645827;
        double r645829 = r645822 / r645828;
        double r645830 = r645829 - r645823;
        return r645830;
}

double f(double x, double __attribute__((unused)) y) {
        double r645831 = -2.0;
        double r645832 = x;
        double r645833 = r645831 * r645832;
        double r645834 = -1876086.774165026;
        bool r645835 = r645833 <= r645834;
        double r645836 = 2.0;
        double r645837 = exp(r645833);
        double r645838 = 1.0;
        double r645839 = r645837 + r645838;
        double r645840 = r645836 / r645839;
        double r645841 = r645840 - r645838;
        double r645842 = exp(r645841);
        double r645843 = log(r645842);
        double r645844 = 7.940217460912e-07;
        bool r645845 = r645833 <= r645844;
        double r645846 = 5.0;
        double r645847 = pow(r645832, r645846);
        double r645848 = 0.13333333333333333;
        double r645849 = r645847 * r645848;
        double r645850 = r645832 * r645832;
        double r645851 = r645850 * r645832;
        double r645852 = 0.3333333333333333;
        double r645853 = r645851 * r645852;
        double r645854 = r645832 - r645853;
        double r645855 = r645849 + r645854;
        double r645856 = r645845 ? r645855 : r645843;
        double r645857 = r645835 ? r645843 : r645856;
        return r645857;
}

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) < -1876086.774165026 or 7.940217460912e-07 < (* -2 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 -1876086.774165026 < (* -2 x) < 7.940217460912e-07

    1. Initial program 58.5

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

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

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

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

Reproduce

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