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

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r59024 = 2.0;
        double r59025 = 1.0;
        double r59026 = -2.0;
        double r59027 = x;
        double r59028 = r59026 * r59027;
        double r59029 = exp(r59028);
        double r59030 = r59025 + r59029;
        double r59031 = r59024 / r59030;
        double r59032 = r59031 - r59025;
        return r59032;
}

double f(double x, double __attribute__((unused)) y) {
        double r59033 = -2.0;
        double r59034 = x;
        double r59035 = r59033 * r59034;
        double r59036 = -0.0018803992190449508;
        bool r59037 = r59035 <= r59036;
        double r59038 = 1.0;
        double r59039 = 1.0;
        double r59040 = exp(r59035);
        double r59041 = r59039 + r59040;
        double r59042 = sqrt(r59041);
        double r59043 = r59038 / r59042;
        double r59044 = cbrt(r59043);
        double r59045 = r59044 * r59044;
        double r59046 = r59045 * r59044;
        double r59047 = 2.0;
        double r59048 = r59047 / r59042;
        double r59049 = -r59039;
        double r59050 = fma(r59046, r59048, r59049);
        double r59051 = log(r59050);
        double r59052 = exp(r59051);
        double r59053 = 0.0010079466525599351;
        bool r59054 = r59035 <= r59053;
        double r59055 = 5.551115123125783e-17;
        double r59056 = 4.0;
        double r59057 = pow(r59034, r59056);
        double r59058 = 0.33333333333333337;
        double r59059 = 3.0;
        double r59060 = pow(r59034, r59059);
        double r59061 = r59058 * r59060;
        double r59062 = fma(r59055, r59057, r59061);
        double r59063 = -r59062;
        double r59064 = fma(r59039, r59034, r59063);
        double r59065 = fma(r59043, r59048, r59049);
        double r59066 = cbrt(r59065);
        double r59067 = r59066 * r59066;
        double r59068 = r59067 * r59066;
        double r59069 = r59054 ? r59064 : r59068;
        double r59070 = r59037 ? r59052 : r59069;
        return r59070;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    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.1

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

      \[\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-cube-cbrt0.1

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\sqrt[3]{\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}} \cdot \sqrt[3]{\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}}\right) \cdot \sqrt[3]{\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)\]
    9. Using strategy rm
    10. Applied add-exp-log0.1

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

    if -0.0018803992190449508 < (* -2.0 x) < 0.0010079466525599351

    1. Initial program 59.0

      \[\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 0.0010079466525599351 < (* -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.1

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

      \[\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-cube-cbrt0.1

      \[\leadsto \color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\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}\;-2 \cdot x \le -0.00188039921904495084:\\ \;\;\;\;e^{\log \left(\mathsf{fma}\left(\left(\sqrt[3]{\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}} \cdot \sqrt[3]{\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}}\right) \cdot \sqrt[3]{\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)\right)}\\ \mathbf{elif}\;-2 \cdot x \le 0.00100794665255993514:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\\ \end{array}\]

Reproduce

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