Average Error: 29.8 → 0.1
Time: 4.5s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.8755191573179796904469185392372310161591:\\ \;\;\;\;\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 0.001318496133275824351918648069670325639891:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{\sqrt{2}}{\left|\sqrt[3]{1 + e^{-2 \cdot x}}\right|} \cdot \frac{\sqrt{2}}{\sqrt{\sqrt[3]{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 -0.8755191573179796904469185392372310161591:\\
\;\;\;\;\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 0.001318496133275824351918648069670325639891:\\
\;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r59053 = 2.0;
        double r59054 = 1.0;
        double r59055 = -2.0;
        double r59056 = x;
        double r59057 = r59055 * r59056;
        double r59058 = exp(r59057);
        double r59059 = r59054 + r59058;
        double r59060 = r59053 / r59059;
        double r59061 = r59060 - r59054;
        return r59061;
}

double f(double x, double __attribute__((unused)) y) {
        double r59062 = -2.0;
        double r59063 = x;
        double r59064 = r59062 * r59063;
        double r59065 = -0.8755191573179797;
        bool r59066 = r59064 <= r59065;
        double r59067 = 1.0;
        double r59068 = 1.0;
        double r59069 = exp(r59064);
        double r59070 = r59068 + r59069;
        double r59071 = sqrt(r59070);
        double r59072 = r59067 / r59071;
        double r59073 = 2.0;
        double r59074 = r59073 / r59071;
        double r59075 = -r59068;
        double r59076 = fma(r59072, r59074, r59075);
        double r59077 = 0.0013184961332758244;
        bool r59078 = r59064 <= r59077;
        double r59079 = 5.551115123125783e-17;
        double r59080 = 4.0;
        double r59081 = pow(r59063, r59080);
        double r59082 = 0.33333333333333337;
        double r59083 = 3.0;
        double r59084 = pow(r59063, r59083);
        double r59085 = r59082 * r59084;
        double r59086 = fma(r59079, r59081, r59085);
        double r59087 = -r59086;
        double r59088 = fma(r59068, r59063, r59087);
        double r59089 = sqrt(r59073);
        double r59090 = cbrt(r59070);
        double r59091 = fabs(r59090);
        double r59092 = r59089 / r59091;
        double r59093 = sqrt(r59090);
        double r59094 = r59089 / r59093;
        double r59095 = r59092 * r59094;
        double r59096 = fma(r59072, r59095, r59075);
        double r59097 = r59078 ? r59088 : r59096;
        double r59098 = r59066 ? r59076 : r59097;
        return r59098;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0.0

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

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

      \[\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.0

      \[\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.0

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

    if -0.8755191573179797 < (* -2.0 x) < 0.0013184961332758244

    1. Initial program 59.1

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

      \[\leadsto \color{blue}{1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)}\]
    3. Simplified0.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\right)}\]

    if 0.0013184961332758244 < (* -2.0 x)

    1. Initial program 0.0

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

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

      \[\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.1

      \[\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.1

      \[\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.1

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.8755191573179796904469185392372310161591:\\ \;\;\;\;\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 0.001318496133275824351918648069670325639891:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{\sqrt{2}}{\left|\sqrt[3]{1 + e^{-2 \cdot x}}\right|} \cdot \frac{\sqrt{2}}{\sqrt{\sqrt[3]{1 + e^{-2 \cdot x}}}}, -1\right)\\ \end{array}\]

Reproduce

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