Average Error: 29.1 → 0.4
Time: 4.5s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -14207516.1141591389 \lor \neg \left(-2 \cdot x \le 3.6425271859424674 \cdot 10^{-6}\right):\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -14207516.1141591389 \lor \neg \left(-2 \cdot x \le 3.6425271859424674 \cdot 10^{-6}\right):\\
\;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r50775 = 2.0;
        double r50776 = 1.0;
        double r50777 = -2.0;
        double r50778 = x;
        double r50779 = r50777 * r50778;
        double r50780 = exp(r50779);
        double r50781 = r50776 + r50780;
        double r50782 = r50775 / r50781;
        double r50783 = r50782 - r50776;
        return r50783;
}

double f(double x, double __attribute__((unused)) y) {
        double r50784 = -2.0;
        double r50785 = x;
        double r50786 = r50784 * r50785;
        double r50787 = -14207516.114159139;
        bool r50788 = r50786 <= r50787;
        double r50789 = 3.6425271859424674e-06;
        bool r50790 = r50786 <= r50789;
        double r50791 = !r50790;
        bool r50792 = r50788 || r50791;
        double r50793 = 2.0;
        double r50794 = 1.0;
        double r50795 = exp(r50786);
        double r50796 = r50794 + r50795;
        double r50797 = sqrt(r50796);
        double r50798 = r50793 / r50797;
        double r50799 = r50798 / r50797;
        double r50800 = r50799 - r50794;
        double r50801 = 5.551115123125783e-17;
        double r50802 = 4.0;
        double r50803 = pow(r50785, r50802);
        double r50804 = 0.33333333333333337;
        double r50805 = 3.0;
        double r50806 = pow(r50785, r50805);
        double r50807 = r50804 * r50806;
        double r50808 = fma(r50801, r50803, r50807);
        double r50809 = -r50808;
        double r50810 = fma(r50794, r50785, r50809);
        double r50811 = r50792 ? r50800 : r50810;
        return r50811;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0.1

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

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

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

    if -14207516.114159139 < (* -2.0 x) < 3.6425271859424674e-06

    1. Initial program 58.3

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

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

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

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

Reproduce

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