Average Error: 29.1 → 1.6
Time: 44.4s
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}^{5}, \frac{2}{15}, \mathsf{fma}\left(\frac{-1}{3}, \left(x \cdot x\right) \cdot x, 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}^{5}, \frac{2}{15}, \mathsf{fma}\left(\frac{-1}{3}, \left(x \cdot x\right) \cdot x, x\right)\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r2185178 = 2.0;
        double r2185179 = 1.0;
        double r2185180 = -2.0;
        double r2185181 = x;
        double r2185182 = r2185180 * r2185181;
        double r2185183 = exp(r2185182);
        double r2185184 = r2185179 + r2185183;
        double r2185185 = r2185178 / r2185184;
        double r2185186 = r2185185 - r2185179;
        return r2185186;
}

double f(double x, double __attribute__((unused)) y) {
        double r2185187 = -2.0;
        double r2185188 = x;
        double r2185189 = r2185187 * r2185188;
        double r2185190 = -2.8120200043225174e+29;
        bool r2185191 = r2185189 <= r2185190;
        double r2185192 = 2.0;
        double r2185193 = 1.0;
        double r2185194 = exp(r2185189);
        double r2185195 = r2185193 + r2185194;
        double r2185196 = r2185192 / r2185195;
        double r2185197 = r2185196 - r2185193;
        double r2185198 = 3.9392690718862813e-07;
        bool r2185199 = r2185189 <= r2185198;
        double r2185200 = 5.0;
        double r2185201 = pow(r2185188, r2185200);
        double r2185202 = 0.13333333333333333;
        double r2185203 = -0.3333333333333333;
        double r2185204 = r2185188 * r2185188;
        double r2185205 = r2185204 * r2185188;
        double r2185206 = fma(r2185203, r2185205, r2185188);
        double r2185207 = fma(r2185201, r2185202, r2185206);
        double r2185208 = r2185199 ? r2185207 : r2185197;
        double r2185209 = r2185191 ? r2185197 : r2185208;
        return r2185209;
}

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}^{5}, \frac{2}{15}, \mathsf{fma}\left(\frac{-1}{3}, x \cdot \left(x \cdot x\right), 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}^{5}, \frac{2}{15}, \mathsf{fma}\left(\frac{-1}{3}, \left(x \cdot x\right) \cdot x, 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))