Average Error: 29.6 → 1.4
Time: 10.9s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -95920403938297937322311680 \lor \neg \left(-2 \cdot x \le 3.196125594223232866536443808058720605914 \cdot 10^{-4}\right):\\ \;\;\;\;\left(\sqrt[3]{\frac{2}{1 + e^{-2 \cdot x}} - 1} \cdot \sqrt[3]{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right) \cdot \sqrt[3]{\frac{2}{1 + e^{-2 \cdot x}} - 1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -95920403938297937322311680 \lor \neg \left(-2 \cdot x \le 3.196125594223232866536443808058720605914 \cdot 10^{-4}\right):\\
\;\;\;\;\left(\sqrt[3]{\frac{2}{1 + e^{-2 \cdot x}} - 1} \cdot \sqrt[3]{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right) \cdot \sqrt[3]{\frac{2}{1 + e^{-2 \cdot x}} - 1}\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r31327 = 2.0;
        double r31328 = 1.0;
        double r31329 = -2.0;
        double r31330 = x;
        double r31331 = r31329 * r31330;
        double r31332 = exp(r31331);
        double r31333 = r31328 + r31332;
        double r31334 = r31327 / r31333;
        double r31335 = r31334 - r31328;
        return r31335;
}

double f(double x, double __attribute__((unused)) y) {
        double r31336 = -2.0;
        double r31337 = x;
        double r31338 = r31336 * r31337;
        double r31339 = -9.592040393829794e+25;
        bool r31340 = r31338 <= r31339;
        double r31341 = 0.0003196125594223233;
        bool r31342 = r31338 <= r31341;
        double r31343 = !r31342;
        bool r31344 = r31340 || r31343;
        double r31345 = 2.0;
        double r31346 = 1.0;
        double r31347 = exp(r31338);
        double r31348 = r31346 + r31347;
        double r31349 = r31345 / r31348;
        double r31350 = r31349 - r31346;
        double r31351 = cbrt(r31350);
        double r31352 = r31351 * r31351;
        double r31353 = r31352 * r31351;
        double r31354 = 5.551115123125783e-17;
        double r31355 = 4.0;
        double r31356 = pow(r31337, r31355);
        double r31357 = 0.33333333333333337;
        double r31358 = 3.0;
        double r31359 = pow(r31337, r31358);
        double r31360 = r31357 * r31359;
        double r31361 = fma(r31354, r31356, r31360);
        double r31362 = -r31361;
        double r31363 = fma(r31346, r31337, r31362);
        double r31364 = r31344 ? r31353 : r31363;
        return r31364;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -9.592040393829794e+25 or 0.0003196125594223233 < (* -2.0 x)

    1. Initial program 0.0

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

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

    if -9.592040393829794e+25 < (* -2.0 x) < 0.0003196125594223233

    1. Initial program 56.8

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.4

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

Reproduce

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