Average Error: 29.6 → 0.1
Time: 11.7s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.6402867958490563449203136769938282668591:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)\right)\\ \mathbf{elif}\;-2 \cdot x \le 6.305606613254815869949905515756682916617 \cdot 10^{-7}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(6.938893903907228377647697925567626953125 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)}^{3}}\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.6402867958490563449203136769938282668591:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)\right)\\

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r55537 = 2.0;
        double r55538 = 1.0;
        double r55539 = -2.0;
        double r55540 = x;
        double r55541 = r55539 * r55540;
        double r55542 = exp(r55541);
        double r55543 = r55538 + r55542;
        double r55544 = r55537 / r55543;
        double r55545 = r55544 - r55538;
        return r55545;
}

double f(double x, double __attribute__((unused)) y) {
        double r55546 = -2.0;
        double r55547 = x;
        double r55548 = r55546 * r55547;
        double r55549 = -0.6402867958490563;
        bool r55550 = r55548 <= r55549;
        double r55551 = 2.0;
        double r55552 = 1.0;
        double r55553 = exp(r55548);
        double r55554 = r55552 + r55553;
        double r55555 = r55551 / r55554;
        double r55556 = r55555 - r55552;
        double r55557 = log1p(r55556);
        double r55558 = expm1(r55557);
        double r55559 = 6.305606613254816e-07;
        bool r55560 = r55548 <= r55559;
        double r55561 = r55552 * r55547;
        double r55562 = 6.938893903907228e-17;
        double r55563 = 4.0;
        double r55564 = pow(r55547, r55563);
        double r55565 = 0.33333333333333337;
        double r55566 = 3.0;
        double r55567 = pow(r55547, r55566);
        double r55568 = r55565 * r55567;
        double r55569 = fma(r55562, r55564, r55568);
        double r55570 = r55561 - r55569;
        double r55571 = pow(r55556, r55566);
        double r55572 = cbrt(r55571);
        double r55573 = r55560 ? r55570 : r55572;
        double r55574 = r55550 ? r55558 : r55573;
        return r55574;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0.0

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied expm1-log1p-u0.0

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

    if -0.6402867958490563 < (* -2.0 x) < 6.305606613254816e-07

    1. Initial program 59.3

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

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)\right)}\]
    4. Taylor expanded around 0 0.1

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

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

    if 6.305606613254816e-07 < (* -2.0 x)

    1. Initial program 0.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.6402867958490563449203136769938282668591:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)\right)\\ \mathbf{elif}\;-2 \cdot x \le 6.305606613254815869949905515756682916617 \cdot 10^{-7}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(6.938893903907228377647697925567626953125 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)}^{3}}\\ \end{array}\]

Reproduce

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