Average Error: 41.2 → 1.0
Time: 30.4s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\frac{e^{x}}{\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(\frac{1}{6}, x, \frac{1}{2}\right), x\right)}\]
\frac{e^{x}}{e^{x} - 1}
\frac{e^{x}}{\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(\frac{1}{6}, x, \frac{1}{2}\right), x\right)}
double f(double x) {
        double r5567802 = x;
        double r5567803 = exp(r5567802);
        double r5567804 = 1.0;
        double r5567805 = r5567803 - r5567804;
        double r5567806 = r5567803 / r5567805;
        return r5567806;
}

double f(double x) {
        double r5567807 = x;
        double r5567808 = exp(r5567807);
        double r5567809 = r5567807 * r5567807;
        double r5567810 = 0.16666666666666666;
        double r5567811 = 0.5;
        double r5567812 = fma(r5567810, r5567807, r5567811);
        double r5567813 = fma(r5567809, r5567812, r5567807);
        double r5567814 = r5567808 / r5567813;
        return r5567814;
}

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}{x + \left(\frac{1}{6} \cdot {x}^{3} + \frac{1}{2} \cdot {x}^{2}\right)}}\]
  3. Simplified1.0

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

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

Reproduce

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

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

  (/ (exp x) (- (exp x) 1.0)))