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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{x}\right) + \frac{1}{2}\\

\end{array}
double f(double x) {
        double r129272 = x;
        double r129273 = exp(r129272);
        double r129274 = 1.0;
        double r129275 = r129273 - r129274;
        double r129276 = r129273 / r129275;
        return r129276;
}

double f(double x) {
        double r129277 = x;
        double r129278 = exp(r129277);
        double r129279 = 0.0;
        bool r129280 = r129278 <= r129279;
        double r129281 = 1.0;
        double r129282 = 1.0;
        double r129283 = r129282 / r129278;
        double r129284 = r129281 - r129283;
        double r129285 = r129281 / r129284;
        double r129286 = cbrt(r129285);
        double r129287 = r129286 * r129286;
        double r129288 = r129287 * r129286;
        double r129289 = 0.08333333333333333;
        double r129290 = r129281 / r129277;
        double r129291 = fma(r129289, r129277, r129290);
        double r129292 = 0.5;
        double r129293 = r129291 + r129292;
        double r129294 = r129280 ? r129288 : r129293;
        return r129294;
}

Error

Bits error versus x

Target

Original41.7
Target41.3
Herbie0.8
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 0

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

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

      \[\leadsto \frac{1}{\color{blue}{1 - \frac{1}{e^{x}}}}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt0

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

    if 0.0 < (exp x)

    1. Initial program 61.6

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{x}\right) + \frac{1}{2}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.8

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

Reproduce

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

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

  (/ (exp x) (- (exp x) 1)))