Average Error: 40.1 → 0.0
Time: 14.8s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\frac{(e^{x} - 1)^*}{x}\]
double f(double x) {
        double r5959291 = x;
        double r5959292 = exp(r5959291);
        double r5959293 = 1.0;
        double r5959294 = r5959292 - r5959293;
        double r5959295 = r5959294 / r5959291;
        return r5959295;
}

double f(double x) {
        double r5959296 = x;
        double r5959297 = expm1(r5959296);
        double r5959298 = r5959297 / r5959296;
        return r5959298;
}

\frac{e^{x} - 1}{x}
\frac{(e^{x} - 1)^*}{x}

Error

Bits error versus x

Target

Original40.1
Target39.2
Herbie0.0
\[\begin{array}{l} \mathbf{if}\;x \lt 1 \land x \gt -1:\\ \;\;\;\;\frac{e^{x} - 1}{\log \left(e^{x}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{x} - 1}{x}\\ \end{array}\]

Derivation

  1. Initial program 40.1

    \[\frac{e^{x} - 1}{x}\]
  2. Simplified0.0

    \[\leadsto \color{blue}{\frac{(e^{x} - 1)^*}{x}}\]
  3. Taylor expanded around inf 40.1

    \[\leadsto \color{blue}{\frac{e^{x} - 1}{x}}\]
  4. Simplified0.0

    \[\leadsto \color{blue}{\frac{(e^{x} - 1)^*}{x}}\]
  5. Final simplification0.0

    \[\leadsto \frac{(e^{x} - 1)^*}{x}\]

Reproduce

herbie shell --seed 2019101 +o rules:numerics
(FPCore (x)
  :name "Kahan's exp quotient"

  :herbie-target
  (if (and (< x 1) (> x -1)) (/ (- (exp x) 1) (log (exp x))) (/ (- (exp x) 1) x))

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