Average Error: 40.1 → 0.3
Time: 8.3s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.900630394348508378759426973303447994113 \cdot 10^{-4}:\\ \;\;\;\;\frac{\frac{e^{x + x} - 1 \cdot 1}{e^{x} + 1}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{5}{96}, x, \frac{1}{4}\right), 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.900630394348508378759426973303447994113 \cdot 10^{-4}:\\
\;\;\;\;\frac{\frac{e^{x + x} - 1 \cdot 1}{e^{x} + 1}}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{5}{96}, x, \frac{1}{4}\right), 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 r73800 = x;
        double r73801 = exp(r73800);
        double r73802 = 1.0;
        double r73803 = r73801 - r73802;
        double r73804 = r73803 / r73800;
        return r73804;
}

double f(double x) {
        double r73805 = x;
        double r73806 = -0.00019006303943485084;
        bool r73807 = r73805 <= r73806;
        double r73808 = r73805 + r73805;
        double r73809 = exp(r73808);
        double r73810 = 1.0;
        double r73811 = r73810 * r73810;
        double r73812 = r73809 - r73811;
        double r73813 = exp(r73805);
        double r73814 = r73813 + r73810;
        double r73815 = r73812 / r73814;
        double r73816 = r73815 / r73805;
        double r73817 = 0.052083333333333336;
        double r73818 = 0.25;
        double r73819 = fma(r73817, r73805, r73818);
        double r73820 = 1.0;
        double r73821 = fma(r73805, r73819, r73820);
        double r73822 = fma(r73805, r73817, r73818);
        double r73823 = fma(r73805, r73822, r73820);
        double r73824 = r73821 * r73823;
        double r73825 = r73807 ? r73816 : r73824;
        return r73825;
}

Error

Bits error versus x

Target

Original40.1
Target40.5
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.00019006303943485084

    1. Initial program 0.1

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

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

      \[\leadsto \frac{\frac{\color{blue}{e^{x + x} - 1 \cdot 1}}{e^{x} + 1}}{x}\]

    if -0.00019006303943485084 < x

    1. Initial program 60.2

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

      \[\leadsto \sqrt{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{1}{6}, \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)}\]
    10. 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)\]
    11. Simplified0.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{5}{96}, x, \frac{1}{4}\right), 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.900630394348508378759426973303447994113 \cdot 10^{-4}:\\ \;\;\;\;\frac{\frac{e^{x + x} - 1 \cdot 1}{e^{x} + 1}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{5}{96}, x, \frac{1}{4}\right), 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 2019235 +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))