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 r76083 = 2.0;
        double r76084 = 1.0;
        double r76085 = -2.0;
        double r76086 = x;
        double r76087 = r76085 * r76086;
        double r76088 = exp(r76087);
        double r76089 = r76084 + r76088;
        double r76090 = r76083 / r76089;
        double r76091 = r76090 - r76084;
        return r76091;
}

double f(double x, double __attribute__((unused)) y) {
        double r76092 = -2.0;
        double r76093 = x;
        double r76094 = r76092 * r76093;
        double r76095 = -0.04639353646233556;
        bool r76096 = r76094 <= r76095;
        double r76097 = 2.0;
        double r76098 = sqrt(r76097);
        double r76099 = 1.0;
        double r76100 = r76098 / r76099;
        double r76101 = 1.0;
        double r76102 = exp(r76094);
        double r76103 = r76101 + r76102;
        double r76104 = r76098 / r76103;
        double r76105 = -r76101;
        double r76106 = fma(r76100, r76104, r76105);
        double r76107 = cbrt(r76106);
        double r76108 = r76107 * r76107;
        double r76109 = r76108 * r76107;
        double r76110 = log1p(r76109);
        double r76111 = expm1(r76110);
        double r76112 = 7.357856183748689e-11;
        bool r76113 = r76094 <= r76112;
        double r76114 = 0.5;
        double r76115 = r76097 * r76114;
        double r76116 = 0.16666666666666669;
        double r76117 = r76116 * r76097;
        double r76118 = 3.0;
        double r76119 = pow(r76093, r76118);
        double r76120 = fma(r76117, r76119, r76101);
        double r76121 = r76115 - r76120;
        double r76122 = fma(r76115, r76093, r76121);
        double r76123 = log1p(r76122);
        double r76124 = expm1(r76123);
        double r76125 = r76097 / r76103;
        double r76126 = r76125 - r76101;
        double r76127 = log1p(r76126);
        double r76128 = expm1(r76127);
        double r76129 = r76113 ? r76124 : r76128;
        double r76130 = r76096 ? r76111 : r76129;
        return r76130;
}

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))