Average Error: 41.0 → 0.0
Time: 12.8s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.9967130846117587816834770819696132093668:\\ \;\;\;\;\left(\frac{\sqrt[3]{e^{x}}}{\sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}} \cdot \sqrt[3]{e^{x}}\right) \cdot \frac{\sqrt[3]{e^{x}}}{\sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}\\ \mathbf{elif}\;e^{x} \le 1.000051799989470246998735092347487807274:\\ \;\;\;\;\frac{1}{x} + \mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 - \frac{1}{e^{x}}}\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \le 0.9967130846117587816834770819696132093668:\\
\;\;\;\;\left(\frac{\sqrt[3]{e^{x}}}{\sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}} \cdot \sqrt[3]{e^{x}}\right) \cdot \frac{\sqrt[3]{e^{x}}}{\sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}\\

\mathbf{elif}\;e^{x} \le 1.000051799989470246998735092347487807274:\\
\;\;\;\;\frac{1}{x} + \mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{1 - \frac{1}{e^{x}}}\\

\end{array}
double f(double x) {
        double r114077 = x;
        double r114078 = exp(r114077);
        double r114079 = 1.0;
        double r114080 = r114078 - r114079;
        double r114081 = r114078 / r114080;
        return r114081;
}

double f(double x) {
        double r114082 = x;
        double r114083 = exp(r114082);
        double r114084 = 0.9967130846117588;
        bool r114085 = r114083 <= r114084;
        double r114086 = cbrt(r114083);
        double r114087 = 1.0;
        double r114088 = -r114087;
        double r114089 = r114082 + r114082;
        double r114090 = exp(r114089);
        double r114091 = fma(r114088, r114087, r114090);
        double r114092 = r114083 + r114087;
        double r114093 = r114091 / r114092;
        double r114094 = cbrt(r114093);
        double r114095 = r114094 * r114094;
        double r114096 = r114086 / r114095;
        double r114097 = r114096 * r114086;
        double r114098 = r114086 / r114094;
        double r114099 = r114097 * r114098;
        double r114100 = 1.0000517999894702;
        bool r114101 = r114083 <= r114100;
        double r114102 = 1.0;
        double r114103 = r114102 / r114082;
        double r114104 = 0.08333333333333333;
        double r114105 = 0.5;
        double r114106 = fma(r114104, r114082, r114105);
        double r114107 = r114103 + r114106;
        double r114108 = r114087 / r114083;
        double r114109 = r114102 - r114108;
        double r114110 = r114102 / r114109;
        double r114111 = r114101 ? r114107 : r114110;
        double r114112 = r114085 ? r114099 : r114111;
        return r114112;
}

Error

Bits error versus x

Target

Original41.0
Target40.5
Herbie0.0
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Split input into 3 regimes
  2. if (exp x) < 0.9967130846117588

    1. Initial program 0.0

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

      \[\leadsto \frac{e^{x}}{\color{blue}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}}\]
    4. Simplified0.0

      \[\leadsto \frac{e^{x}}{\frac{\color{blue}{\mathsf{fma}\left(1, -1, e^{x + x}\right)}}{e^{x} + 1}}\]
    5. Simplified0.0

      \[\leadsto \frac{e^{x}}{\frac{\mathsf{fma}\left(1, -1, e^{x + x}\right)}{\color{blue}{1 + e^{x}}}}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt0.0

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

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

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

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

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

    if 0.9967130846117588 < (exp x) < 1.0000517999894702

    1. Initial program 62.6

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right) + \frac{1}{x}}\]

    if 1.0000517999894702 < (exp x)

    1. Initial program 35.6

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied clear-num35.6

      \[\leadsto \color{blue}{\frac{1}{\frac{e^{x} - 1}{e^{x}}}}\]
    4. Simplified2.1

      \[\leadsto \frac{1}{\color{blue}{1 - \frac{1}{e^{x}}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{x} \le 0.9967130846117587816834770819696132093668:\\ \;\;\;\;\left(\frac{\sqrt[3]{e^{x}}}{\sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}} \cdot \sqrt[3]{e^{x}}\right) \cdot \frac{\sqrt[3]{e^{x}}}{\sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}\\ \mathbf{elif}\;e^{x} \le 1.000051799989470246998735092347487807274:\\ \;\;\;\;\frac{1}{x} + \mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 - \frac{1}{e^{x}}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019174 +o rules:numerics
(FPCore (x)
  :name "expq2 (section 3.11)"

  :herbie-target
  (/ 1.0 (- 1.0 (exp (- x))))

  (/ (exp x) (- (exp x) 1.0)))