Average Error: 39.8 → 0.3
Time: 16.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(x, \mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), 1\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), x, 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(x, \mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), 1\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), x, 1\right)\\

\end{array}
double f(double x) {
        double r62347 = x;
        double r62348 = exp(r62347);
        double r62349 = 1.0;
        double r62350 = r62348 - r62349;
        double r62351 = r62350 / r62347;
        return r62351;
}

double f(double x) {
        double r62352 = x;
        double r62353 = -0.00017507561591521617;
        bool r62354 = r62352 <= r62353;
        double r62355 = exp(r62352);
        double r62356 = 1.0;
        double r62357 = r62355 - r62356;
        double r62358 = exp(r62357);
        double r62359 = log(r62358);
        double r62360 = r62359 / r62352;
        double r62361 = 0.052083333333333336;
        double r62362 = 0.25;
        double r62363 = fma(r62352, r62361, r62362);
        double r62364 = 1.0;
        double r62365 = fma(r62352, r62363, r62364);
        double r62366 = fma(r62363, r62352, r62364);
        double r62367 = r62365 * r62366;
        double r62368 = r62354 ? r62360 : r62367;
        return r62368;
}

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 \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(\frac{1}{6}, x, \frac{1}{2}\right), 1\right)}\]
    7. Simplified0.5

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

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

      \[\leadsto \mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), 1\right) \cdot \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), x, 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(x, \mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), 1\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(x, \frac{5}{96}, \frac{1}{4}\right), x, 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))