Average Error: 29.2 → 0.0
Time: 19.2s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.007801985501095653:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{elif}\;x \le 0.011811720304489515:\\ \;\;\;\;\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{2}{\mathsf{expm1}\left(-4 \cdot x\right)} \cdot \left(e^{-2 \cdot x} - 1\right) - 1\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;x \le -0.007801985501095653:\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\

\mathbf{elif}\;x \le 0.011811720304489515:\\
\;\;\;\;\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{2}{\mathsf{expm1}\left(-4 \cdot x\right)} \cdot \left(e^{-2 \cdot x} - 1\right) - 1\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r2081686 = 2.0;
        double r2081687 = 1.0;
        double r2081688 = -2.0;
        double r2081689 = x;
        double r2081690 = r2081688 * r2081689;
        double r2081691 = exp(r2081690);
        double r2081692 = r2081687 + r2081691;
        double r2081693 = r2081686 / r2081692;
        double r2081694 = r2081693 - r2081687;
        return r2081694;
}

double f(double x, double __attribute__((unused)) y) {
        double r2081695 = x;
        double r2081696 = -0.007801985501095653;
        bool r2081697 = r2081695 <= r2081696;
        double r2081698 = 2.0;
        double r2081699 = 1.0;
        double r2081700 = -2.0;
        double r2081701 = r2081700 * r2081695;
        double r2081702 = exp(r2081701);
        double r2081703 = r2081699 + r2081702;
        double r2081704 = r2081698 / r2081703;
        double r2081705 = r2081704 - r2081699;
        double r2081706 = 0.011811720304489515;
        bool r2081707 = r2081695 <= r2081706;
        double r2081708 = -0.3333333333333333;
        double r2081709 = r2081695 * r2081695;
        double r2081710 = r2081695 * r2081709;
        double r2081711 = 5.0;
        double r2081712 = pow(r2081695, r2081711);
        double r2081713 = 0.13333333333333333;
        double r2081714 = fma(r2081712, r2081713, r2081695);
        double r2081715 = fma(r2081708, r2081710, r2081714);
        double r2081716 = -4.0;
        double r2081717 = r2081716 * r2081695;
        double r2081718 = expm1(r2081717);
        double r2081719 = r2081698 / r2081718;
        double r2081720 = r2081702 - r2081699;
        double r2081721 = r2081719 * r2081720;
        double r2081722 = r2081721 - r2081699;
        double r2081723 = r2081707 ? r2081715 : r2081722;
        double r2081724 = r2081697 ? r2081705 : r2081723;
        return r2081724;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 3 regimes
  2. if x < -0.007801985501095653

    1. Initial program 0.0

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

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

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

    if -0.007801985501095653 < x < 0.011811720304489515

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

    if 0.011811720304489515 < x

    1. Initial program 0.0

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

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

      \[\leadsto \color{blue}{\frac{2}{e^{x \cdot -2} + 1} - 1}\]
    4. Using strategy rm
    5. Applied flip-+0.0

      \[\leadsto \frac{2}{\color{blue}{\frac{e^{x \cdot -2} \cdot e^{x \cdot -2} - 1 \cdot 1}{e^{x \cdot -2} - 1}}} - 1\]
    6. Applied associate-/r/0.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.007801985501095653:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{elif}\;x \le 0.011811720304489515:\\ \;\;\;\;\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{2}{\mathsf{expm1}\left(-4 \cdot x\right)} \cdot \left(e^{-2 \cdot x} - 1\right) - 1\\ \end{array}\]

Reproduce

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