Average Error: 29.2 → 0.3
Time: 18.0s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -7479.799764354564103996381163597106933594 \lor \neg \left(-2 \cdot x \le 8.70697753800674634828830743637595283857 \cdot 10^{-11}\right):\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\ \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 -7479.799764354564103996381163597106933594 \lor \neg \left(-2 \cdot x \le 8.70697753800674634828830743637595283857 \cdot 10^{-11}\right):\\
\;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\

\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 r43500 = 2.0;
        double r43501 = 1.0;
        double r43502 = -2.0;
        double r43503 = x;
        double r43504 = r43502 * r43503;
        double r43505 = exp(r43504);
        double r43506 = r43501 + r43505;
        double r43507 = r43500 / r43506;
        double r43508 = r43507 - r43501;
        return r43508;
}

double f(double x, double __attribute__((unused)) y) {
        double r43509 = -2.0;
        double r43510 = x;
        double r43511 = r43509 * r43510;
        double r43512 = -7479.799764354564;
        bool r43513 = r43511 <= r43512;
        double r43514 = 8.706977538006746e-11;
        bool r43515 = r43511 <= r43514;
        double r43516 = !r43515;
        bool r43517 = r43513 || r43516;
        double r43518 = 2.0;
        double r43519 = 1.0;
        double r43520 = exp(r43511);
        double r43521 = r43519 + r43520;
        double r43522 = sqrt(r43521);
        double r43523 = r43518 / r43522;
        double r43524 = r43523 / r43522;
        double r43525 = r43524 - r43519;
        double r43526 = r43519 * r43510;
        double r43527 = 5.551115123125783e-17;
        double r43528 = 4.0;
        double r43529 = pow(r43510, r43528);
        double r43530 = 0.33333333333333337;
        double r43531 = 3.0;
        double r43532 = pow(r43510, r43531);
        double r43533 = r43530 * r43532;
        double r43534 = fma(r43527, r43529, r43533);
        double r43535 = r43526 - r43534;
        double r43536 = r43517 ? r43525 : r43535;
        return r43536;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -7479.799764354564 or 8.706977538006746e-11 < (* -2.0 x)

    1. Initial program 0.3

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

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

      \[\leadsto \frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} - \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}\]
    5. Applied add-sqr-sqrt1.1

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

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

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

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

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

    if -7479.799764354564 < (* -2.0 x) < 8.706977538006746e-11

    1. Initial program 59.1

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

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

      \[\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 -7479.799764354564103996381163597106933594 \lor \neg \left(-2 \cdot x \le 8.70697753800674634828830743637595283857 \cdot 10^{-11}\right):\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\ \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 2019326 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  :precision binary64
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))