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

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r58443 = 2.0;
        double r58444 = 1.0;
        double r58445 = -2.0;
        double r58446 = x;
        double r58447 = r58445 * r58446;
        double r58448 = exp(r58447);
        double r58449 = r58444 + r58448;
        double r58450 = r58443 / r58449;
        double r58451 = r58450 - r58444;
        return r58451;
}

double f(double x, double __attribute__((unused)) y) {
        double r58452 = -2.0;
        double r58453 = x;
        double r58454 = r58452 * r58453;
        double r58455 = -0.0014783414053817301;
        bool r58456 = r58454 <= r58455;
        double r58457 = 4.0;
        double r58458 = exp(r58454);
        double r58459 = 1.0;
        double r58460 = r58458 + r58459;
        double r58461 = 2.0;
        double r58462 = pow(r58460, r58461);
        double r58463 = r58457 / r58462;
        double r58464 = r58463 - r58459;
        double r58465 = 1.0;
        double r58466 = r58459 * r58459;
        double r58467 = r58458 * r58458;
        double r58468 = r58466 - r58467;
        double r58469 = sqrt(r58468);
        double r58470 = r58465 / r58469;
        double r58471 = r58459 - r58458;
        double r58472 = sqrt(r58471);
        double r58473 = 2.0;
        double r58474 = r58459 + r58458;
        double r58475 = sqrt(r58474);
        double r58476 = r58473 / r58475;
        double r58477 = r58472 * r58476;
        double r58478 = r58470 * r58477;
        double r58479 = r58478 + r58459;
        double r58480 = r58464 / r58479;
        double r58481 = 1.20204220238677e-06;
        bool r58482 = r58454 <= r58481;
        double r58483 = r58459 * r58453;
        double r58484 = 5.551115123125783e-17;
        double r58485 = 4.0;
        double r58486 = pow(r58453, r58485);
        double r58487 = 0.33333333333333337;
        double r58488 = 3.0;
        double r58489 = pow(r58453, r58488);
        double r58490 = r58487 * r58489;
        double r58491 = fma(r58484, r58486, r58490);
        double r58492 = r58483 - r58491;
        double r58493 = r58463 * r58463;
        double r58494 = r58493 - r58466;
        double r58495 = r58463 + r58459;
        double r58496 = r58494 / r58495;
        double r58497 = r58465 / r58475;
        double r58498 = r58497 * r58476;
        double r58499 = r58498 + r58459;
        double r58500 = r58496 / r58499;
        double r58501 = r58482 ? r58492 : r58500;
        double r58502 = r58456 ? r58480 : r58501;
        return r58502;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\frac{2}{1 + e^{-2 \cdot x}} + 1}}\]
    4. Taylor expanded around inf 0.0

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

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

      \[\leadsto \frac{\frac{4}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} - 1}{\frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} + 1}\]
    8. Applied *-un-lft-identity0.0

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

      \[\leadsto \frac{\frac{4}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} - 1}{\color{blue}{\frac{1}{\sqrt{1 + e^{-2 \cdot x}}} \cdot \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}} + 1}\]
    10. Using strategy rm
    11. Applied flip-+0.0

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

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

      \[\leadsto \frac{\frac{4}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} - 1}{\color{blue}{\left(\frac{1}{\sqrt{1 \cdot 1 - e^{-2 \cdot x} \cdot e^{-2 \cdot x}}} \cdot \sqrt{1 - e^{-2 \cdot x}}\right)} \cdot \frac{2}{\sqrt{1 + e^{-2 \cdot x}}} + 1}\]
    14. Applied associate-*l*0.0

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

    if -0.0014783414053817301 < (* -2.0 x) < 1.20204220238677e-06

    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}{1 \cdot x - \mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)}\]

    if 1.20204220238677e-06 < (* -2.0 x)

    1. Initial program 0.2

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

      \[\leadsto \color{blue}{\frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\frac{2}{1 + e^{-2 \cdot x}} + 1}}\]
    4. Taylor expanded around inf 0.2

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

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

      \[\leadsto \frac{\frac{4}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} - 1}{\frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} + 1}\]
    8. Applied *-un-lft-identity0.2

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

      \[\leadsto \frac{\frac{4}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} - 1}{\color{blue}{\frac{1}{\sqrt{1 + e^{-2 \cdot x}}} \cdot \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}} + 1}\]
    10. Using strategy rm
    11. Applied flip--0.2

      \[\leadsto \frac{\color{blue}{\frac{\frac{4}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} \cdot \frac{4}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} - 1 \cdot 1}{\frac{4}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} + 1}}}{\frac{1}{\sqrt{1 + e^{-2 \cdot x}}} \cdot \frac{2}{\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.001478341405381730123969052925758660421707:\\ \;\;\;\;\frac{\frac{4}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} - 1}{\frac{1}{\sqrt{1 \cdot 1 - e^{-2 \cdot x} \cdot e^{-2 \cdot x}}} \cdot \left(\sqrt{1 - e^{-2 \cdot x}} \cdot \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}\right) + 1}\\ \mathbf{elif}\;-2 \cdot x \le 1.202042202386769937275221194206142882877 \cdot 10^{-6}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{4}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} \cdot \frac{4}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} - 1 \cdot 1}{\frac{4}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} + 1}}{\frac{1}{\sqrt{1 + e^{-2 \cdot x}}} \cdot \frac{2}{\sqrt{1 + e^{-2 \cdot x}}} + 1}\\ \end{array}\]

Reproduce

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