Average Error: 29.4 → 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.07473290851215121100015181809794739820063:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)} \cdot \sqrt{\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 1.119851185614108205585662952907810563374 \cdot 10^{-5}:\\ \;\;\;\;\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}}}, \sqrt[3]{{\left(\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}\right)}^{3}}, -1\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.07473290851215121100015181809794739820063:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)} \cdot \sqrt{\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 1.119851185614108205585662952907810563374 \cdot 10^{-5}:\\
\;\;\;\;\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}}}, \sqrt[3]{{\left(\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}\right)}^{3}}, -1\right)\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r61087 = 2.0;
        double r61088 = 1.0;
        double r61089 = -2.0;
        double r61090 = x;
        double r61091 = r61089 * r61090;
        double r61092 = exp(r61091);
        double r61093 = r61088 + r61092;
        double r61094 = r61087 / r61093;
        double r61095 = r61094 - r61088;
        return r61095;
}

double f(double x, double __attribute__((unused)) y) {
        double r61096 = -2.0;
        double r61097 = x;
        double r61098 = r61096 * r61097;
        double r61099 = -0.07473290851215121;
        bool r61100 = r61098 <= r61099;
        double r61101 = 1.0;
        double r61102 = 1.0;
        double r61103 = exp(r61098);
        double r61104 = r61102 + r61103;
        double r61105 = sqrt(r61104);
        double r61106 = r61101 / r61105;
        double r61107 = 2.0;
        double r61108 = r61107 / r61105;
        double r61109 = -r61102;
        double r61110 = fma(r61106, r61108, r61109);
        double r61111 = sqrt(r61110);
        double r61112 = r61111 * r61111;
        double r61113 = 1.1198511856141082e-05;
        bool r61114 = r61098 <= r61113;
        double r61115 = 5.551115123125783e-17;
        double r61116 = 4.0;
        double r61117 = pow(r61097, r61116);
        double r61118 = 0.33333333333333337;
        double r61119 = 3.0;
        double r61120 = pow(r61097, r61119);
        double r61121 = r61118 * r61120;
        double r61122 = fma(r61115, r61117, r61121);
        double r61123 = -r61122;
        double r61124 = fma(r61102, r61097, r61123);
        double r61125 = pow(r61108, r61119);
        double r61126 = cbrt(r61125);
        double r61127 = fma(r61106, r61126, r61109);
        double r61128 = r61114 ? r61124 : r61127;
        double r61129 = r61100 ? r61112 : r61128;
        return r61129;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    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)}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt0.0

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

    if -0.07473290851215121 < (* -2.0 x) < 1.1198511856141082e-05

    1. Initial program 59.2

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

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

      \[\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 1.1198511856141082e-05 < (* -2.0 x)

    1. Initial program 0.1

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

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

      \[\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-cbrt-cube0.2

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

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

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

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

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

Reproduce

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