Average Error: 29.2 → 0.0
Time: 14.6s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.0132325776020981046:\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{elif}\;-2 \cdot x \le 2.72138255369031824 \cdot 10^{-5}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\sqrt{2}}{\sqrt[3]{1 + e^{-2 \cdot x}} \cdot \sqrt[3]{1 + e^{-2 \cdot x}}}, \frac{\sqrt{2}}{{\left(1 + e^{-2 \cdot x}\right)}^{\frac{1}{3}}}, -1\right) + 1 \cdot 0\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.0132325776020981046:\\
\;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\

\mathbf{elif}\;-2 \cdot x \le 2.72138255369031824 \cdot 10^{-5}:\\
\;\;\;\;1 \cdot x - \mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r48995 = 2.0;
        double r48996 = 1.0;
        double r48997 = -2.0;
        double r48998 = x;
        double r48999 = r48997 * r48998;
        double r49000 = exp(r48999);
        double r49001 = r48996 + r49000;
        double r49002 = r48995 / r49001;
        double r49003 = r49002 - r48996;
        return r49003;
}

double f(double x, double __attribute__((unused)) y) {
        double r49004 = -2.0;
        double r49005 = x;
        double r49006 = r49004 * r49005;
        double r49007 = -0.013232577602098105;
        bool r49008 = r49006 <= r49007;
        double r49009 = 2.0;
        double r49010 = 1.0;
        double r49011 = exp(r49006);
        double r49012 = r49010 + r49011;
        double r49013 = r49009 / r49012;
        double r49014 = r49013 - r49010;
        double r49015 = exp(r49014);
        double r49016 = log(r49015);
        double r49017 = 2.7213825536903182e-05;
        bool r49018 = r49006 <= r49017;
        double r49019 = r49010 * r49005;
        double r49020 = 5.551115123125783e-17;
        double r49021 = 4.0;
        double r49022 = pow(r49005, r49021);
        double r49023 = 0.33333333333333337;
        double r49024 = 3.0;
        double r49025 = pow(r49005, r49024);
        double r49026 = r49023 * r49025;
        double r49027 = fma(r49020, r49022, r49026);
        double r49028 = r49019 - r49027;
        double r49029 = sqrt(r49009);
        double r49030 = cbrt(r49012);
        double r49031 = r49030 * r49030;
        double r49032 = r49029 / r49031;
        double r49033 = 0.3333333333333333;
        double r49034 = pow(r49012, r49033);
        double r49035 = r49029 / r49034;
        double r49036 = -r49010;
        double r49037 = fma(r49032, r49035, r49036);
        double r49038 = 0.0;
        double r49039 = r49010 * r49038;
        double r49040 = r49037 + r49039;
        double r49041 = r49018 ? r49028 : r49040;
        double r49042 = r49008 ? r49016 : r49041;
        return r49042;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    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)}\]

    if -0.013232577602098105 < (* -2.0 x) < 2.7213825536903182e-05

    1. Initial program 59.1

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

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

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

    if 2.7213825536903182e-05 < (* -2.0 x)

    1. Initial program 0.1

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

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

      \[\leadsto \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}}}} - \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}\]
    5. Applied add-sqr-sqrt0.1

      \[\leadsto \frac{\color{blue}{\sqrt{2} \cdot \sqrt{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}}} - \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}\]
    6. Applied times-frac0.1

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{\sqrt{2}}{\sqrt[3]{1 + e^{-2 \cdot x}} \cdot \sqrt[3]{1 + e^{-2 \cdot x}}}, \frac{\sqrt{2}}{\sqrt[3]{1 + e^{-2 \cdot x}}}, -1\right) + \color{blue}{1 \cdot 0}\]
    10. Using strategy rm
    11. Applied pow1/30.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.0132325776020981046:\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{elif}\;-2 \cdot x \le 2.72138255369031824 \cdot 10^{-5}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\sqrt{2}}{\sqrt[3]{1 + e^{-2 \cdot x}} \cdot \sqrt[3]{1 + e^{-2 \cdot x}}}, \frac{\sqrt{2}}{{\left(1 + e^{-2 \cdot x}\right)}^{\frac{1}{3}}}, -1\right) + 1 \cdot 0\\ \end{array}\]

Reproduce

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