Average Error: 40.8 → 0.8
Time: 11.3s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.0:\\ \;\;\;\;\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:\\
\;\;\;\;\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 r128317 = x;
        double r128318 = exp(r128317);
        double r128319 = 1.0;
        double r128320 = r128318 - r128319;
        double r128321 = r128318 / r128320;
        return r128321;
}

double f(double x) {
        double r128322 = x;
        double r128323 = exp(r128322);
        double r128324 = 0.0;
        bool r128325 = r128323 <= r128324;
        double r128326 = 1.0;
        double r128327 = 1.0;
        double r128328 = r128327 / r128323;
        double r128329 = r128326 - r128328;
        double r128330 = r128326 / r128329;
        double r128331 = 0.08333333333333333;
        double r128332 = r128326 / r128322;
        double r128333 = fma(r128331, r128322, r128332);
        double r128334 = 0.5;
        double r128335 = r128333 + r128334;
        double r128336 = r128325 ? r128330 : r128335;
        return r128336;
}

Error

Bits error versus x

Target

Original40.8
Target40.4
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}}}}\]

    if 0.0 < (exp x)

    1. Initial program 61.2

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

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

      \[\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:\\ \;\;\;\;\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 2020045 +o rules:numerics
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

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

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