Average Error: 29.0 → 0.3
Time: 9.8s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -57837.87936140412784880027174949645996094 \lor \neg \left(-2 \cdot x \le 5.996013450899827812467547671904100070606 \cdot 10^{-6}\right):\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 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 -57837.87936140412784880027174949645996094 \lor \neg \left(-2 \cdot x \le 5.996013450899827812467547671904100070606 \cdot 10^{-6}\right):\\
\;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 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 r44759 = 2.0;
        double r44760 = 1.0;
        double r44761 = -2.0;
        double r44762 = x;
        double r44763 = r44761 * r44762;
        double r44764 = exp(r44763);
        double r44765 = r44760 + r44764;
        double r44766 = r44759 / r44765;
        double r44767 = r44766 - r44760;
        return r44767;
}

double f(double x, double __attribute__((unused)) y) {
        double r44768 = -2.0;
        double r44769 = x;
        double r44770 = r44768 * r44769;
        double r44771 = -57837.87936140413;
        bool r44772 = r44770 <= r44771;
        double r44773 = 5.996013450899828e-06;
        bool r44774 = r44770 <= r44773;
        double r44775 = !r44774;
        bool r44776 = r44772 || r44775;
        double r44777 = 2.0;
        double r44778 = exp(r44770);
        double r44779 = 1.0;
        double r44780 = r44778 + r44779;
        double r44781 = r44777 / r44780;
        double r44782 = r44781 - r44779;
        double r44783 = 5.551115123125783e-17;
        double r44784 = 4.0;
        double r44785 = pow(r44769, r44784);
        double r44786 = 0.33333333333333337;
        double r44787 = 3.0;
        double r44788 = pow(r44769, r44787);
        double r44789 = r44786 * r44788;
        double r44790 = fma(r44783, r44785, r44789);
        double r44791 = -r44790;
        double r44792 = fma(r44779, r44769, r44791);
        double r44793 = r44776 ? r44782 : r44792;
        return r44793;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -57837.87936140413 or 5.996013450899828e-06 < (* -2.0 x)

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{2 \cdot \frac{1}{e^{-2 \cdot x} + 1} - 1}\]
    3. Simplified0.0

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

    if -57837.87936140413 < (* -2.0 x) < 5.996013450899828e-06

    1. Initial program 58.7

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

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

      \[\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 simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -57837.87936140412784880027174949645996094 \lor \neg \left(-2 \cdot x \le 5.996013450899827812467547671904100070606 \cdot 10^{-6}\right):\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 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 2019212 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  :precision binary64
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))