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

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r50263 = 2.0;
        double r50264 = 1.0;
        double r50265 = -2.0;
        double r50266 = x;
        double r50267 = r50265 * r50266;
        double r50268 = exp(r50267);
        double r50269 = r50264 + r50268;
        double r50270 = r50263 / r50269;
        double r50271 = r50270 - r50264;
        return r50271;
}

double f(double x, double __attribute__((unused)) y) {
        double r50272 = -2.0;
        double r50273 = x;
        double r50274 = r50272 * r50273;
        double r50275 = -25682837.73154429;
        bool r50276 = r50274 <= r50275;
        double r50277 = 2.0;
        double r50278 = 1.0;
        double r50279 = exp(r50274);
        double r50280 = r50278 + r50279;
        double r50281 = r50277 / r50280;
        double r50282 = r50281 - r50278;
        double r50283 = exp(r50282);
        double r50284 = log(r50283);
        double r50285 = 5.646048818049403e-09;
        bool r50286 = r50274 <= r50285;
        double r50287 = r50278 * r50273;
        double r50288 = 5.551115123125783e-17;
        double r50289 = 4.0;
        double r50290 = pow(r50273, r50289);
        double r50291 = 0.33333333333333337;
        double r50292 = 3.0;
        double r50293 = pow(r50273, r50292);
        double r50294 = r50291 * r50293;
        double r50295 = fma(r50288, r50290, r50294);
        double r50296 = r50287 - r50295;
        double r50297 = r50281 * r50281;
        double r50298 = r50278 * r50278;
        double r50299 = r50297 - r50298;
        double r50300 = 1.0;
        double r50301 = cbrt(r50280);
        double r50302 = r50300 / r50301;
        double r50303 = r50302 / r50301;
        double r50304 = sqrt(r50301);
        double r50305 = r50304 * r50304;
        double r50306 = r50277 / r50305;
        double r50307 = r50303 * r50306;
        double r50308 = r50307 + r50278;
        double r50309 = r50299 / r50308;
        double r50310 = r50286 ? r50296 : r50309;
        double r50311 = r50276 ? r50284 : r50310;
        return r50311;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied flip--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. Using strategy rm
    5. Applied add-log-exp0

      \[\leadsto \color{blue}{\log \left(e^{\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}}\right)}\]
    6. Simplified0

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

    if -25682837.73154429 < (* -2.0 x) < 5.646048818049403e-09

    1. Initial program 58.5

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

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

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

    if 5.646048818049403e-09 < (* -2.0 x)

    1. Initial program 0.4

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

      \[\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. Using strategy rm
    5. Applied add-cube-cbrt0.4

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

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

      \[\leadsto \frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\color{blue}{\frac{1}{\sqrt[3]{1 + e^{-2 \cdot x}} \cdot \sqrt[3]{1 + e^{-2 \cdot x}}} \cdot \frac{2}{\sqrt[3]{1 + e^{-2 \cdot x}}}} + 1}\]
    8. Simplified0.4

      \[\leadsto \frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\color{blue}{\frac{\frac{1}{\sqrt[3]{1 + e^{-2 \cdot x}}}}{\sqrt[3]{1 + e^{-2 \cdot x}}}} \cdot \frac{2}{\sqrt[3]{1 + e^{-2 \cdot x}}} + 1}\]
    9. Using strategy rm
    10. Applied add-sqr-sqrt0.4

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

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

Reproduce

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