Average Error: 39.6 → 0.3
Time: 16.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}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{1}{6}, x, \frac{1}{2}\right), 1\right)} \cdot \sqrt[3]{{\left(\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{5}{96}, x, \frac{1}{4}\right), 1\right)\right)}^{3}}\\ \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}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{1}{6}, x, \frac{1}{2}\right), 1\right)} \cdot \sqrt[3]{{\left(\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{5}{96}, x, \frac{1}{4}\right), 1\right)\right)}^{3}}\\

\end{array}
double f(double x) {
        double r100721 = x;
        double r100722 = exp(r100721);
        double r100723 = 1.0;
        double r100724 = r100722 - r100723;
        double r100725 = r100724 / r100721;
        return r100725;
}

double f(double x) {
        double r100726 = x;
        double r100727 = -0.00019073022953316793;
        bool r100728 = r100726 <= r100727;
        double r100729 = exp(r100726);
        double r100730 = 1.0;
        double r100731 = r100729 - r100730;
        double r100732 = exp(r100731);
        double r100733 = log(r100732);
        double r100734 = r100733 / r100726;
        double r100735 = 0.16666666666666666;
        double r100736 = 0.5;
        double r100737 = fma(r100735, r100726, r100736);
        double r100738 = 1.0;
        double r100739 = fma(r100726, r100737, r100738);
        double r100740 = sqrt(r100739);
        double r100741 = 0.052083333333333336;
        double r100742 = 0.25;
        double r100743 = fma(r100741, r100726, r100742);
        double r100744 = fma(r100726, r100743, r100738);
        double r100745 = 3.0;
        double r100746 = pow(r100744, r100745);
        double r100747 = cbrt(r100746);
        double r100748 = r100740 * r100747;
        double r100749 = r100728 ? r100734 : r100748;
        return r100749;
}

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

      \[\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. Using strategy rm
    7. Applied add-cbrt-cube0.4

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

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

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

      \[\leadsto \sqrt{\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{1}{6}, x, \frac{1}{2}\right), 1\right)} \cdot \sqrt[3]{{\color{blue}{\left(\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{5}{96}, x, \frac{1}{4}\right), 1\right)\right)}}^{3}}\]
  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}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{1}{6}, x, \frac{1}{2}\right), 1\right)} \cdot \sqrt[3]{{\left(\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{5}{96}, x, \frac{1}{4}\right), 1\right)\right)}^{3}}\\ \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))