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

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

\end{array}
double f(double x) {
        double r3631307 = x;
        double r3631308 = exp(r3631307);
        double r3631309 = 1.0;
        double r3631310 = r3631308 - r3631309;
        double r3631311 = r3631310 / r3631307;
        return r3631311;
}

double f(double x) {
        double r3631312 = x;
        double r3631313 = -0.00016689112366788532;
        bool r3631314 = r3631312 <= r3631313;
        double r3631315 = exp(r3631312);
        double r3631316 = 1.0;
        double r3631317 = r3631315 - r3631316;
        double r3631318 = r3631317 / r3631312;
        double r3631319 = 0.16666666666666666;
        double r3631320 = 0.5;
        double r3631321 = fma(r3631319, r3631312, r3631320);
        double r3631322 = 1.0;
        double r3631323 = fma(r3631312, r3631321, r3631322);
        double r3631324 = r3631314 ? r3631318 : r3631323;
        return r3631324;
}

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

    1. Initial program 0.0

      \[\frac{e^{x} - 1}{x}\]

    if -0.00016689112366788532 < x

    1. Initial program 60.1

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{1}{6}, x, \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.668911236678853246811343735700461365923 \cdot 10^{-4}:\\ \;\;\;\;\frac{e^{x} - 1}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{1}{6}, x, \frac{1}{2}\right), 1\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019172 +o rules:numerics
(FPCore (x)
  :name "Kahan's exp quotient"

  :herbie-target
  (if (and (< x 1.0) (> x -1.0)) (/ (- (exp x) 1.0) (log (exp x))) (/ (- (exp x) 1.0) x))

  (/ (- (exp x) 1.0) x))