Average Error: 29.2 → 0.0
Time: 18.9s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.008058366041537793:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{elif}\;x \le 0.006522581402346801:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{3}, \left(x \cdot \left(x \cdot x\right)\right), \left(\mathsf{fma}\left(\left({x}^{5}\right), \frac{2}{15}, x\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\mathsf{fma}\left(\left(\mathsf{fma}\left(\left(e^{-2 \cdot x}\right), \left(e^{-2 \cdot x}\right), 1\right) - e^{-2 \cdot x}\right), \left(\frac{2}{\mathsf{fma}\left(\left(\sqrt{e^{-2 \cdot x}} \cdot e^{-2 \cdot x}\right), \left(\sqrt{e^{-2 \cdot x}} \cdot e^{-2 \cdot x}\right), 1\right)}\right), -1\right)}\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;x \le -0.008058366041537793:\\
\;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\

\mathbf{elif}\;x \le 0.006522581402346801:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{3}, \left(x \cdot \left(x \cdot x\right)\right), \left(\mathsf{fma}\left(\left({x}^{5}\right), \frac{2}{15}, x\right)\right)\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r1349169 = 2.0;
        double r1349170 = 1.0;
        double r1349171 = -2.0;
        double r1349172 = x;
        double r1349173 = r1349171 * r1349172;
        double r1349174 = exp(r1349173);
        double r1349175 = r1349170 + r1349174;
        double r1349176 = r1349169 / r1349175;
        double r1349177 = r1349176 - r1349170;
        return r1349177;
}

double f(double x, double __attribute__((unused)) y) {
        double r1349178 = x;
        double r1349179 = -0.008058366041537793;
        bool r1349180 = r1349178 <= r1349179;
        double r1349181 = 2.0;
        double r1349182 = -2.0;
        double r1349183 = r1349182 * r1349178;
        double r1349184 = exp(r1349183);
        double r1349185 = 1.0;
        double r1349186 = r1349184 + r1349185;
        double r1349187 = r1349181 / r1349186;
        double r1349188 = r1349187 - r1349185;
        double r1349189 = 0.006522581402346801;
        bool r1349190 = r1349178 <= r1349189;
        double r1349191 = -0.3333333333333333;
        double r1349192 = r1349178 * r1349178;
        double r1349193 = r1349178 * r1349192;
        double r1349194 = 5.0;
        double r1349195 = pow(r1349178, r1349194);
        double r1349196 = 0.13333333333333333;
        double r1349197 = fma(r1349195, r1349196, r1349178);
        double r1349198 = fma(r1349191, r1349193, r1349197);
        double r1349199 = fma(r1349184, r1349184, r1349185);
        double r1349200 = r1349199 - r1349184;
        double r1349201 = sqrt(r1349184);
        double r1349202 = r1349201 * r1349184;
        double r1349203 = fma(r1349202, r1349202, r1349185);
        double r1349204 = r1349181 / r1349203;
        double r1349205 = -1.0;
        double r1349206 = fma(r1349200, r1349204, r1349205);
        double r1349207 = exp(r1349206);
        double r1349208 = log(r1349207);
        double r1349209 = r1349190 ? r1349198 : r1349208;
        double r1349210 = r1349180 ? r1349188 : r1349209;
        return r1349210;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 3 regimes
  2. if x < -0.008058366041537793

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{2 \cdot \frac{1}{e^{-2 \cdot x} + 1} - 1}\]
    3. Simplified0.0

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

    if -0.008058366041537793 < x < 0.006522581402346801

    1. Initial program 59.0

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

      \[\leadsto \color{blue}{\left(x + \frac{2}{15} \cdot {x}^{5}\right) - \frac{1}{3} \cdot {x}^{3}}\]
    3. Simplified0.0

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

    if 0.006522581402346801 < x

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{2 \cdot \frac{1}{e^{-2 \cdot x} + 1} - 1}\]
    3. Simplified0.0

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

      \[\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\]
    6. Applied associate-/r/0.0

      \[\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\]
    7. Applied fma-neg0.0

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

      \[\leadsto \mathsf{fma}\left(\left(\frac{2}{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}\right), \left(1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right)\right), \color{blue}{-1}\right)\]
    9. Using strategy rm
    10. Applied add-log-exp0.0

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

      \[\leadsto \log \color{blue}{\left(e^{\mathsf{fma}\left(\left(\mathsf{fma}\left(\left(e^{-2 \cdot x}\right), \left(e^{-2 \cdot x}\right), 1\right) - e^{-2 \cdot x}\right), \left(\frac{2}{\mathsf{fma}\left(\left(\sqrt{e^{-2 \cdot x}} \cdot e^{-2 \cdot x}\right), \left(\sqrt{e^{-2 \cdot x}} \cdot e^{-2 \cdot x}\right), 1\right)}\right), -1\right)}\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.008058366041537793:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{elif}\;x \le 0.006522581402346801:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{3}, \left(x \cdot \left(x \cdot x\right)\right), \left(\mathsf{fma}\left(\left({x}^{5}\right), \frac{2}{15}, x\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\mathsf{fma}\left(\left(\mathsf{fma}\left(\left(e^{-2 \cdot x}\right), \left(e^{-2 \cdot x}\right), 1\right) - e^{-2 \cdot x}\right), \left(\frac{2}{\mathsf{fma}\left(\left(\sqrt{e^{-2 \cdot x}} \cdot e^{-2 \cdot x}\right), \left(\sqrt{e^{-2 \cdot x}} \cdot e^{-2 \cdot x}\right), 1\right)}\right), -1\right)}\right)\\ \end{array}\]

Reproduce

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