Average Error: 40.1 → 0.3
Time: 9.7s
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, \frac{1}{2}, \mathsf{fma}\left(\frac{1}{6}, x \cdot x, 1\right)\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, \frac{1}{2}, \mathsf{fma}\left(\frac{1}{6}, x \cdot x, 1\right)\right)\\

\end{array}
double f(double x) {
        double r3326281 = x;
        double r3326282 = exp(r3326281);
        double r3326283 = 1.0;
        double r3326284 = r3326282 - r3326283;
        double r3326285 = r3326284 / r3326281;
        return r3326285;
}

double f(double x) {
        double r3326286 = x;
        double r3326287 = -0.00016689112366788532;
        bool r3326288 = r3326286 <= r3326287;
        double r3326289 = exp(r3326286);
        double r3326290 = 1.0;
        double r3326291 = r3326289 - r3326290;
        double r3326292 = r3326291 / r3326286;
        double r3326293 = 0.5;
        double r3326294 = 0.16666666666666666;
        double r3326295 = r3326286 * r3326286;
        double r3326296 = 1.0;
        double r3326297 = fma(r3326294, r3326295, r3326296);
        double r3326298 = fma(r3326286, r3326293, r3326297);
        double r3326299 = r3326288 ? r3326292 : r3326298;
        return r3326299;
}

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, \frac{1}{2}, \mathsf{fma}\left(\frac{1}{6}, x \cdot x, 1\right)\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, \frac{1}{2}, \mathsf{fma}\left(\frac{1}{6}, x \cdot x, 1\right)\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))