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

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

\end{array}
double f(double x) {
        double r80075 = x;
        double r80076 = exp(r80075);
        double r80077 = 1.0;
        double r80078 = r80076 - r80077;
        double r80079 = r80078 / r80075;
        return r80079;
}

double f(double x) {
        double r80080 = x;
        double r80081 = -0.00019073022953316793;
        bool r80082 = r80080 <= r80081;
        double r80083 = exp(r80080);
        double r80084 = 1.0;
        double r80085 = r80083 - r80084;
        double r80086 = exp(r80085);
        double r80087 = log(r80086);
        double r80088 = r80087 / r80080;
        double r80089 = 0.052083333333333336;
        double r80090 = 2.0;
        double r80091 = pow(r80080, r80090);
        double r80092 = 0.25;
        double r80093 = 1.0;
        double r80094 = fma(r80092, r80080, r80093);
        double r80095 = fma(r80089, r80091, r80094);
        double r80096 = 0.16666666666666666;
        double r80097 = 0.5;
        double r80098 = fma(r80080, r80096, r80097);
        double r80099 = fma(r80080, r80098, r80093);
        double r80100 = sqrt(r80099);
        double r80101 = r80095 * r80100;
        double r80102 = r80082 ? r80088 : r80101;
        return r80102;
}

Error

Bits error versus x

Target

Original39.6
Target40.0
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.00019073022953316793

    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.1

      \[\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.1

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

    if -0.00019073022953316793 < 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(\frac{1}{6}, x \cdot x, \mathsf{fma}\left(\frac{1}{2}, x, 1\right)\right)}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt0.4

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

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

      \[\leadsto \sqrt{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{1}{6}, \frac{1}{2}\right), 1\right)} \cdot \color{blue}{\sqrt{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{1}{6}, \frac{1}{2}\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 \sqrt{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{1}{6}, \frac{1}{2}\right), 1\right)}\]
    9. Simplified0.4

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

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

Reproduce

herbie shell --seed 2019323 +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))