Average Error: 29.3 → 0.2
Time: 18.1s
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(\left(x \cdot x\right) \cdot x\right) \cdot 0.3333333333333333703407674875052180141211\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(\left(x \cdot x\right) \cdot x\right) \cdot 0.3333333333333333703407674875052180141211\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 r1786627 = 2.0;
        double r1786628 = 1.0;
        double r1786629 = -2.0;
        double r1786630 = x;
        double r1786631 = r1786629 * r1786630;
        double r1786632 = exp(r1786631);
        double r1786633 = r1786628 + r1786632;
        double r1786634 = r1786627 / r1786633;
        double r1786635 = r1786634 - r1786628;
        return r1786635;
}

double f(double x, double __attribute__((unused)) y) {
        double r1786636 = -2.0;
        double r1786637 = x;
        double r1786638 = r1786636 * r1786637;
        double r1786639 = -107280.03230818809;
        bool r1786640 = r1786638 <= r1786639;
        double r1786641 = 2.0;
        double r1786642 = exp(r1786638);
        double r1786643 = 1.0;
        double r1786644 = r1786642 + r1786643;
        double r1786645 = sqrt(r1786644);
        double r1786646 = r1786641 / r1786645;
        double r1786647 = r1786646 / r1786645;
        double r1786648 = r1786647 - r1786643;
        double r1786649 = 9.92216650385362e-05;
        bool r1786650 = r1786638 <= r1786649;
        double r1786651 = r1786643 * r1786637;
        double r1786652 = 5.551115123125783e-17;
        double r1786653 = r1786637 * r1786637;
        double r1786654 = r1786653 * r1786653;
        double r1786655 = r1786653 * r1786637;
        double r1786656 = 0.33333333333333337;
        double r1786657 = r1786655 * r1786656;
        double r1786658 = fma(r1786652, r1786654, r1786657);
        double r1786659 = r1786651 - r1786658;
        double r1786660 = r1786650 ? r1786659 : r1786648;
        double r1786661 = r1786640 ? r1786648 : r1786660;
        return r1786661;
}

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(x \cdot \left(x \cdot x\right)\right) \cdot 0.3333333333333333703407674875052180141211\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(\left(x \cdot x\right) \cdot x\right) \cdot 0.3333333333333333703407674875052180141211\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))