Average Error: 41.5 → 0.9
Time: 15.7s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\frac{e^{x}}{\mathsf{fma}\left(x \cdot x, \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 \cdot x, \mathsf{fma}\left(x, \frac{1}{6}, \frac{1}{2}\right), x\right)}
double f(double x) {
        double r2801313 = x;
        double r2801314 = exp(r2801313);
        double r2801315 = 1.0;
        double r2801316 = r2801314 - r2801315;
        double r2801317 = r2801314 / r2801316;
        return r2801317;
}

double f(double x) {
        double r2801318 = x;
        double r2801319 = exp(r2801318);
        double r2801320 = r2801318 * r2801318;
        double r2801321 = 0.16666666666666666;
        double r2801322 = 0.5;
        double r2801323 = fma(r2801318, r2801321, r2801322);
        double r2801324 = fma(r2801320, r2801323, r2801318);
        double r2801325 = r2801319 / r2801324;
        return r2801325;
}

Error

Bits error versus x

Target

Original41.5
Target41.2
Herbie0.9
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Initial program 41.5

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

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

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

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

Reproduce

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

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

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