Average Error: 39.9 → 0.4
Time: 7.7s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.304505555650203115110319362912605356541 \cdot 10^{-4}:\\ \;\;\;\;\frac{\frac{e^{x + x} - 1 \cdot 1}{e^{x} + 1}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{6}, x \cdot x, \mathsf{fma}\left(\frac{1}{2}, x, 1\right)\right)\\ \end{array}\]
\frac{e^{x} - 1}{x}
\begin{array}{l}
\mathbf{if}\;x \le -1.304505555650203115110319362912605356541 \cdot 10^{-4}:\\
\;\;\;\;\frac{\frac{e^{x + x} - 1 \cdot 1}{e^{x} + 1}}{x}\\

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

\end{array}
double f(double x) {
        double r82825 = x;
        double r82826 = exp(r82825);
        double r82827 = 1.0;
        double r82828 = r82826 - r82827;
        double r82829 = r82828 / r82825;
        return r82829;
}

double f(double x) {
        double r82830 = x;
        double r82831 = -0.0001304505555650203;
        bool r82832 = r82830 <= r82831;
        double r82833 = r82830 + r82830;
        double r82834 = exp(r82833);
        double r82835 = 1.0;
        double r82836 = r82835 * r82835;
        double r82837 = r82834 - r82836;
        double r82838 = exp(r82830);
        double r82839 = r82838 + r82835;
        double r82840 = r82837 / r82839;
        double r82841 = r82840 / r82830;
        double r82842 = 0.16666666666666666;
        double r82843 = r82830 * r82830;
        double r82844 = 0.5;
        double r82845 = 1.0;
        double r82846 = fma(r82844, r82830, r82845);
        double r82847 = fma(r82842, r82843, r82846);
        double r82848 = r82832 ? r82841 : r82847;
        return r82848;
}

Error

Bits error versus x

Target

Original39.9
Target40.3
Herbie0.4
\[\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.0001304505555650203

    1. Initial program 0.0

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

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

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

    if -0.0001304505555650203 < x

    1. Initial program 60.0

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

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

      \[\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 *-un-lft-identity0.5

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

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

Reproduce

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