Average Error: 29.4 → 0.0
Time: 5.6m
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.006924991008319216:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{elif}\;x \le 0.007132824427291399:\\ \;\;\;\;(\left(\frac{-1}{3} \cdot x\right) \cdot \left(x \cdot x\right) + \left((\frac{2}{15} \cdot \left({x}^{5}\right) + x)_*\right))_*\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(\frac{\frac{8}{(\left(e^{-2 \cdot x} \cdot e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_*}}{(\left(e^{-2 \cdot x} \cdot e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* \cdot (\left(e^{-2 \cdot x} \cdot e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_*}\right) \cdot \left(\left(\left((\left(e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* - e^{-2 \cdot x}\right) \cdot \left((\left(e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* - e^{-2 \cdot x}\right)\right) \cdot \left((\left(e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* - e^{-2 \cdot x}\right)\right) + -1)_*}{\left(\frac{2}{e^{-2 \cdot x} + 1} + 1\right) + \frac{2}{e^{-2 \cdot x} + 1} \cdot \frac{2}{e^{-2 \cdot x} + 1}}\\ \end{array}\]
double f(double x, double __attribute__((unused)) y) {
        double r36127776 = 2.0;
        double r36127777 = 1.0;
        double r36127778 = -2.0;
        double r36127779 = x;
        double r36127780 = r36127778 * r36127779;
        double r36127781 = exp(r36127780);
        double r36127782 = r36127777 + r36127781;
        double r36127783 = r36127776 / r36127782;
        double r36127784 = r36127783 - r36127777;
        return r36127784;
}

double f(double x, double __attribute__((unused)) y) {
        double r36127785 = x;
        double r36127786 = -0.006924991008319216;
        bool r36127787 = r36127785 <= r36127786;
        double r36127788 = 2.0;
        double r36127789 = -2.0;
        double r36127790 = r36127789 * r36127785;
        double r36127791 = exp(r36127790);
        double r36127792 = 1.0;
        double r36127793 = r36127791 + r36127792;
        double r36127794 = r36127788 / r36127793;
        double r36127795 = r36127794 - r36127792;
        double r36127796 = 0.007132824427291399;
        bool r36127797 = r36127785 <= r36127796;
        double r36127798 = -0.3333333333333333;
        double r36127799 = r36127798 * r36127785;
        double r36127800 = r36127785 * r36127785;
        double r36127801 = 0.13333333333333333;
        double r36127802 = 5.0;
        double r36127803 = pow(r36127785, r36127802);
        double r36127804 = fma(r36127801, r36127803, r36127785);
        double r36127805 = fma(r36127799, r36127800, r36127804);
        double r36127806 = 8.0;
        double r36127807 = r36127791 * r36127791;
        double r36127808 = fma(r36127807, r36127791, r36127792);
        double r36127809 = r36127806 / r36127808;
        double r36127810 = r36127808 * r36127808;
        double r36127811 = r36127809 / r36127810;
        double r36127812 = fma(r36127791, r36127791, r36127792);
        double r36127813 = r36127812 - r36127791;
        double r36127814 = r36127813 * r36127813;
        double r36127815 = r36127814 * r36127813;
        double r36127816 = -1.0;
        double r36127817 = fma(r36127811, r36127815, r36127816);
        double r36127818 = r36127794 + r36127792;
        double r36127819 = r36127794 * r36127794;
        double r36127820 = r36127818 + r36127819;
        double r36127821 = r36127817 / r36127820;
        double r36127822 = r36127797 ? r36127805 : r36127821;
        double r36127823 = r36127787 ? r36127795 : r36127822;
        return r36127823;
}

\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;x \le -0.006924991008319216:\\
\;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\

\mathbf{elif}\;x \le 0.007132824427291399:\\
\;\;\;\;(\left(\frac{-1}{3} \cdot x\right) \cdot \left(x \cdot x\right) + \left((\frac{2}{15} \cdot \left({x}^{5}\right) + x)_*\right))_*\\

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

\end{array}

Error

Bits error versus x

Bits error versus y

Derivation

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

    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.006924991008319216 < x < 0.007132824427291399

    1. Initial program 59.1

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

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

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

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

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

    if 0.007132824427291399 < 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 \color{blue}{\frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} + \left(1 \cdot 1 + \frac{2}{1 + e^{-2 \cdot x}} \cdot 1\right)}}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt0.0

      \[\leadsto \frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - \color{blue}{\left(\sqrt[3]{{1}^{3}} \cdot \sqrt[3]{{1}^{3}}\right) \cdot \sqrt[3]{{1}^{3}}}}{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} + \left(1 \cdot 1 + \frac{2}{1 + e^{-2 \cdot x}} \cdot 1\right)}\]
    8. Applied flip3-+0.0

      \[\leadsto \frac{{\left(\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)}}}\right)}^{3} - \left(\sqrt[3]{{1}^{3}} \cdot \sqrt[3]{{1}^{3}}\right) \cdot \sqrt[3]{{1}^{3}}}{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} + \left(1 \cdot 1 + \frac{2}{1 + e^{-2 \cdot x}} \cdot 1\right)}\]
    9. Applied associate-/r/0.0

      \[\leadsto \frac{{\color{blue}{\left(\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)\right)}}^{3} - \left(\sqrt[3]{{1}^{3}} \cdot \sqrt[3]{{1}^{3}}\right) \cdot \sqrt[3]{{1}^{3}}}{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} + \left(1 \cdot 1 + \frac{2}{1 + e^{-2 \cdot x}} \cdot 1\right)}\]
    10. Applied unpow-prod-down0.0

      \[\leadsto \frac{\color{blue}{{\left(\frac{2}{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}\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)}^{3}} - \left(\sqrt[3]{{1}^{3}} \cdot \sqrt[3]{{1}^{3}}\right) \cdot \sqrt[3]{{1}^{3}}}{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} + \left(1 \cdot 1 + \frac{2}{1 + e^{-2 \cdot x}} \cdot 1\right)}\]
    11. Applied prod-diff0.0

      \[\leadsto \frac{\color{blue}{(\left({\left(\frac{2}{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}\right)}^{3}\right) \cdot \left({\left(1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right)\right)}^{3}\right) + \left(-\sqrt[3]{{1}^{3}} \cdot \left(\sqrt[3]{{1}^{3}} \cdot \sqrt[3]{{1}^{3}}\right)\right))_* + (\left(-\sqrt[3]{{1}^{3}}\right) \cdot \left(\sqrt[3]{{1}^{3}} \cdot \sqrt[3]{{1}^{3}}\right) + \left(\sqrt[3]{{1}^{3}} \cdot \left(\sqrt[3]{{1}^{3}} \cdot \sqrt[3]{{1}^{3}}\right)\right))_*}}{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} + \left(1 \cdot 1 + \frac{2}{1 + e^{-2 \cdot x}} \cdot 1\right)}\]
    12. Simplified0.0

      \[\leadsto \frac{\color{blue}{(\left(\frac{\frac{8}{(\left(e^{-2 \cdot x} \cdot e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_*}}{(\left(e^{-2 \cdot x} \cdot e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* \cdot (\left(e^{-2 \cdot x} \cdot e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_*}\right) \cdot \left(\left(\left((\left(e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* - e^{-2 \cdot x}\right) \cdot \left((\left(e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* - e^{-2 \cdot x}\right)\right) \cdot \left((\left(e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* - e^{-2 \cdot x}\right)\right) + -1)_*} + (\left(-\sqrt[3]{{1}^{3}}\right) \cdot \left(\sqrt[3]{{1}^{3}} \cdot \sqrt[3]{{1}^{3}}\right) + \left(\sqrt[3]{{1}^{3}} \cdot \left(\sqrt[3]{{1}^{3}} \cdot \sqrt[3]{{1}^{3}}\right)\right))_*}{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} + \left(1 \cdot 1 + \frac{2}{1 + e^{-2 \cdot x}} \cdot 1\right)}\]
    13. Simplified0.0

      \[\leadsto \frac{(\left(\frac{\frac{8}{(\left(e^{-2 \cdot x} \cdot e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_*}}{(\left(e^{-2 \cdot x} \cdot e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* \cdot (\left(e^{-2 \cdot x} \cdot e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_*}\right) \cdot \left(\left(\left((\left(e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* - e^{-2 \cdot x}\right) \cdot \left((\left(e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* - e^{-2 \cdot x}\right)\right) \cdot \left((\left(e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* - e^{-2 \cdot x}\right)\right) + -1)_* + \color{blue}{0}}{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} + \left(1 \cdot 1 + \frac{2}{1 + e^{-2 \cdot x}} \cdot 1\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.006924991008319216:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{elif}\;x \le 0.007132824427291399:\\ \;\;\;\;(\left(\frac{-1}{3} \cdot x\right) \cdot \left(x \cdot x\right) + \left((\frac{2}{15} \cdot \left({x}^{5}\right) + x)_*\right))_*\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(\frac{\frac{8}{(\left(e^{-2 \cdot x} \cdot e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_*}}{(\left(e^{-2 \cdot x} \cdot e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* \cdot (\left(e^{-2 \cdot x} \cdot e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_*}\right) \cdot \left(\left(\left((\left(e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* - e^{-2 \cdot x}\right) \cdot \left((\left(e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* - e^{-2 \cdot x}\right)\right) \cdot \left((\left(e^{-2 \cdot x}\right) \cdot \left(e^{-2 \cdot x}\right) + 1)_* - e^{-2 \cdot x}\right)\right) + -1)_*}{\left(\frac{2}{e^{-2 \cdot x} + 1} + 1\right) + \frac{2}{e^{-2 \cdot x} + 1} \cdot \frac{2}{e^{-2 \cdot x} + 1}}\\ \end{array}\]

Reproduce

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