Average Error: 29.0 → 0.6
Time: 4.8s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -17964639.956402041:\\ \;\;\;\;\left(\sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\\ \mathbf{elif}\;-2 \cdot x \le 3.59556513046770647 \cdot 10^{-10}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\frac{\frac{1}{\sqrt{\sqrt{1 + e^{-2 \cdot x}}}}}{\sqrt{\sqrt{1 + e^{-2 \cdot x}}}}, \frac{2}{\sqrt{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 -17964639.956402041:\\
\;\;\;\;\left(\sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\\

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r64941 = 2.0;
        double r64942 = 1.0;
        double r64943 = -2.0;
        double r64944 = x;
        double r64945 = r64943 * r64944;
        double r64946 = exp(r64945);
        double r64947 = r64942 + r64946;
        double r64948 = r64941 / r64947;
        double r64949 = r64948 - r64942;
        return r64949;
}

double f(double x, double __attribute__((unused)) y) {
        double r64950 = -2.0;
        double r64951 = x;
        double r64952 = r64950 * r64951;
        double r64953 = -17964639.95640204;
        bool r64954 = r64952 <= r64953;
        double r64955 = 1.0;
        double r64956 = 1.0;
        double r64957 = exp(r64952);
        double r64958 = r64956 + r64957;
        double r64959 = sqrt(r64958);
        double r64960 = r64955 / r64959;
        double r64961 = 2.0;
        double r64962 = r64961 / r64959;
        double r64963 = -r64956;
        double r64964 = fma(r64960, r64962, r64963);
        double r64965 = cbrt(r64964);
        double r64966 = r64965 * r64965;
        double r64967 = r64966 * r64965;
        double r64968 = 3.5955651304677065e-10;
        bool r64969 = r64952 <= r64968;
        double r64970 = 5.551115123125783e-17;
        double r64971 = 4.0;
        double r64972 = pow(r64951, r64971);
        double r64973 = 0.33333333333333337;
        double r64974 = 3.0;
        double r64975 = pow(r64951, r64974);
        double r64976 = r64973 * r64975;
        double r64977 = fma(r64970, r64972, r64976);
        double r64978 = -r64977;
        double r64979 = fma(r64956, r64951, r64978);
        double r64980 = sqrt(r64959);
        double r64981 = r64955 / r64980;
        double r64982 = r64981 / r64980;
        double r64983 = fma(r64982, r64962, r64963);
        double r64984 = cbrt(r64983);
        double r64985 = r64966 * r64984;
        double r64986 = r64969 ? r64979 : r64985;
        double r64987 = r64954 ? r64967 : r64986;
        return r64987;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0

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

      \[\leadsto \frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    4. Applied *-un-lft-identity0

      \[\leadsto \frac{\color{blue}{1 \cdot 2}}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}} - 1\]
    5. Applied times-frac0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{1 + e^{-2 \cdot x}}} \cdot \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    6. Applied fma-neg0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\]
    7. Using strategy rm
    8. Applied add-cube-cbrt0

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

    if -17964639.95640204 < (* -2.0 x) < 3.5955651304677065e-10

    1. Initial program 58.6

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

      \[\leadsto \color{blue}{1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)}\]
    3. Simplified1.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 3.5955651304677065e-10 < (* -2.0 x)

    1. Initial program 0.5

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.5

      \[\leadsto \frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    4. Applied *-un-lft-identity0.5

      \[\leadsto \frac{\color{blue}{1 \cdot 2}}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}} - 1\]
    5. Applied times-frac0.5

      \[\leadsto \color{blue}{\frac{1}{\sqrt{1 + e^{-2 \cdot x}}} \cdot \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    6. Applied fma-neg0.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\]
    7. Using strategy rm
    8. Applied add-cube-cbrt0.5

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

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

      \[\leadsto \left(\sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\frac{1}{\color{blue}{\sqrt{\sqrt{1 + e^{-2 \cdot x}}} \cdot \sqrt{\sqrt{1 + e^{-2 \cdot x}}}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\]
    12. Applied associate-/r*0.5

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

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

Reproduce

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