Average Error: 29.4 → 0.4
Time: 3.1s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -55422.43288444895006250590085983276367188 \lor \neg \left(-2 \cdot x \le 1.186352449555409772300601511929585285543 \cdot 10^{-4}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -55422.43288444895006250590085983276367188 \lor \neg \left(-2 \cdot x \le 1.186352449555409772300601511929585285543 \cdot 10^{-4}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r45863 = 2.0;
        double r45864 = 1.0;
        double r45865 = -2.0;
        double r45866 = x;
        double r45867 = r45865 * r45866;
        double r45868 = exp(r45867);
        double r45869 = r45864 + r45868;
        double r45870 = r45863 / r45869;
        double r45871 = r45870 - r45864;
        return r45871;
}

double f(double x, double __attribute__((unused)) y) {
        double r45872 = -2.0;
        double r45873 = x;
        double r45874 = r45872 * r45873;
        double r45875 = -55422.43288444895;
        bool r45876 = r45874 <= r45875;
        double r45877 = 0.00011863524495554098;
        bool r45878 = r45874 <= r45877;
        double r45879 = !r45878;
        bool r45880 = r45876 || r45879;
        double r45881 = 1.0;
        double r45882 = 1.0;
        double r45883 = exp(r45874);
        double r45884 = r45882 + r45883;
        double r45885 = sqrt(r45884);
        double r45886 = r45881 / r45885;
        double r45887 = 2.0;
        double r45888 = r45887 / r45885;
        double r45889 = -r45882;
        double r45890 = fma(r45886, r45888, r45889);
        double r45891 = 5.551115123125783e-17;
        double r45892 = 4.0;
        double r45893 = pow(r45873, r45892);
        double r45894 = 0.33333333333333337;
        double r45895 = 3.0;
        double r45896 = pow(r45873, r45895);
        double r45897 = r45894 * r45896;
        double r45898 = fma(r45891, r45893, r45897);
        double r45899 = -r45898;
        double r45900 = fma(r45882, r45873, r45899);
        double r45901 = r45880 ? r45890 : r45900;
        return r45901;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -55422.43288444895 or 0.00011863524495554098 < (* -2.0 x)

    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 *-un-lft-identity0.0

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

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

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

    if -55422.43288444895 < (* -2.0 x) < 0.00011863524495554098

    1. Initial program 58.5

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

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

      \[\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)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

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

Reproduce

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