Average Error: 39.6 → 0.3
Time: 17.1s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.976097856766479928837532131780108102248 \cdot 10^{-4}:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{e^{x}}, \frac{\sqrt{e^{x}}}{x}, -\frac{1}{x}\right)\\ \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.976097856766479928837532131780108102248 \cdot 10^{-4}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{e^{x}}, \frac{\sqrt{e^{x}}}{x}, -\frac{1}{x}\right)\\

\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 r3135028 = x;
        double r3135029 = exp(r3135028);
        double r3135030 = 1.0;
        double r3135031 = r3135029 - r3135030;
        double r3135032 = r3135031 / r3135028;
        return r3135032;
}

double f(double x) {
        double r3135033 = x;
        double r3135034 = -0.000197609785676648;
        bool r3135035 = r3135033 <= r3135034;
        double r3135036 = exp(r3135033);
        double r3135037 = sqrt(r3135036);
        double r3135038 = r3135037 / r3135033;
        double r3135039 = 1.0;
        double r3135040 = r3135039 / r3135033;
        double r3135041 = -r3135040;
        double r3135042 = fma(r3135037, r3135038, r3135041);
        double r3135043 = 0.16666666666666666;
        double r3135044 = 0.5;
        double r3135045 = fma(r3135043, r3135033, r3135044);
        double r3135046 = 1.0;
        double r3135047 = fma(r3135033, r3135045, r3135046);
        double r3135048 = r3135035 ? r3135042 : r3135047;
        return r3135048;
}

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

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\frac{e^{x}}{x} - \frac{1}{x}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{1 \cdot x}} - \frac{1}{x}\]
    6. Applied add-sqr-sqrt0.0

      \[\leadsto \frac{\color{blue}{\sqrt{e^{x}} \cdot \sqrt{e^{x}}}}{1 \cdot x} - \frac{1}{x}\]
    7. Applied times-frac0.0

      \[\leadsto \color{blue}{\frac{\sqrt{e^{x}}}{1} \cdot \frac{\sqrt{e^{x}}}{x}} - \frac{1}{x}\]
    8. Applied fma-neg0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sqrt{e^{x}}}{1}, \frac{\sqrt{e^{x}}}{x}, -\frac{1}{x}\right)}\]

    if -0.000197609785676648 < x

    1. Initial program 60.0

      \[\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.976097856766479928837532131780108102248 \cdot 10^{-4}:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{e^{x}}, \frac{\sqrt{e^{x}}}{x}, -\frac{1}{x}\right)\\ \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 2019170 +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))