Average Error: 40.5 → 0.7
Time: 3.3s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.0184360243772397382:\\ \;\;\;\;\frac{e^{x}}{e^{x} - 1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-x, \frac{1}{12}, \mathsf{fma}\left({x}^{3}, \frac{7}{720}, \frac{\frac{1}{2}}{x}\right)\right) \cdot \left(e^{x} + 1\right)\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \le 0.0184360243772397382:\\
\;\;\;\;\frac{e^{x}}{e^{x} - 1}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, \frac{1}{12}, \mathsf{fma}\left({x}^{3}, \frac{7}{720}, \frac{\frac{1}{2}}{x}\right)\right) \cdot \left(e^{x} + 1\right)\\

\end{array}
double f(double x) {
        double r93447 = x;
        double r93448 = exp(r93447);
        double r93449 = 1.0;
        double r93450 = r93448 - r93449;
        double r93451 = r93448 / r93450;
        return r93451;
}

double f(double x) {
        double r93452 = x;
        double r93453 = exp(r93452);
        double r93454 = 0.018436024377239738;
        bool r93455 = r93453 <= r93454;
        double r93456 = 1.0;
        double r93457 = r93453 - r93456;
        double r93458 = r93453 / r93457;
        double r93459 = -r93452;
        double r93460 = 0.08333333333333333;
        double r93461 = 3.0;
        double r93462 = pow(r93452, r93461);
        double r93463 = 0.009722222222222222;
        double r93464 = 0.5;
        double r93465 = r93464 / r93452;
        double r93466 = fma(r93462, r93463, r93465);
        double r93467 = fma(r93459, r93460, r93466);
        double r93468 = r93453 + r93456;
        double r93469 = r93467 * r93468;
        double r93470 = r93455 ? r93458 : r93469;
        return r93470;
}

Error

Bits error versus x

Target

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

Derivation

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

    1. Initial program 0.0

      \[\frac{e^{x}}{e^{x} - 1}\]

    if 0.018436024377239738 < (exp x)

    1. Initial program 61.4

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

      \[\leadsto \frac{e^{x}}{\color{blue}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}}\]
    4. Applied associate-/r/61.4

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

      \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}} \cdot \left(e^{x} + 1\right)\]
    6. Taylor expanded around 0 1.1

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

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

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

Reproduce

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

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

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