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

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

\end{array}
double f(double x) {
        double r44565 = x;
        double r44566 = exp(r44565);
        double r44567 = 1.0;
        double r44568 = r44566 - r44567;
        double r44569 = r44568 / r44565;
        return r44569;
}

double f(double x) {
        double r44570 = x;
        double r44571 = -0.00012380748142098064;
        bool r44572 = r44570 <= r44571;
        double r44573 = exp(r44570);
        double r44574 = 1.0;
        double r44575 = r44574 / r44570;
        double r44576 = r44573 * r44575;
        double r44577 = 1.0;
        double r44578 = r44577 / r44570;
        double r44579 = r44576 - r44578;
        double r44580 = 0.16666666666666666;
        double r44581 = 0.5;
        double r44582 = fma(r44570, r44580, r44581);
        double r44583 = fma(r44570, r44582, r44574);
        double r44584 = r44572 ? r44579 : r44583;
        return r44584;
}

Error

Bits error versus x

Target

Original39.8
Target40.3
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.00012380748142098064

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{\frac{e^{x}}{x} - \frac{1}{x}}\]
    4. Using strategy rm
    5. Applied div-inv0.1

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

    if -0.00012380748142098064 < 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. Taylor expanded around 0 0.4

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

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

Reproduce

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