Average Error: 29.0 → 0.0
Time: 5.3s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.0010666532697164817:\\ \;\;\;\;e^{\log \left(\mathsf{fma}\left(\frac{2}{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}, 1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right), -1\right)\right)}\\ \mathbf{elif}\;-2 \cdot x \le 1.11971615771184669 \cdot 10^{-4}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.0010666532697164817:\\
\;\;\;\;e^{\log \left(\mathsf{fma}\left(\frac{2}{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}, 1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right), -1\right)\right)}\\

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r55587 = 2.0;
        double r55588 = 1.0;
        double r55589 = -2.0;
        double r55590 = x;
        double r55591 = r55589 * r55590;
        double r55592 = exp(r55591);
        double r55593 = r55588 + r55592;
        double r55594 = r55587 / r55593;
        double r55595 = r55594 - r55588;
        return r55595;
}

double f(double x, double __attribute__((unused)) y) {
        double r55596 = -2.0;
        double r55597 = x;
        double r55598 = r55596 * r55597;
        double r55599 = -0.0010666532697164817;
        bool r55600 = r55598 <= r55599;
        double r55601 = 2.0;
        double r55602 = 1.0;
        double r55603 = 3.0;
        double r55604 = pow(r55602, r55603);
        double r55605 = exp(r55598);
        double r55606 = pow(r55605, r55603);
        double r55607 = r55604 + r55606;
        double r55608 = r55601 / r55607;
        double r55609 = r55602 * r55602;
        double r55610 = r55605 * r55605;
        double r55611 = r55602 * r55605;
        double r55612 = r55610 - r55611;
        double r55613 = r55609 + r55612;
        double r55614 = -r55602;
        double r55615 = fma(r55608, r55613, r55614);
        double r55616 = log(r55615);
        double r55617 = exp(r55616);
        double r55618 = 0.00011197161577118467;
        bool r55619 = r55598 <= r55618;
        double r55620 = 5.551115123125783e-17;
        double r55621 = 4.0;
        double r55622 = pow(r55597, r55621);
        double r55623 = 0.33333333333333337;
        double r55624 = pow(r55597, r55603);
        double r55625 = r55623 * r55624;
        double r55626 = fma(r55620, r55622, r55625);
        double r55627 = -r55626;
        double r55628 = fma(r55602, r55597, r55627);
        double r55629 = r55602 + r55605;
        double r55630 = sqrt(r55629);
        double r55631 = r55601 / r55630;
        double r55632 = r55631 / r55630;
        double r55633 = r55632 - r55602;
        double r55634 = r55619 ? r55628 : r55633;
        double r55635 = r55600 ? r55617 : r55634;
        return r55635;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 3 regimes
  2. if (* -2.0 x) < -0.0010666532697164817

    1. Initial program 0.1

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

      \[\leadsto \frac{2}{\color{blue}{\frac{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}{1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right)}}} - 1\]
    4. Applied associate-/r/0.1

      \[\leadsto \color{blue}{\frac{2}{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}} \cdot \left(1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right)\right)} - 1\]
    5. Applied fma-neg0.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{2}{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}, 1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right), -1\right)}\]
    6. Using strategy rm
    7. Applied add-exp-log0.1

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

    if -0.0010666532697164817 < (* -2.0 x) < 0.00011197161577118467

    1. Initial program 59.2

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

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

      \[\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)}\]

    if 0.00011197161577118467 < (* -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\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.0

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

Reproduce

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