Average Error: 29.3 → 0.5
Time: 4.0s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -12083926.2470296454:\\ \;\;\;\;\frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\frac{1}{\sqrt[3]{1 + e^{-2 \cdot x}} \cdot \sqrt[3]{1 + e^{-2 \cdot x}}} \cdot \frac{2}{\sqrt[3]{1 + e^{-2 \cdot x}}} + 1}\\ \mathbf{elif}\;-2 \cdot x \le 4.592736067343327 \cdot 10^{-10}:\\ \;\;\;\;\frac{\mathsf{fma}\left({x}^{2}, 1, 2 \cdot x - 0.66666666666666696 \cdot {x}^{3}\right)}{\frac{2}{1 + e^{-2 \cdot x}} + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\left(\left(\left(\sqrt[3]{\sqrt[3]{2}} \cdot \sqrt[3]{\sqrt[3]{2}}\right) \cdot \sqrt[3]{\sqrt[3]{2}}\right) \cdot \sqrt[3]{2}\right) \cdot \frac{\sqrt[3]{2}}{1 + e^{-2 \cdot x}} + 1}\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -12083926.2470296454:\\
\;\;\;\;\frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\frac{1}{\sqrt[3]{1 + e^{-2 \cdot x}} \cdot \sqrt[3]{1 + e^{-2 \cdot x}}} \cdot \frac{2}{\sqrt[3]{1 + e^{-2 \cdot x}}} + 1}\\

\mathbf{elif}\;-2 \cdot x \le 4.592736067343327 \cdot 10^{-10}:\\
\;\;\;\;\frac{\mathsf{fma}\left({x}^{2}, 1, 2 \cdot x - 0.66666666666666696 \cdot {x}^{3}\right)}{\frac{2}{1 + e^{-2 \cdot x}} + 1}\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r61234 = 2.0;
        double r61235 = 1.0;
        double r61236 = -2.0;
        double r61237 = x;
        double r61238 = r61236 * r61237;
        double r61239 = exp(r61238);
        double r61240 = r61235 + r61239;
        double r61241 = r61234 / r61240;
        double r61242 = r61241 - r61235;
        return r61242;
}

double f(double x, double __attribute__((unused)) y) {
        double r61243 = -2.0;
        double r61244 = x;
        double r61245 = r61243 * r61244;
        double r61246 = -12083926.247029645;
        bool r61247 = r61245 <= r61246;
        double r61248 = 2.0;
        double r61249 = 1.0;
        double r61250 = exp(r61245);
        double r61251 = r61249 + r61250;
        double r61252 = r61248 / r61251;
        double r61253 = r61252 * r61252;
        double r61254 = r61249 * r61249;
        double r61255 = r61253 - r61254;
        double r61256 = 1.0;
        double r61257 = cbrt(r61251);
        double r61258 = r61257 * r61257;
        double r61259 = r61256 / r61258;
        double r61260 = r61248 / r61257;
        double r61261 = r61259 * r61260;
        double r61262 = r61261 + r61249;
        double r61263 = r61255 / r61262;
        double r61264 = 4.5927360673433267e-10;
        bool r61265 = r61245 <= r61264;
        double r61266 = 2.0;
        double r61267 = pow(r61244, r61266);
        double r61268 = r61248 * r61244;
        double r61269 = 0.666666666666667;
        double r61270 = 3.0;
        double r61271 = pow(r61244, r61270);
        double r61272 = r61269 * r61271;
        double r61273 = r61268 - r61272;
        double r61274 = fma(r61267, r61249, r61273);
        double r61275 = r61252 + r61249;
        double r61276 = r61274 / r61275;
        double r61277 = cbrt(r61248);
        double r61278 = cbrt(r61277);
        double r61279 = r61278 * r61278;
        double r61280 = r61279 * r61278;
        double r61281 = r61280 * r61277;
        double r61282 = r61277 / r61251;
        double r61283 = r61281 * r61282;
        double r61284 = r61283 + r61249;
        double r61285 = r61255 / r61284;
        double r61286 = r61265 ? r61276 : r61285;
        double r61287 = r61247 ? r61263 : r61286;
        return r61287;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0

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

      \[\leadsto \color{blue}{\frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\frac{2}{1 + e^{-2 \cdot x}} + 1}}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt0

      \[\leadsto \frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\frac{2}{\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}\]
    6. Applied *-un-lft-identity0

      \[\leadsto \frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\frac{\color{blue}{1 \cdot 2}}{\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}\]
    7. Applied times-frac0

      \[\leadsto \frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\color{blue}{\frac{1}{\sqrt[3]{1 + e^{-2 \cdot x}} \cdot \sqrt[3]{1 + e^{-2 \cdot x}}} \cdot \frac{2}{\sqrt[3]{1 + e^{-2 \cdot x}}}} + 1}\]

    if -12083926.247029645 < (* -2.0 x) < 4.5927360673433267e-10

    1. Initial program 58.9

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

      \[\leadsto \color{blue}{\frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\frac{2}{1 + e^{-2 \cdot x}} + 1}}\]
    4. Taylor expanded around 0 0.7

      \[\leadsto \frac{\color{blue}{\left(1 \cdot {x}^{2} + 2 \cdot x\right) - 0.66666666666666696 \cdot {x}^{3}}}{\frac{2}{1 + e^{-2 \cdot x}} + 1}\]
    5. Simplified0.7

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

    if 4.5927360673433267e-10 < (* -2.0 x)

    1. Initial program 0.4

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

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

      \[\leadsto \frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\frac{2}{\color{blue}{1 \cdot \left(1 + e^{-2 \cdot x}\right)}} + 1}\]
    6. Applied add-cube-cbrt0.4

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

      \[\leadsto \frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\color{blue}{\frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{1} \cdot \frac{\sqrt[3]{2}}{1 + e^{-2 \cdot x}}} + 1}\]
    8. Simplified0.4

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

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

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

Reproduce

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