Average Error: 41.5 → 0.3
Time: 2.8s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 1.31827911485803592 \cdot 10^{-175} \lor \neg \left(e^{x} \le 1.0000164897469046\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 1.31827911485803592 \cdot 10^{-175} \lor \neg \left(e^{x} \le 1.0000164897469046\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 r98515 = x;
        double r98516 = exp(r98515);
        double r98517 = 1.0;
        double r98518 = r98516 - r98517;
        double r98519 = r98516 / r98518;
        return r98519;
}

double f(double x) {
        double r98520 = x;
        double r98521 = exp(r98520);
        double r98522 = 1.318279114858036e-175;
        bool r98523 = r98521 <= r98522;
        double r98524 = 1.0000164897469046;
        bool r98525 = r98521 <= r98524;
        double r98526 = !r98525;
        bool r98527 = r98523 || r98526;
        double r98528 = 1.0;
        double r98529 = 1.0;
        double r98530 = r98529 / r98521;
        double r98531 = r98528 - r98530;
        double r98532 = r98528 / r98531;
        double r98533 = 0.08333333333333333;
        double r98534 = r98528 / r98520;
        double r98535 = fma(r98533, r98520, r98534);
        double r98536 = 0.5;
        double r98537 = r98535 + r98536;
        double r98538 = r98527 ? r98532 : r98537;
        return r98538;
}

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (exp x) < 1.318279114858036e-175 or 1.0000164897469046 < (exp x)

    1. Initial program 1.8

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

      \[\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 1.318279114858036e-175 < (exp x) < 1.0000164897469046

    1. Initial program 62.2

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

      \[\leadsto \color{blue}{\frac{1}{2} + \left(\frac{1}{12} \cdot x + \frac{1}{x}\right)}\]
    3. Simplified0.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.3

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

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

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