Average Error: 29.7 → 0.0
Time: 28.4s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.005900779815178019:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{2}{e^{-2 \cdot x} + 1}, \frac{2}{e^{-2 \cdot x} + 1} \cdot \frac{2}{e^{-2 \cdot x} + 1}, -1\right)}{\mathsf{fma}\left(\frac{2}{e^{-2 \cdot x} + 1}, \frac{2}{e^{-2 \cdot x} + 1}, 1\right) + \frac{2}{e^{-2 \cdot x} + 1}}\\ \mathbf{elif}\;x \le 0.007644269470426118:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{3}, x \cdot \left(x \cdot x\right), \mathsf{fma}\left({x}^{5}, \frac{2}{15}, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{2}{e^{-2 \cdot x} + 1}, \frac{2}{e^{-2 \cdot x} + 1} \cdot \frac{2}{e^{-2 \cdot x} + 1}, -1\right)}{\mathsf{fma}\left(\frac{2}{e^{-2 \cdot x} + 1}, \frac{2}{e^{-2 \cdot x} + 1}, 1\right) + \frac{2}{e^{-2 \cdot x} + 1}}\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;x \le -0.005900779815178019:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{2}{e^{-2 \cdot x} + 1}, \frac{2}{e^{-2 \cdot x} + 1} \cdot \frac{2}{e^{-2 \cdot x} + 1}, -1\right)}{\mathsf{fma}\left(\frac{2}{e^{-2 \cdot x} + 1}, \frac{2}{e^{-2 \cdot x} + 1}, 1\right) + \frac{2}{e^{-2 \cdot x} + 1}}\\

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r2403674 = 2.0;
        double r2403675 = 1.0;
        double r2403676 = -2.0;
        double r2403677 = x;
        double r2403678 = r2403676 * r2403677;
        double r2403679 = exp(r2403678);
        double r2403680 = r2403675 + r2403679;
        double r2403681 = r2403674 / r2403680;
        double r2403682 = r2403681 - r2403675;
        return r2403682;
}

double f(double x, double __attribute__((unused)) y) {
        double r2403683 = x;
        double r2403684 = -0.005900779815178019;
        bool r2403685 = r2403683 <= r2403684;
        double r2403686 = 2.0;
        double r2403687 = -2.0;
        double r2403688 = r2403687 * r2403683;
        double r2403689 = exp(r2403688);
        double r2403690 = 1.0;
        double r2403691 = r2403689 + r2403690;
        double r2403692 = r2403686 / r2403691;
        double r2403693 = r2403692 * r2403692;
        double r2403694 = -1.0;
        double r2403695 = fma(r2403692, r2403693, r2403694);
        double r2403696 = fma(r2403692, r2403692, r2403690);
        double r2403697 = r2403696 + r2403692;
        double r2403698 = r2403695 / r2403697;
        double r2403699 = 0.007644269470426118;
        bool r2403700 = r2403683 <= r2403699;
        double r2403701 = -0.3333333333333333;
        double r2403702 = r2403683 * r2403683;
        double r2403703 = r2403683 * r2403702;
        double r2403704 = 5.0;
        double r2403705 = pow(r2403683, r2403704);
        double r2403706 = 0.13333333333333333;
        double r2403707 = fma(r2403705, r2403706, r2403683);
        double r2403708 = fma(r2403701, r2403703, r2403707);
        double r2403709 = r2403700 ? r2403708 : r2403698;
        double r2403710 = r2403685 ? r2403698 : r2403709;
        return r2403710;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if x < -0.005900779815178019 or 0.007644269470426118 < x

    1. Initial program 0.0

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied flip3--0.0

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{2}{1 + e^{-2 \cdot x}}, \frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}}, -1\right)}}{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} + \left(1 \cdot 1 + \frac{2}{1 + e^{-2 \cdot x}} \cdot 1\right)}\]
    5. Simplified0.0

      \[\leadsto \frac{\mathsf{fma}\left(\frac{2}{1 + e^{-2 \cdot x}}, \frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}}, -1\right)}{\color{blue}{\mathsf{fma}\left(\frac{2}{1 + e^{-2 \cdot x}}, \frac{2}{1 + e^{-2 \cdot x}}, 1\right) + \frac{2}{1 + e^{-2 \cdot x}}}}\]

    if -0.005900779815178019 < x < 0.007644269470426118

    1. Initial program 59.0

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

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

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

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

Reproduce

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