Average Error: 29.0 → 0.6
Time: 4.2s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -17964639.956402041:\\ \;\;\;\;\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)}\\ \mathbf{elif}\;-2 \cdot x \le 3.59556513046770647 \cdot 10^{-10}:\\ \;\;\;\;\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{\sqrt{1 + e^{-2 \cdot x}}}} \cdot \frac{1}{\sqrt{\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 -17964639.956402041:\\
\;\;\;\;\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)}\\

\mathbf{elif}\;-2 \cdot x \le 3.59556513046770647 \cdot 10^{-10}:\\
\;\;\;\;\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{\sqrt{1 + e^{-2 \cdot x}}}} \cdot \frac{1}{\sqrt{\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 r57996 = 2.0;
        double r57997 = 1.0;
        double r57998 = -2.0;
        double r57999 = x;
        double r58000 = r57998 * r57999;
        double r58001 = exp(r58000);
        double r58002 = r57997 + r58001;
        double r58003 = r57996 / r58002;
        double r58004 = r58003 - r57997;
        return r58004;
}

double f(double x, double __attribute__((unused)) y) {
        double r58005 = -2.0;
        double r58006 = x;
        double r58007 = r58005 * r58006;
        double r58008 = -17964639.95640204;
        bool r58009 = r58007 <= r58008;
        double r58010 = 1.0;
        double r58011 = 1.0;
        double r58012 = exp(r58007);
        double r58013 = r58011 + r58012;
        double r58014 = sqrt(r58013);
        double r58015 = r58010 / r58014;
        double r58016 = 2.0;
        double r58017 = r58016 / r58014;
        double r58018 = -r58011;
        double r58019 = fma(r58015, r58017, r58018);
        double r58020 = cbrt(r58019);
        double r58021 = r58020 * r58020;
        double r58022 = r58021 * r58020;
        double r58023 = 3.5955651304677065e-10;
        bool r58024 = r58007 <= r58023;
        double r58025 = 5.551115123125783e-17;
        double r58026 = 4.0;
        double r58027 = pow(r58006, r58026);
        double r58028 = 0.33333333333333337;
        double r58029 = 3.0;
        double r58030 = pow(r58006, r58029);
        double r58031 = r58028 * r58030;
        double r58032 = fma(r58025, r58027, r58031);
        double r58033 = -r58032;
        double r58034 = fma(r58011, r58006, r58033);
        double r58035 = sqrt(r58014);
        double r58036 = r58010 / r58035;
        double r58037 = r58036 * r58036;
        double r58038 = fma(r58037, r58017, r58018);
        double r58039 = cbrt(r58038);
        double r58040 = r58021 * r58039;
        double r58041 = r58024 ? r58034 : r58040;
        double r58042 = r58009 ? r58022 : r58041;
        return r58042;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0

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

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

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

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

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

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

    if -17964639.95640204 < (* -2.0 x) < 3.5955651304677065e-10

    1. Initial program 58.6

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

      \[\leadsto \color{blue}{1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)}\]
    3. Simplified1.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 3.5955651304677065e-10 < (* -2.0 x)

    1. Initial program 0.5

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

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

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

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

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

      \[\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)}}\]
    9. Using strategy rm
    10. Applied add-sqr-sqrt0.5

      \[\leadsto \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{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\]
    11. Applied sqrt-prod0.5

      \[\leadsto \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}{\color{blue}{\sqrt{\sqrt{1 + e^{-2 \cdot x}}} \cdot \sqrt{\sqrt{1 + e^{-2 \cdot x}}}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\]
    12. Applied add-cube-cbrt0.5

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

      \[\leadsto \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(\color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\sqrt{\sqrt{1 + e^{-2 \cdot x}}}} \cdot \frac{\sqrt[3]{1}}{\sqrt{\sqrt{1 + e^{-2 \cdot x}}}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\]
    14. Simplified0.5

      \[\leadsto \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(\color{blue}{\frac{1}{\sqrt{\sqrt{1 + e^{-2 \cdot x}}}}} \cdot \frac{\sqrt[3]{1}}{\sqrt{\sqrt{1 + e^{-2 \cdot x}}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\]
    15. Simplified0.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -17964639.956402041:\\ \;\;\;\;\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)}\\ \mathbf{elif}\;-2 \cdot x \le 3.59556513046770647 \cdot 10^{-10}:\\ \;\;\;\;\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{\sqrt{1 + e^{-2 \cdot x}}}} \cdot \frac{1}{\sqrt{\sqrt{1 + e^{-2 \cdot x}}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\\ \end{array}\]

Reproduce

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