Average Error: 29.1 → 1.6
Time: 12.2s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -2.8120200043225174 \cdot 10^{+29}:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{elif}\;-2 \cdot x \le 3.9392690718862813 \cdot 10^{-07}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot \left(x \cdot x\right), \frac{-1}{3}, \mathsf{fma}\left(\frac{2}{15}, {x}^{5}, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -2.8120200043225174 \cdot 10^{+29}:\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r849000 = 2.0;
        double r849001 = 1.0;
        double r849002 = -2.0;
        double r849003 = x;
        double r849004 = r849002 * r849003;
        double r849005 = exp(r849004);
        double r849006 = r849001 + r849005;
        double r849007 = r849000 / r849006;
        double r849008 = r849007 - r849001;
        return r849008;
}

double f(double x, double __attribute__((unused)) y) {
        double r849009 = -2.0;
        double r849010 = x;
        double r849011 = r849009 * r849010;
        double r849012 = -2.8120200043225174e+29;
        bool r849013 = r849011 <= r849012;
        double r849014 = 2.0;
        double r849015 = 1.0;
        double r849016 = exp(r849011);
        double r849017 = r849015 + r849016;
        double r849018 = r849014 / r849017;
        double r849019 = r849018 - r849015;
        double r849020 = 3.9392690718862813e-07;
        bool r849021 = r849011 <= r849020;
        double r849022 = r849010 * r849010;
        double r849023 = r849010 * r849022;
        double r849024 = -0.3333333333333333;
        double r849025 = 0.13333333333333333;
        double r849026 = 5.0;
        double r849027 = pow(r849010, r849026);
        double r849028 = fma(r849025, r849027, r849010);
        double r849029 = fma(r849023, r849024, r849028);
        double r849030 = r849021 ? r849029 : r849019;
        double r849031 = r849013 ? r849019 : r849030;
        return r849031;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2 x) < -2.8120200043225174e+29 or 3.9392690718862813e-07 < (* -2 x)

    1. Initial program 0.1

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

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

    if -2.8120200043225174e+29 < (* -2 x) < 3.9392690718862813e-07

    1. Initial program 56.4

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

      \[\leadsto \color{blue}{\frac{2}{e^{-2 \cdot x} + 1}} - 1\]
    3. Taylor expanded around 0 2.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -2.8120200043225174 \cdot 10^{+29}:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{elif}\;-2 \cdot x \le 3.9392690718862813 \cdot 10^{-07}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot \left(x \cdot x\right), \frac{-1}{3}, \mathsf{fma}\left(\frac{2}{15}, {x}^{5}, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \end{array}\]

Reproduce

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