Average Error: 40.9 → 1.1
Time: 17.4s
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 r72984 = x;
        double r72985 = exp(r72984);
        double r72986 = 1.0;
        double r72987 = r72985 - r72986;
        double r72988 = r72985 / r72987;
        return r72988;
}

double f(double x) {
        double r72989 = x;
        double r72990 = exp(r72989);
        double r72991 = 0.16666666666666666;
        double r72992 = 0.5;
        double r72993 = fma(r72989, r72991, r72992);
        double r72994 = r72989 * r72993;
        double r72995 = fma(r72989, r72994, r72989);
        double r72996 = r72990 / r72995;
        return r72996;
}

Error

Bits error versus x

Target

Original40.9
Target40.5
Herbie1.1
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Initial program 40.9

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

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

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

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

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

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