Average Error: 29.2 → 0.2
Time: 17.0s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -30.01217653759367109955746855121105909348:\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\ \mathbf{elif}\;-2 \cdot x \le 1.928362974497356761681291295595919166317 \cdot 10^{-6}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}} \cdot \sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}}{\left|\sqrt[3]{1 + e^{-2 \cdot x}}\right|}, \frac{\sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}}{\sqrt{\sqrt[3]{1 + e^{-2 \cdot x}}}}, -1\right) + \left(1 + \left(-1\right)\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -30.01217653759367109955746855121105909348:\\
\;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}} \cdot \sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}}{\left|\sqrt[3]{1 + e^{-2 \cdot x}}\right|}, \frac{\sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}}{\sqrt{\sqrt[3]{1 + e^{-2 \cdot x}}}}, -1\right) + \left(1 + \left(-1\right)\right)\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r41555 = 2.0;
        double r41556 = 1.0;
        double r41557 = -2.0;
        double r41558 = x;
        double r41559 = r41557 * r41558;
        double r41560 = exp(r41559);
        double r41561 = r41556 + r41560;
        double r41562 = r41555 / r41561;
        double r41563 = r41562 - r41556;
        return r41563;
}

double f(double x, double __attribute__((unused)) y) {
        double r41564 = -2.0;
        double r41565 = x;
        double r41566 = r41564 * r41565;
        double r41567 = -30.01217653759367;
        bool r41568 = r41566 <= r41567;
        double r41569 = 2.0;
        double r41570 = 1.0;
        double r41571 = exp(r41566);
        double r41572 = r41570 + r41571;
        double r41573 = sqrt(r41572);
        double r41574 = r41569 / r41573;
        double r41575 = r41574 / r41573;
        double r41576 = r41575 - r41570;
        double r41577 = 1.9283629744973568e-06;
        bool r41578 = r41566 <= r41577;
        double r41579 = r41570 * r41565;
        double r41580 = 5.551115123125783e-17;
        double r41581 = 4.0;
        double r41582 = pow(r41565, r41581);
        double r41583 = 0.33333333333333337;
        double r41584 = 3.0;
        double r41585 = pow(r41565, r41584);
        double r41586 = r41583 * r41585;
        double r41587 = fma(r41580, r41582, r41586);
        double r41588 = r41579 - r41587;
        double r41589 = cbrt(r41574);
        double r41590 = r41589 * r41589;
        double r41591 = cbrt(r41572);
        double r41592 = fabs(r41591);
        double r41593 = r41590 / r41592;
        double r41594 = sqrt(r41591);
        double r41595 = r41589 / r41594;
        double r41596 = -r41570;
        double r41597 = fma(r41593, r41595, r41596);
        double r41598 = r41570 + r41596;
        double r41599 = r41597 + r41598;
        double r41600 = r41578 ? r41588 : r41599;
        double r41601 = r41568 ? r41576 : r41600;
        return r41601;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    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 associate-/r*0.0

      \[\leadsto \color{blue}{\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}}} - 1\]

    if -30.01217653759367 < (* -2.0 x) < 1.9283629744973568e-06

    1. Initial program 59.0

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

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

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

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

    1. Initial program 0.2

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

      \[\leadsto \frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    4. Applied associate-/r*0.2

      \[\leadsto \color{blue}{\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    5. Using strategy rm
    6. Applied add-cube-cbrt0.2

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

      \[\leadsto \frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{\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}}}}} - \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}\]
    8. Applied sqrt-prod0.2

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}} \cdot \sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}}{\sqrt{\sqrt[3]{1 + e^{-2 \cdot x}} \cdot \sqrt[3]{1 + e^{-2 \cdot x}}}}, \frac{\sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}}{\sqrt{\sqrt[3]{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)}\]
    12. Simplified0.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}} \cdot \sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}}{\left|\sqrt[3]{1 + e^{-2 \cdot x}}\right|}, \frac{\sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}}{\sqrt{\sqrt[3]{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)\]
    13. Simplified0.2

      \[\leadsto \mathsf{fma}\left(\frac{\sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}} \cdot \sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}}{\left|\sqrt[3]{1 + e^{-2 \cdot x}}\right|}, \frac{\sqrt[3]{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}}{\sqrt{\sqrt[3]{1 + e^{-2 \cdot x}}}}, -1\right) + \color{blue}{\left(1 + \left(-1\right)\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

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

Reproduce

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