Average Error: 29.8 → 0.3
Time: 19.5s
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 r36268 = 2.0;
        double r36269 = 1.0;
        double r36270 = -2.0;
        double r36271 = x;
        double r36272 = r36270 * r36271;
        double r36273 = exp(r36272);
        double r36274 = r36269 + r36273;
        double r36275 = r36268 / r36274;
        double r36276 = r36275 - r36269;
        return r36276;
}

double f(double x, double __attribute__((unused)) y) {
        double r36277 = -2.0;
        double r36278 = x;
        double r36279 = r36277 * r36278;
        double r36280 = -200852.69093066952;
        bool r36281 = r36279 <= r36280;
        double r36282 = 0.0008698543000047537;
        bool r36283 = r36279 <= r36282;
        double r36284 = !r36283;
        bool r36285 = r36281 || r36284;
        double r36286 = 1.0;
        double r36287 = 1.0;
        double r36288 = exp(r36279);
        double r36289 = r36287 + r36288;
        double r36290 = sqrt(r36289);
        double r36291 = r36286 / r36290;
        double r36292 = 2.0;
        double r36293 = r36292 / r36290;
        double r36294 = -r36287;
        double r36295 = fma(r36291, r36293, r36294);
        double r36296 = r36287 * r36278;
        double r36297 = 5.551115123125783e-17;
        double r36298 = 4.0;
        double r36299 = pow(r36278, r36298);
        double r36300 = 0.33333333333333337;
        double r36301 = 3.0;
        double r36302 = pow(r36278, r36301);
        double r36303 = r36300 * r36302;
        double r36304 = fma(r36297, r36299, r36303);
        double r36305 = r36296 - r36304;
        double r36306 = r36285 ? r36295 : r36305;
        return r36306;
}

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))