Average Error: 28.9 → 0.2
Time: 4.1s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.04639353646233555783506830039186752401292:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\left(\sqrt[3]{\mathsf{fma}\left(\frac{\sqrt{2}}{1}, \frac{\sqrt{2}}{1 + e^{-2 \cdot x}}, -1\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{\sqrt{2}}{1}, \frac{\sqrt{2}}{1 + e^{-2 \cdot x}}, -1\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\frac{\sqrt{2}}{1}, \frac{\sqrt{2}}{1 + e^{-2 \cdot x}}, -1\right)}\right)\right)\\ \mathbf{elif}\;-2 \cdot x \le 7.357856183748689123394269679412382258177 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(2 \cdot 0.5, x, 2 \cdot 0.5 - \mathsf{fma}\left(0.1666666666666666851703837437526090070605 \cdot 2, {x}^{3}, 1\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.04639353646233555783506830039186752401292:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\left(\sqrt[3]{\mathsf{fma}\left(\frac{\sqrt{2}}{1}, \frac{\sqrt{2}}{1 + e^{-2 \cdot x}}, -1\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{\sqrt{2}}{1}, \frac{\sqrt{2}}{1 + e^{-2 \cdot x}}, -1\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\frac{\sqrt{2}}{1}, \frac{\sqrt{2}}{1 + e^{-2 \cdot x}}, -1\right)}\right)\right)\\

\mathbf{elif}\;-2 \cdot x \le 7.357856183748689123394269679412382258177 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(2 \cdot 0.5, x, 2 \cdot 0.5 - \mathsf{fma}\left(0.1666666666666666851703837437526090070605 \cdot 2, {x}^{3}, 1\right)\right)\right)\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r77939 = 2.0;
        double r77940 = 1.0;
        double r77941 = -2.0;
        double r77942 = x;
        double r77943 = r77941 * r77942;
        double r77944 = exp(r77943);
        double r77945 = r77940 + r77944;
        double r77946 = r77939 / r77945;
        double r77947 = r77946 - r77940;
        return r77947;
}

double f(double x, double __attribute__((unused)) y) {
        double r77948 = -2.0;
        double r77949 = x;
        double r77950 = r77948 * r77949;
        double r77951 = -0.04639353646233556;
        bool r77952 = r77950 <= r77951;
        double r77953 = 2.0;
        double r77954 = sqrt(r77953);
        double r77955 = 1.0;
        double r77956 = r77954 / r77955;
        double r77957 = 1.0;
        double r77958 = exp(r77950);
        double r77959 = r77957 + r77958;
        double r77960 = r77954 / r77959;
        double r77961 = -r77957;
        double r77962 = fma(r77956, r77960, r77961);
        double r77963 = cbrt(r77962);
        double r77964 = r77963 * r77963;
        double r77965 = r77964 * r77963;
        double r77966 = log1p(r77965);
        double r77967 = expm1(r77966);
        double r77968 = 7.357856183748689e-11;
        bool r77969 = r77950 <= r77968;
        double r77970 = 0.5;
        double r77971 = r77953 * r77970;
        double r77972 = 0.16666666666666669;
        double r77973 = r77972 * r77953;
        double r77974 = 3.0;
        double r77975 = pow(r77949, r77974);
        double r77976 = fma(r77973, r77975, r77957);
        double r77977 = r77971 - r77976;
        double r77978 = fma(r77971, r77949, r77977);
        double r77979 = log1p(r77978);
        double r77980 = expm1(r77979);
        double r77981 = r77953 / r77959;
        double r77982 = r77981 - r77957;
        double r77983 = log1p(r77982);
        double r77984 = expm1(r77983);
        double r77985 = r77969 ? r77980 : r77984;
        double r77986 = r77952 ? r77967 : r77985;
        return r77986;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0.0

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied expm1-log1p-u0.0

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)\right)}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity0.0

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{\color{blue}{1 \cdot \left(1 + e^{-2 \cdot x}\right)}} - 1\right)\right)\]
    6. Applied add-sqr-sqrt1.6

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{2} \cdot \sqrt{2}}}{1 \cdot \left(1 + e^{-2 \cdot x}\right)} - 1\right)\right)\]
    7. Applied times-frac1.6

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sqrt{2}}{1} \cdot \frac{\sqrt{2}}{1 + e^{-2 \cdot x}}} - 1\right)\right)\]
    8. Applied fma-neg1.0

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

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

    if -0.04639353646233556 < (* -2.0 x) < 7.357856183748689e-11

    1. Initial program 59.5

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied expm1-log1p-u59.5

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)\right)}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity59.5

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{\color{blue}{1 \cdot \left(1 + e^{-2 \cdot x}\right)}} - 1\right)\right)\]
    6. Applied add-sqr-sqrt60.6

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{2} \cdot \sqrt{2}}}{1 \cdot \left(1 + e^{-2 \cdot x}\right)} - 1\right)\right)\]
    7. Applied times-frac60.6

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sqrt{2}}{1} \cdot \frac{\sqrt{2}}{1 + e^{-2 \cdot x}}} - 1\right)\right)\]
    8. Applied fma-neg60.6

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\mathsf{fma}\left(\frac{\sqrt{2}}{1}, \frac{\sqrt{2}}{1 + e^{-2 \cdot x}}, -1\right)}\right)\right)\]
    9. Taylor expanded around 0 60.6

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\left(0.5 \cdot {\left(\sqrt{2}\right)}^{2} + 0.5 \cdot \left({\left(\sqrt{2}\right)}^{2} \cdot x\right)\right) - \left(0.1666666666666666851703837437526090070605 \cdot \left({\left(\sqrt{2}\right)}^{2} \cdot {x}^{3}\right) + 1\right)}\right)\right)\]
    10. Simplified0.1

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\mathsf{fma}\left(2 \cdot 0.5, x, 2 \cdot 0.5 - \mathsf{fma}\left(0.1666666666666666851703837437526090070605 \cdot 2, {x}^{3}, 1\right)\right)}\right)\right)\]

    if 7.357856183748689e-11 < (* -2.0 x)

    1. Initial program 0.4

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied expm1-log1p-u0.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.04639353646233555783506830039186752401292:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\left(\sqrt[3]{\mathsf{fma}\left(\frac{\sqrt{2}}{1}, \frac{\sqrt{2}}{1 + e^{-2 \cdot x}}, -1\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{\sqrt{2}}{1}, \frac{\sqrt{2}}{1 + e^{-2 \cdot x}}, -1\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\frac{\sqrt{2}}{1}, \frac{\sqrt{2}}{1 + e^{-2 \cdot x}}, -1\right)}\right)\right)\\ \mathbf{elif}\;-2 \cdot x \le 7.357856183748689123394269679412382258177 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(2 \cdot 0.5, x, 2 \cdot 0.5 - \mathsf{fma}\left(0.1666666666666666851703837437526090070605 \cdot 2, {x}^{3}, 1\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)\right)\\ \end{array}\]

Reproduce

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