Average Error: 29.3 → 0.2
Time: 15.5s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -107280.0323081880924291908740997314453125:\\ \;\;\;\;\frac{\frac{2}{\sqrt{e^{-2 \cdot x} + 1}}}{\sqrt{e^{-2 \cdot x} + 1}} - 1\\ \mathbf{elif}\;-2 \cdot x \le 9.922166503853619421490067642466215147579 \cdot 10^{-5}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, \left(x \cdot x\right) \cdot \left(x \cdot x\right), \left(0.3333333333333333703407674875052180141211 \cdot x\right) \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{\sqrt{e^{-2 \cdot x} + 1}}}{\sqrt{e^{-2 \cdot x} + 1}} - 1\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -107280.0323081880924291908740997314453125:\\
\;\;\;\;\frac{\frac{2}{\sqrt{e^{-2 \cdot x} + 1}}}{\sqrt{e^{-2 \cdot x} + 1}} - 1\\

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r2143566 = 2.0;
        double r2143567 = 1.0;
        double r2143568 = -2.0;
        double r2143569 = x;
        double r2143570 = r2143568 * r2143569;
        double r2143571 = exp(r2143570);
        double r2143572 = r2143567 + r2143571;
        double r2143573 = r2143566 / r2143572;
        double r2143574 = r2143573 - r2143567;
        return r2143574;
}

double f(double x, double __attribute__((unused)) y) {
        double r2143575 = -2.0;
        double r2143576 = x;
        double r2143577 = r2143575 * r2143576;
        double r2143578 = -107280.03230818809;
        bool r2143579 = r2143577 <= r2143578;
        double r2143580 = 2.0;
        double r2143581 = exp(r2143577);
        double r2143582 = 1.0;
        double r2143583 = r2143581 + r2143582;
        double r2143584 = sqrt(r2143583);
        double r2143585 = r2143580 / r2143584;
        double r2143586 = r2143585 / r2143584;
        double r2143587 = r2143586 - r2143582;
        double r2143588 = 9.92216650385362e-05;
        bool r2143589 = r2143577 <= r2143588;
        double r2143590 = r2143582 * r2143576;
        double r2143591 = 5.551115123125783e-17;
        double r2143592 = r2143576 * r2143576;
        double r2143593 = r2143592 * r2143592;
        double r2143594 = 0.33333333333333337;
        double r2143595 = r2143594 * r2143576;
        double r2143596 = r2143595 * r2143592;
        double r2143597 = fma(r2143591, r2143593, r2143596);
        double r2143598 = r2143590 - r2143597;
        double r2143599 = r2143589 ? r2143598 : r2143587;
        double r2143600 = r2143579 ? r2143587 : r2143599;
        return r2143600;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -107280.03230818809 or 9.92216650385362e-05 < (* -2.0 x)

    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 -107280.03230818809 < (* -2.0 x) < 9.92216650385362e-05

    1. Initial program 58.9

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019171 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))