Average Error: 28.8 → 0.1
Time: 7.2s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.002635842201220140595951946238528762478381:\\ \;\;\;\;\mathsf{fma}\left(\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}}, \sqrt{1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right)}, -1\right)\\ \mathbf{elif}\;-2 \cdot x \le 2.54615102978797293259243233326527544591 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{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 -0.002635842201220140595951946238528762478381:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}}, \sqrt{1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right)}, -1\right)\\

\mathbf{elif}\;-2 \cdot x \le 2.54615102978797293259243233326527544591 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r87700 = 2.0;
        double r87701 = 1.0;
        double r87702 = -2.0;
        double r87703 = x;
        double r87704 = r87702 * r87703;
        double r87705 = exp(r87704);
        double r87706 = r87701 + r87705;
        double r87707 = r87700 / r87706;
        double r87708 = r87707 - r87701;
        return r87708;
}

double f(double x, double __attribute__((unused)) y) {
        double r87709 = -2.0;
        double r87710 = x;
        double r87711 = r87709 * r87710;
        double r87712 = -0.0026358422012201406;
        bool r87713 = r87711 <= r87712;
        double r87714 = 2.0;
        double r87715 = 1.0;
        double r87716 = exp(r87711);
        double r87717 = r87715 + r87716;
        double r87718 = sqrt(r87717);
        double r87719 = r87714 / r87718;
        double r87720 = 3.0;
        double r87721 = pow(r87715, r87720);
        double r87722 = pow(r87716, r87720);
        double r87723 = r87721 + r87722;
        double r87724 = sqrt(r87723);
        double r87725 = r87719 / r87724;
        double r87726 = r87715 * r87715;
        double r87727 = r87716 * r87716;
        double r87728 = r87715 * r87716;
        double r87729 = r87727 - r87728;
        double r87730 = r87726 + r87729;
        double r87731 = sqrt(r87730);
        double r87732 = -r87715;
        double r87733 = fma(r87725, r87731, r87732);
        double r87734 = 2.546151029787973e-07;
        bool r87735 = r87711 <= r87734;
        double r87736 = 5.551115123125783e-17;
        double r87737 = 4.0;
        double r87738 = pow(r87710, r87737);
        double r87739 = 0.33333333333333337;
        double r87740 = pow(r87710, r87720);
        double r87741 = r87739 * r87740;
        double r87742 = fma(r87736, r87738, r87741);
        double r87743 = -r87742;
        double r87744 = fma(r87715, r87710, r87743);
        double r87745 = r87719 / r87718;
        double r87746 = r87745 - r87715;
        double r87747 = r87735 ? r87744 : r87746;
        double r87748 = r87713 ? r87733 : r87747;
        return r87748;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0.0

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

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

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

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

      \[\leadsto \frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\color{blue}{\frac{\sqrt{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}}{\sqrt{1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right)}}}} - 1\]
    8. Applied associate-/r/0.0

      \[\leadsto \color{blue}{\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}} \cdot \sqrt{1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right)}} - 1\]
    9. Applied fma-neg0.0

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

    if -0.0026358422012201406 < (* -2.0 x) < 2.546151029787973e-07

    1. Initial program 59.5

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

      \[\leadsto \color{blue}{1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)}\]
    3. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\right)}\]

    if 2.546151029787973e-07 < (* -2.0 x)

    1. Initial program 0.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.002635842201220140595951946238528762478381:\\ \;\;\;\;\mathsf{fma}\left(\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}}, \sqrt{1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right)}, -1\right)\\ \mathbf{elif}\;-2 \cdot x \le 2.54615102978797293259243233326527544591 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\ \end{array}\]

Reproduce

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