Average Error: 40.2 → 0.4
Time: 12.8s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\mathsf{fma}\left(\frac{e^{x}}{\mathsf{expm1}\left(x + x\right)}, e^{x}, \frac{e^{x}}{\mathsf{expm1}\left(x + x\right)}\right)\]
\frac{e^{x}}{e^{x} - 1}
\mathsf{fma}\left(\frac{e^{x}}{\mathsf{expm1}\left(x + x\right)}, e^{x}, \frac{e^{x}}{\mathsf{expm1}\left(x + x\right)}\right)
double f(double x) {
        double r3130899 = x;
        double r3130900 = exp(r3130899);
        double r3130901 = 1.0;
        double r3130902 = r3130900 - r3130901;
        double r3130903 = r3130900 / r3130902;
        return r3130903;
}

double f(double x) {
        double r3130904 = x;
        double r3130905 = exp(r3130904);
        double r3130906 = r3130904 + r3130904;
        double r3130907 = expm1(r3130906);
        double r3130908 = r3130905 / r3130907;
        double r3130909 = fma(r3130908, r3130905, r3130908);
        return r3130909;
}

Error

Bits error versus x

Target

Original40.2
Target39.8
Herbie0.4
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Initial program 40.2

    \[\frac{e^{x}}{e^{x} - 1}\]
  2. Using strategy rm
  3. Applied flip--40.2

    \[\leadsto \frac{e^{x}}{\color{blue}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}}\]
  4. Applied associate-/r/40.2

    \[\leadsto \color{blue}{\frac{e^{x}}{e^{x} \cdot e^{x} - 1 \cdot 1} \cdot \left(e^{x} + 1\right)}\]
  5. Simplified0.4

    \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x + x\right)}} \cdot \left(e^{x} + 1\right)\]
  6. Using strategy rm
  7. Applied *-un-lft-identity0.4

    \[\leadsto \color{blue}{\left(1 \cdot \frac{e^{x}}{\mathsf{expm1}\left(x + x\right)}\right)} \cdot \left(e^{x} + 1\right)\]
  8. Applied associate-*l*0.4

    \[\leadsto \color{blue}{1 \cdot \left(\frac{e^{x}}{\mathsf{expm1}\left(x + x\right)} \cdot \left(e^{x} + 1\right)\right)}\]
  9. Simplified0.4

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

    \[\leadsto \mathsf{fma}\left(\frac{e^{x}}{\mathsf{expm1}\left(x + x\right)}, e^{x}, \frac{e^{x}}{\mathsf{expm1}\left(x + x\right)}\right)\]

Reproduce

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

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

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