Average Error: 40.5 → 0.3
Time: 12.3s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.0 \lor \neg \left(e^{x} \le 1.0001616862874831\right):\\ \;\;\;\;\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 \lor \neg \left(e^{x} \le 1.0001616862874831\right):\\
\;\;\;\;\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 r97559 = x;
        double r97560 = exp(r97559);
        double r97561 = 1.0;
        double r97562 = r97560 - r97561;
        double r97563 = r97560 / r97562;
        return r97563;
}

double f(double x) {
        double r97564 = x;
        double r97565 = exp(r97564);
        double r97566 = 0.0;
        bool r97567 = r97565 <= r97566;
        double r97568 = 1.0001616862874831;
        bool r97569 = r97565 <= r97568;
        double r97570 = !r97569;
        bool r97571 = r97567 || r97570;
        double r97572 = 1.0;
        double r97573 = 1.0;
        double r97574 = r97573 / r97565;
        double r97575 = r97572 - r97574;
        double r97576 = r97572 / r97575;
        double r97577 = 0.08333333333333333;
        double r97578 = r97572 / r97564;
        double r97579 = fma(r97577, r97564, r97578);
        double r97580 = 0.5;
        double r97581 = r97579 + r97580;
        double r97582 = r97571 ? r97576 : r97581;
        return r97582;
}

Error

Bits error versus x

Target

Original40.5
Target40.1
Herbie0.3
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 1.3

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

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

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

    if 0.0 < (exp x) < 1.0001616862874831

    1. Initial program 62.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{x} \le 0.0 \lor \neg \left(e^{x} \le 1.0001616862874831\right):\\ \;\;\;\;\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 2020043 +o rules:numerics
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

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

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