Average Error: 29.4 → 0.0
Time: 7.0s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.0039848092641429148:\\ \;\;\;\;\sqrt[3]{{\left(\frac{8 \cdot \frac{1}{{\left(e^{-2 \cdot x} + 1\right)}^{3}} - 1}{1 + \left(4 \cdot \frac{1}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} + 2 \cdot \frac{1}{e^{-2 \cdot x} + 1}\right)}\right)}^{3}}\\ \mathbf{elif}\;-2 \cdot x \le 8.5922675456739933 \cdot 10^{-5}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{8 \cdot \frac{1}{{\left(e^{-2 \cdot x} + 1\right)}^{3}} - 1}{1 + \left(4 \cdot \frac{1}{{\left({\left(e^{-2 \cdot x} + 1\right)}^{\left(\sqrt[3]{2} \cdot \sqrt[3]{2}\right)}\right)}^{\left(\sqrt[3]{2}\right)}} + 2 \cdot \frac{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.0039848092641429148:\\
\;\;\;\;\sqrt[3]{{\left(\frac{8 \cdot \frac{1}{{\left(e^{-2 \cdot x} + 1\right)}^{3}} - 1}{1 + \left(4 \cdot \frac{1}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} + 2 \cdot \frac{1}{e^{-2 \cdot x} + 1}\right)}\right)}^{3}}\\

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r62990 = 2.0;
        double r62991 = 1.0;
        double r62992 = -2.0;
        double r62993 = x;
        double r62994 = r62992 * r62993;
        double r62995 = exp(r62994);
        double r62996 = r62991 + r62995;
        double r62997 = r62990 / r62996;
        double r62998 = r62997 - r62991;
        return r62998;
}

double f(double x, double __attribute__((unused)) y) {
        double r62999 = -2.0;
        double r63000 = x;
        double r63001 = r62999 * r63000;
        double r63002 = -0.003984809264142915;
        bool r63003 = r63001 <= r63002;
        double r63004 = 8.0;
        double r63005 = 1.0;
        double r63006 = exp(r63001);
        double r63007 = 1.0;
        double r63008 = r63006 + r63007;
        double r63009 = 3.0;
        double r63010 = pow(r63008, r63009);
        double r63011 = r63005 / r63010;
        double r63012 = r63004 * r63011;
        double r63013 = r63012 - r63007;
        double r63014 = 4.0;
        double r63015 = 2.0;
        double r63016 = pow(r63008, r63015);
        double r63017 = r63005 / r63016;
        double r63018 = r63014 * r63017;
        double r63019 = 2.0;
        double r63020 = r63005 / r63008;
        double r63021 = r63019 * r63020;
        double r63022 = r63018 + r63021;
        double r63023 = r63007 + r63022;
        double r63024 = r63013 / r63023;
        double r63025 = pow(r63024, r63009);
        double r63026 = cbrt(r63025);
        double r63027 = 8.592267545673993e-05;
        bool r63028 = r63001 <= r63027;
        double r63029 = 5.551115123125783e-17;
        double r63030 = 4.0;
        double r63031 = pow(r63000, r63030);
        double r63032 = 0.33333333333333337;
        double r63033 = pow(r63000, r63009);
        double r63034 = r63032 * r63033;
        double r63035 = fma(r63029, r63031, r63034);
        double r63036 = -r63035;
        double r63037 = fma(r63007, r63000, r63036);
        double r63038 = cbrt(r63015);
        double r63039 = r63038 * r63038;
        double r63040 = pow(r63008, r63039);
        double r63041 = pow(r63040, r63038);
        double r63042 = r63005 / r63041;
        double r63043 = r63014 * r63042;
        double r63044 = r63043 + r63021;
        double r63045 = r63007 + r63044;
        double r63046 = r63013 / r63045;
        double r63047 = r63028 ? r63037 : r63046;
        double r63048 = r63003 ? r63026 : r63047;
        return r63048;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0.0

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

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

      \[\leadsto \frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\color{blue}{\frac{2}{e^{-2 \cdot x} + 1} \cdot \left(\frac{2}{1 + e^{-2 \cdot x}} + 1\right) + 1 \cdot 1}}\]
    5. Taylor expanded around inf 0.0

      \[\leadsto \color{blue}{\frac{8 \cdot \frac{1}{{\left(e^{-2 \cdot x} + 1\right)}^{3}} - 1}{1 + \left(4 \cdot \frac{1}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} + 2 \cdot \frac{1}{e^{-2 \cdot x} + 1}\right)}}\]
    6. Using strategy rm
    7. Applied add-cbrt-cube0.0

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

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(8 \cdot \frac{1}{{\left(e^{-2 \cdot x} + 1\right)}^{3}} - 1\right) \cdot \left(8 \cdot \frac{1}{{\left(e^{-2 \cdot x} + 1\right)}^{3}} - 1\right)\right) \cdot \left(8 \cdot \frac{1}{{\left(e^{-2 \cdot x} + 1\right)}^{3}} - 1\right)}}}{\sqrt[3]{\left(\left(1 + \left(4 \cdot \frac{1}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} + 2 \cdot \frac{1}{e^{-2 \cdot x} + 1}\right)\right) \cdot \left(1 + \left(4 \cdot \frac{1}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} + 2 \cdot \frac{1}{e^{-2 \cdot x} + 1}\right)\right)\right) \cdot \left(1 + \left(4 \cdot \frac{1}{{\left(e^{-2 \cdot x} + 1\right)}^{2}} + 2 \cdot \frac{1}{e^{-2 \cdot x} + 1}\right)\right)}}\]
    9. Applied cbrt-undiv0.0

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

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

    if -0.003984809264142915 < (* -2.0 x) < 8.592267545673993e-05

    1. Initial program 59.3

      \[\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}{\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)}\]

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

    1. Initial program 0.1

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

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

      \[\leadsto \frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\color{blue}{\frac{2}{e^{-2 \cdot x} + 1} \cdot \left(\frac{2}{1 + e^{-2 \cdot x}} + 1\right) + 1 \cdot 1}}\]
    5. Taylor expanded around inf 0.1

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

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

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

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

Reproduce

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