Average Error: 39.8 → 0.3
Time: 15.3s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.750756159152161677960285457444911116909 \cdot 10^{-4}:\\ \;\;\;\;\frac{\log \left(e^{e^{x} - 1}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), x, 1\right) \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), 1\right)\\ \end{array}\]
\frac{e^{x} - 1}{x}
\begin{array}{l}
\mathbf{if}\;x \le -1.750756159152161677960285457444911116909 \cdot 10^{-4}:\\
\;\;\;\;\frac{\log \left(e^{e^{x} - 1}\right)}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), x, 1\right) \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), 1\right)\\

\end{array}
double f(double x) {
        double r68980 = x;
        double r68981 = exp(r68980);
        double r68982 = 1.0;
        double r68983 = r68981 - r68982;
        double r68984 = r68983 / r68980;
        return r68984;
}

double f(double x) {
        double r68985 = x;
        double r68986 = -0.00017507561591521617;
        bool r68987 = r68985 <= r68986;
        double r68988 = exp(r68985);
        double r68989 = 1.0;
        double r68990 = r68988 - r68989;
        double r68991 = exp(r68990);
        double r68992 = log(r68991);
        double r68993 = r68992 / r68985;
        double r68994 = 0.052083333333333336;
        double r68995 = 0.25;
        double r68996 = fma(r68985, r68994, r68995);
        double r68997 = 1.0;
        double r68998 = fma(r68996, r68985, r68997);
        double r68999 = fma(r68985, r68996, r68997);
        double r69000 = r68998 * r68999;
        double r69001 = r68987 ? r68993 : r69000;
        return r69001;
}

Error

Bits error versus x

Target

Original39.8
Target40.3
Herbie0.3
\[\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. Split input into 2 regimes
  2. if x < -0.00017507561591521617

    1. Initial program 0.0

      \[\frac{e^{x} - 1}{x}\]
    2. Using strategy rm
    3. Applied add-log-exp0.0

      \[\leadsto \frac{e^{x} - \color{blue}{\log \left(e^{1}\right)}}{x}\]
    4. Applied add-log-exp0.0

      \[\leadsto \frac{\color{blue}{\log \left(e^{e^{x}}\right)} - \log \left(e^{1}\right)}{x}\]
    5. Applied diff-log0.1

      \[\leadsto \frac{\color{blue}{\log \left(\frac{e^{e^{x}}}{e^{1}}\right)}}{x}\]
    6. Simplified0.0

      \[\leadsto \frac{\log \color{blue}{\left(e^{e^{x} - 1}\right)}}{x}\]

    if -0.00017507561591521617 < x

    1. Initial program 60.1

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{1}{6}, x, \frac{1}{2}\right), 1\right)}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt0.5

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{1}{6}, x, \frac{1}{2}\right), 1\right)} \cdot \sqrt{\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{1}{6}, x, \frac{1}{2}\right), 1\right)}}\]
    6. Taylor expanded around 0 0.5

      \[\leadsto \sqrt{\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{1}{6}, x, \frac{1}{2}\right), 1\right)} \cdot \color{blue}{\left(\frac{5}{96} \cdot {x}^{2} + \left(\frac{1}{4} \cdot x + 1\right)\right)}\]
    7. Simplified0.5

      \[\leadsto \sqrt{\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{1}{6}, x, \frac{1}{2}\right), 1\right)} \cdot \color{blue}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), 1\right)}\]
    8. Taylor expanded around 0 0.4

      \[\leadsto \color{blue}{\left(\frac{5}{96} \cdot {x}^{2} + \left(\frac{1}{4} \cdot x + 1\right)\right)} \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), 1\right)\]
    9. Simplified0.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), x, 1\right)} \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), 1\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.750756159152161677960285457444911116909 \cdot 10^{-4}:\\ \;\;\;\;\frac{\log \left(e^{e^{x} - 1}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), x, 1\right) \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), 1\right)\\ \end{array}\]

Reproduce

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

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

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