Average Error: 29.0 → 0.0
Time: 13.4s
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}}, \mathsf{fma}\left(1, 1, e^{-2 \cdot x} \cdot \left(e^{-2 \cdot x} - 1\right)\right), -1\right)\right)}\\ \mathbf{elif}\;-2 \cdot x \le 1.11971615771184669 \cdot 10^{-4}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \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}}, \mathsf{fma}\left(1, 1, e^{-2 \cdot x} \cdot \left(e^{-2 \cdot x} - 1\right)\right), -1\right)\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r39668 = 2.0;
        double r39669 = 1.0;
        double r39670 = -2.0;
        double r39671 = x;
        double r39672 = r39670 * r39671;
        double r39673 = exp(r39672);
        double r39674 = r39669 + r39673;
        double r39675 = r39668 / r39674;
        double r39676 = r39675 - r39669;
        return r39676;
}

double f(double x, double __attribute__((unused)) y) {
        double r39677 = -2.0;
        double r39678 = x;
        double r39679 = r39677 * r39678;
        double r39680 = -0.0010666532697164817;
        bool r39681 = r39679 <= r39680;
        double r39682 = 2.0;
        double r39683 = 1.0;
        double r39684 = 3.0;
        double r39685 = pow(r39683, r39684);
        double r39686 = exp(r39679);
        double r39687 = pow(r39686, r39684);
        double r39688 = r39685 + r39687;
        double r39689 = r39682 / r39688;
        double r39690 = r39686 - r39683;
        double r39691 = r39686 * r39690;
        double r39692 = fma(r39683, r39683, r39691);
        double r39693 = -r39683;
        double r39694 = fma(r39689, r39692, r39693);
        double r39695 = log(r39694);
        double r39696 = exp(r39695);
        double r39697 = 0.00011197161577118467;
        bool r39698 = r39679 <= r39697;
        double r39699 = r39683 * r39678;
        double r39700 = 5.551115123125783e-17;
        double r39701 = 4.0;
        double r39702 = pow(r39678, r39701);
        double r39703 = 0.33333333333333337;
        double r39704 = pow(r39678, r39684);
        double r39705 = r39703 * r39704;
        double r39706 = fma(r39700, r39702, r39705);
        double r39707 = r39699 - r39706;
        double r39708 = r39683 + r39686;
        double r39709 = r39682 / r39708;
        double r39710 = r39709 - r39683;
        double r39711 = exp(r39710);
        double r39712 = log(r39711);
        double r39713 = r39698 ? r39707 : r39712;
        double r39714 = r39681 ? r39696 : r39713;
        return r39714;
}

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)}}\]
    8. Simplified0.1

      \[\leadsto e^{\color{blue}{\log \left(\mathsf{fma}\left(\frac{2}{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}, \mathsf{fma}\left(1, 1, e^{-2 \cdot x} \cdot \left(e^{-2 \cdot x} - 1\right)\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}{1 \cdot x - \mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\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-log-exp0.1

      \[\leadsto \frac{2}{1 + e^{-2 \cdot x}} - \color{blue}{\log \left(e^{1}\right)}\]
    4. Applied add-log-exp0.1

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

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

      \[\leadsto \log \color{blue}{\left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)}\]
  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}}, \mathsf{fma}\left(1, 1, e^{-2 \cdot x} \cdot \left(e^{-2 \cdot x} - 1\right)\right), -1\right)\right)}\\ \mathbf{elif}\;-2 \cdot x \le 1.11971615771184669 \cdot 10^{-4}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \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))