Average Error: 29.6 → 0.2
Time: 18.3s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -1972.3938625414924:\\ \;\;\;\;\frac{\frac{2}{\sqrt{e^{-2 \cdot x} + 1}}}{\sqrt{e^{-2 \cdot x} + 1}} - 1\\ \mathbf{elif}\;-2 \cdot x \le 0.0002071702113622589:\\ \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot x, \frac{-1}{3}, \mathsf{fma}\left({x}^{5}, \frac{2}{15}, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{2}, \frac{\sqrt{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 -1972.3938625414924:\\
\;\;\;\;\frac{\frac{2}{\sqrt{e^{-2 \cdot x} + 1}}}{\sqrt{e^{-2 \cdot x} + 1}} - 1\\

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r2775712 = 2.0;
        double r2775713 = 1.0;
        double r2775714 = -2.0;
        double r2775715 = x;
        double r2775716 = r2775714 * r2775715;
        double r2775717 = exp(r2775716);
        double r2775718 = r2775713 + r2775717;
        double r2775719 = r2775712 / r2775718;
        double r2775720 = r2775719 - r2775713;
        return r2775720;
}

double f(double x, double __attribute__((unused)) y) {
        double r2775721 = -2.0;
        double r2775722 = x;
        double r2775723 = r2775721 * r2775722;
        double r2775724 = -1972.3938625414924;
        bool r2775725 = r2775723 <= r2775724;
        double r2775726 = 2.0;
        double r2775727 = exp(r2775723);
        double r2775728 = 1.0;
        double r2775729 = r2775727 + r2775728;
        double r2775730 = sqrt(r2775729);
        double r2775731 = r2775726 / r2775730;
        double r2775732 = r2775731 / r2775730;
        double r2775733 = r2775732 - r2775728;
        double r2775734 = 0.0002071702113622589;
        bool r2775735 = r2775723 <= r2775734;
        double r2775736 = r2775722 * r2775722;
        double r2775737 = r2775736 * r2775722;
        double r2775738 = -0.3333333333333333;
        double r2775739 = 5.0;
        double r2775740 = pow(r2775722, r2775739);
        double r2775741 = 0.13333333333333333;
        double r2775742 = fma(r2775740, r2775741, r2775722);
        double r2775743 = fma(r2775737, r2775738, r2775742);
        double r2775744 = sqrt(r2775726);
        double r2775745 = r2775744 / r2775729;
        double r2775746 = -1.0;
        double r2775747 = fma(r2775744, r2775745, r2775746);
        double r2775748 = r2775735 ? r2775743 : r2775747;
        double r2775749 = r2775725 ? r2775733 : r2775748;
        return r2775749;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 3 regimes
  2. if (* -2 x) < -1972.3938625414924

    1. Initial program 0

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

      \[\leadsto \frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    4. Applied associate-/r*0

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

    if -1972.3938625414924 < (* -2 x) < 0.0002071702113622589

    1. Initial program 58.6

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

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

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

    if 0.0002071702113622589 < (* -2 x)

    1. Initial program 0.1

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied *-un-lft-identity0.1

      \[\leadsto \frac{2}{\color{blue}{1 \cdot \left(1 + e^{-2 \cdot x}\right)}} - 1\]
    4. Applied add-sqr-sqrt0.1

      \[\leadsto \frac{\color{blue}{\sqrt{2} \cdot \sqrt{2}}}{1 \cdot \left(1 + e^{-2 \cdot x}\right)} - 1\]
    5. Applied times-frac0.1

      \[\leadsto \color{blue}{\frac{\sqrt{2}}{1} \cdot \frac{\sqrt{2}}{1 + e^{-2 \cdot x}}} - 1\]
    6. Applied fma-neg0.1

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

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

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

Reproduce

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