Average Error: 29.0 → 0.1
Time: 20.1s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.16694293117624887 \lor \neg \left(-2 \cdot x \le 1.3471487435038969 \cdot 10^{-8}\right):\\ \;\;\;\;\left(\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1\right) \cdot \frac{1}{\frac{2}{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 -0.16694293117624887 \lor \neg \left(-2 \cdot x \le 1.3471487435038969 \cdot 10^{-8}\right):\\
\;\;\;\;\left(\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1\right) \cdot \frac{1}{\frac{2}{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 r55585 = 2.0;
        double r55586 = 1.0;
        double r55587 = -2.0;
        double r55588 = x;
        double r55589 = r55587 * r55588;
        double r55590 = exp(r55589);
        double r55591 = r55586 + r55590;
        double r55592 = r55585 / r55591;
        double r55593 = r55592 - r55586;
        return r55593;
}

double f(double x, double __attribute__((unused)) y) {
        double r55594 = -2.0;
        double r55595 = x;
        double r55596 = r55594 * r55595;
        double r55597 = -0.16694293117624887;
        bool r55598 = r55596 <= r55597;
        double r55599 = 1.3471487435038969e-08;
        bool r55600 = r55596 <= r55599;
        double r55601 = !r55600;
        bool r55602 = r55598 || r55601;
        double r55603 = 2.0;
        double r55604 = 1.0;
        double r55605 = exp(r55596);
        double r55606 = r55604 + r55605;
        double r55607 = r55603 / r55606;
        double r55608 = r55607 * r55607;
        double r55609 = r55604 * r55604;
        double r55610 = r55608 - r55609;
        double r55611 = 1.0;
        double r55612 = r55607 + r55604;
        double r55613 = r55611 / r55612;
        double r55614 = r55610 * r55613;
        double r55615 = 5.551115123125783e-17;
        double r55616 = 4.0;
        double r55617 = pow(r55595, r55616);
        double r55618 = 0.33333333333333337;
        double r55619 = 3.0;
        double r55620 = pow(r55595, r55619);
        double r55621 = r55618 * r55620;
        double r55622 = fma(r55615, r55617, r55621);
        double r55623 = -r55622;
        double r55624 = fma(r55604, r55595, r55623);
        double r55625 = r55602 ? r55614 : r55624;
        return r55625;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -0.16694293117624887 or 1.3471487435038969e-08 < (* -2.0 x)

    1. Initial program 0.2

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

      \[\leadsto \color{blue}{\frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\frac{2}{1 + e^{-2 \cdot x}} + 1}}\]
    4. Using strategy rm
    5. Applied div-inv0.2

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

    if -0.16694293117624887 < (* -2.0 x) < 1.3471487435038969e-08

    1. Initial program 59.4

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

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

      \[\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.1

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