Average Error: 29.4 → 0.2
Time: 4.0s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.448110715835612849 \lor \neg \left(-2 \cdot x \le 5.632744022585048 \cdot 10^{-10}\right):\\ \;\;\;\;\log \left(\frac{{\left(e^{\frac{2}{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}}\right)}^{\left(\mathsf{fma}\left(e^{-2 \cdot x}, e^{-2 \cdot x} - 1, 1 \cdot 1\right)\right)}}{e^{1}}\right)\\ \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.448110715835612849 \lor \neg \left(-2 \cdot x \le 5.632744022585048 \cdot 10^{-10}\right):\\
\;\;\;\;\log \left(\frac{{\left(e^{\frac{2}{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}}\right)}^{\left(\mathsf{fma}\left(e^{-2 \cdot x}, e^{-2 \cdot x} - 1, 1 \cdot 1\right)\right)}}{e^{1}}\right)\\

\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 r62149 = 2.0;
        double r62150 = 1.0;
        double r62151 = -2.0;
        double r62152 = x;
        double r62153 = r62151 * r62152;
        double r62154 = exp(r62153);
        double r62155 = r62150 + r62154;
        double r62156 = r62149 / r62155;
        double r62157 = r62156 - r62150;
        return r62157;
}

double f(double x, double __attribute__((unused)) y) {
        double r62158 = -2.0;
        double r62159 = x;
        double r62160 = r62158 * r62159;
        double r62161 = -0.44811071583561285;
        bool r62162 = r62160 <= r62161;
        double r62163 = 5.632744022585048e-10;
        bool r62164 = r62160 <= r62163;
        double r62165 = !r62164;
        bool r62166 = r62162 || r62165;
        double r62167 = 2.0;
        double r62168 = 1.0;
        double r62169 = 3.0;
        double r62170 = pow(r62168, r62169);
        double r62171 = exp(r62160);
        double r62172 = pow(r62171, r62169);
        double r62173 = r62170 + r62172;
        double r62174 = r62167 / r62173;
        double r62175 = exp(r62174);
        double r62176 = r62171 - r62168;
        double r62177 = r62168 * r62168;
        double r62178 = fma(r62171, r62176, r62177);
        double r62179 = pow(r62175, r62178);
        double r62180 = exp(r62168);
        double r62181 = r62179 / r62180;
        double r62182 = log(r62181);
        double r62183 = 5.551115123125783e-17;
        double r62184 = 4.0;
        double r62185 = pow(r62159, r62184);
        double r62186 = 0.33333333333333337;
        double r62187 = pow(r62159, r62169);
        double r62188 = r62186 * r62187;
        double r62189 = fma(r62183, r62185, r62188);
        double r62190 = -r62189;
        double r62191 = fma(r62168, r62159, r62190);
        double r62192 = r62166 ? r62182 : r62191;
        return r62192;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -0.44811071583561285 or 5.632744022585048e-10 < (* -2.0 x)

    1. Initial program 0.2

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

      \[\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/30.8

      \[\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-neg30.8

      \[\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-log-exp30.8

      \[\leadsto \color{blue}{\log \left(e^{\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.3

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

    if -0.44811071583561285 < (* -2.0 x) < 5.632744022585048e-10

    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.2

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