Average Error: 29.8 → 0.3
Time: 19.9s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -200852.6909306695160921663045883178710938 \lor \neg \left(-2 \cdot x \le 8.698543000047536614266485699431541434024 \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}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -200852.6909306695160921663045883178710938 \lor \neg \left(-2 \cdot x \le 8.698543000047536614266485699431541434024 \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}:\\
\;\;\;\;1 \cdot x - \mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r32119 = 2.0;
        double r32120 = 1.0;
        double r32121 = -2.0;
        double r32122 = x;
        double r32123 = r32121 * r32122;
        double r32124 = exp(r32123);
        double r32125 = r32120 + r32124;
        double r32126 = r32119 / r32125;
        double r32127 = r32126 - r32120;
        return r32127;
}

double f(double x, double __attribute__((unused)) y) {
        double r32128 = -2.0;
        double r32129 = x;
        double r32130 = r32128 * r32129;
        double r32131 = -200852.69093066952;
        bool r32132 = r32130 <= r32131;
        double r32133 = 0.0008698543000047537;
        bool r32134 = r32130 <= r32133;
        double r32135 = !r32134;
        bool r32136 = r32132 || r32135;
        double r32137 = 1.0;
        double r32138 = 1.0;
        double r32139 = exp(r32130);
        double r32140 = r32138 + r32139;
        double r32141 = sqrt(r32140);
        double r32142 = r32137 / r32141;
        double r32143 = 2.0;
        double r32144 = r32143 / r32141;
        double r32145 = -r32138;
        double r32146 = fma(r32142, r32144, r32145);
        double r32147 = r32138 * r32129;
        double r32148 = 5.551115123125783e-17;
        double r32149 = 4.0;
        double r32150 = pow(r32129, r32149);
        double r32151 = 0.33333333333333337;
        double r32152 = 3.0;
        double r32153 = pow(r32129, r32152);
        double r32154 = r32151 * r32153;
        double r32155 = fma(r32148, r32150, r32154);
        double r32156 = r32147 - r32155;
        double r32157 = r32136 ? r32146 : r32156;
        return r32157;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -200852.69093066952 or 0.0008698543000047537 < (* -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 -200852.69093066952 < (* -2.0 x) < 0.0008698543000047537

    1. Initial program 58.5

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

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

      \[\leadsto \color{blue}{1 \cdot x - \mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -200852.6909306695160921663045883178710938 \lor \neg \left(-2 \cdot x \le 8.698543000047536614266485699431541434024 \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}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \end{array}\]

Reproduce

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