Average Error: 41.2 → 1.0
Time: 15.9s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\frac{e^{x}}{\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, \frac{1}{6}, \frac{1}{2}\right), x\right)}\]
\frac{e^{x}}{e^{x} - 1}
\frac{e^{x}}{\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, \frac{1}{6}, \frac{1}{2}\right), x\right)}
double f(double x) {
        double r82236 = x;
        double r82237 = exp(r82236);
        double r82238 = 1.0;
        double r82239 = r82237 - r82238;
        double r82240 = r82237 / r82239;
        return r82240;
}

double f(double x) {
        double r82241 = x;
        double r82242 = exp(r82241);
        double r82243 = 0.16666666666666666;
        double r82244 = 0.5;
        double r82245 = fma(r82241, r82243, r82244);
        double r82246 = r82241 * r82245;
        double r82247 = fma(r82241, r82246, r82241);
        double r82248 = r82242 / r82247;
        return r82248;
}

Error

Bits error versus x

Target

Original41.2
Target40.8
Herbie1.0
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Initial program 41.2

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

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

    \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, \frac{1}{6}, \frac{1}{2}\right), x\right)}}\]
  4. Final simplification1.0

    \[\leadsto \frac{e^{x}}{\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, \frac{1}{6}, \frac{1}{2}\right), x\right)}\]

Reproduce

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

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

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