Average Error: 29.1 → 0.0
Time: 39.9s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.008638132025518943:\\ \;\;\;\;\mathsf{fma}\left(\left(\frac{\sqrt{2}}{\left|\sqrt[3]{1 + e^{x \cdot -2}}\right|}\right), \left(\frac{\frac{\sqrt{2}}{\sqrt{1 + e^{x \cdot -2}}}}{\sqrt{\sqrt[3]{1 + e^{x \cdot -2}}}}\right), -1\right)\\ \mathbf{elif}\;x \le 0.006936161389017993:\\ \;\;\;\;\mathsf{fma}\left(\left({x}^{5}\right), \frac{2}{15}, x\right) - \frac{1}{3} \cdot \left(\left(x \cdot x\right) \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{\frac{2}{\sqrt{1 + e^{x \cdot -2}}}}{\sqrt{1 + e^{x \cdot -2}}} - 1}\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;x \le -0.008638132025518943:\\
\;\;\;\;\mathsf{fma}\left(\left(\frac{\sqrt{2}}{\left|\sqrt[3]{1 + e^{x \cdot -2}}\right|}\right), \left(\frac{\frac{\sqrt{2}}{\sqrt{1 + e^{x \cdot -2}}}}{\sqrt{\sqrt[3]{1 + e^{x \cdot -2}}}}\right), -1\right)\\

\mathbf{elif}\;x \le 0.006936161389017993:\\
\;\;\;\;\mathsf{fma}\left(\left({x}^{5}\right), \frac{2}{15}, x\right) - \frac{1}{3} \cdot \left(\left(x \cdot x\right) \cdot x\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r1490262 = 2.0;
        double r1490263 = 1.0;
        double r1490264 = -2.0;
        double r1490265 = x;
        double r1490266 = r1490264 * r1490265;
        double r1490267 = exp(r1490266);
        double r1490268 = r1490263 + r1490267;
        double r1490269 = r1490262 / r1490268;
        double r1490270 = r1490269 - r1490263;
        return r1490270;
}

double f(double x, double __attribute__((unused)) y) {
        double r1490271 = x;
        double r1490272 = -0.008638132025518943;
        bool r1490273 = r1490271 <= r1490272;
        double r1490274 = 2.0;
        double r1490275 = sqrt(r1490274);
        double r1490276 = 1.0;
        double r1490277 = -2.0;
        double r1490278 = r1490271 * r1490277;
        double r1490279 = exp(r1490278);
        double r1490280 = r1490276 + r1490279;
        double r1490281 = cbrt(r1490280);
        double r1490282 = fabs(r1490281);
        double r1490283 = r1490275 / r1490282;
        double r1490284 = sqrt(r1490280);
        double r1490285 = r1490275 / r1490284;
        double r1490286 = sqrt(r1490281);
        double r1490287 = r1490285 / r1490286;
        double r1490288 = -1.0;
        double r1490289 = fma(r1490283, r1490287, r1490288);
        double r1490290 = 0.006936161389017993;
        bool r1490291 = r1490271 <= r1490290;
        double r1490292 = 5.0;
        double r1490293 = pow(r1490271, r1490292);
        double r1490294 = 0.13333333333333333;
        double r1490295 = fma(r1490293, r1490294, r1490271);
        double r1490296 = 0.3333333333333333;
        double r1490297 = r1490271 * r1490271;
        double r1490298 = r1490297 * r1490271;
        double r1490299 = r1490296 * r1490298;
        double r1490300 = r1490295 - r1490299;
        double r1490301 = r1490274 / r1490284;
        double r1490302 = r1490301 / r1490284;
        double r1490303 = r1490302 - r1490276;
        double r1490304 = exp(r1490303);
        double r1490305 = log(r1490304);
        double r1490306 = r1490291 ? r1490300 : r1490305;
        double r1490307 = r1490273 ? r1490289 : r1490306;
        return r1490307;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 3 regimes
  2. if x < -0.008638132025518943

    1. Initial program 0.0

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

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

      \[\leadsto \color{blue}{\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right)} - \log \left(e^{1}\right)\]
    5. Applied diff-log0.0

      \[\leadsto \color{blue}{\log \left(\frac{e^{\frac{2}{1 + e^{-2 \cdot x}}}}{e^{1}}\right)}\]
    6. Simplified0.0

      \[\leadsto \log \color{blue}{\left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt0.0

      \[\leadsto \log \left(e^{\frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} - 1}\right)\]
    9. Applied associate-/r*0.0

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

      \[\leadsto \log \left(e^{\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - \color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}\right)\]
    12. Applied add-cube-cbrt0.0

      \[\leadsto \log \left(e^{\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\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}}}}} - \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}\right)\]
    13. Applied sqrt-prod0.0

      \[\leadsto \log \left(e^{\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\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}}}}} - \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}\right)\]
    14. Applied *-un-lft-identity0.0

      \[\leadsto \log \left(e^{\frac{\frac{2}{\color{blue}{1 \cdot \sqrt{1 + e^{-2 \cdot x}}}}}{\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}}}} - \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}\right)\]
    15. Applied add-sqr-sqrt0.0

      \[\leadsto \log \left(e^{\frac{\frac{\color{blue}{\sqrt{2} \cdot \sqrt{2}}}{1 \cdot \sqrt{1 + e^{-2 \cdot x}}}}{\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}}}} - \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}\right)\]
    16. Applied times-frac0.0

      \[\leadsto \log \left(e^{\frac{\color{blue}{\frac{\sqrt{2}}{1} \cdot \frac{\sqrt{2}}{\sqrt{1 + e^{-2 \cdot x}}}}}{\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}}}} - \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}\right)\]
    17. Applied times-frac0.0

      \[\leadsto \log \left(e^{\color{blue}{\frac{\frac{\sqrt{2}}{1}}{\sqrt{\sqrt[3]{1 + e^{-2 \cdot x}} \cdot \sqrt[3]{1 + e^{-2 \cdot x}}}} \cdot \frac{\frac{\sqrt{2}}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{\sqrt[3]{1 + e^{-2 \cdot x}}}}} - \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}\right)\]
    18. Applied prod-diff0.0

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

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

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

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

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

    if -0.008638132025518943 < x < 0.006936161389017993

    1. Initial program 59.0

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

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

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

    if 0.006936161389017993 < x

    1. Initial program 0.0

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

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

      \[\leadsto \color{blue}{\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right)} - \log \left(e^{1}\right)\]
    5. Applied diff-log0.0

      \[\leadsto \color{blue}{\log \left(\frac{e^{\frac{2}{1 + e^{-2 \cdot x}}}}{e^{1}}\right)}\]
    6. Simplified0.0

      \[\leadsto \log \color{blue}{\left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt0.0

      \[\leadsto \log \left(e^{\frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} - 1}\right)\]
    9. Applied associate-/r*0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.008638132025518943:\\ \;\;\;\;\mathsf{fma}\left(\left(\frac{\sqrt{2}}{\left|\sqrt[3]{1 + e^{x \cdot -2}}\right|}\right), \left(\frac{\frac{\sqrt{2}}{\sqrt{1 + e^{x \cdot -2}}}}{\sqrt{\sqrt[3]{1 + e^{x \cdot -2}}}}\right), -1\right)\\ \mathbf{elif}\;x \le 0.006936161389017993:\\ \;\;\;\;\mathsf{fma}\left(\left({x}^{5}\right), \frac{2}{15}, x\right) - \frac{1}{3} \cdot \left(\left(x \cdot x\right) \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{\frac{2}{\sqrt{1 + e^{x \cdot -2}}}}{\sqrt{1 + e^{x \cdot -2}}} - 1}\right)\\ \end{array}\]

Reproduce

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