Average Error: 41.2 → 1.1
Time: 11.5s
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 r104850 = x;
        double r104851 = exp(r104850);
        double r104852 = 1.0;
        double r104853 = r104851 - r104852;
        double r104854 = r104851 / r104853;
        return r104854;
}

double f(double x) {
        double r104855 = x;
        double r104856 = exp(r104855);
        double r104857 = 0.16666666666666666;
        double r104858 = 0.5;
        double r104859 = fma(r104855, r104857, r104858);
        double r104860 = r104855 * r104859;
        double r104861 = fma(r104855, r104860, r104855);
        double r104862 = r104856 / r104861;
        return r104862;
}

Error

Bits error versus x

Target

Original41.2
Target40.7
Herbie1.1
\[\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.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 2019351 +o rules:numerics
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

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

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