Average Error: 39.6 → 0.3
Time: 11.1s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.091099350464505882921800727913819173409 \cdot 10^{-4}:\\ \;\;\;\;\frac{\frac{e^{\mathsf{fma}\left(2, x, x\right)} - \left(1 \cdot 1\right) \cdot 1}{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)}}{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.091099350464505882921800727913819173409 \cdot 10^{-4}:\\
\;\;\;\;\frac{\frac{e^{\mathsf{fma}\left(2, x, x\right)} - \left(1 \cdot 1\right) \cdot 1}{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)}}{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 r5415910 = x;
        double r5415911 = exp(r5415910);
        double r5415912 = 1.0;
        double r5415913 = r5415911 - r5415912;
        double r5415914 = r5415913 / r5415910;
        return r5415914;
}

double f(double x) {
        double r5415915 = x;
        double r5415916 = -0.00010910993504645059;
        bool r5415917 = r5415915 <= r5415916;
        double r5415918 = 2.0;
        double r5415919 = fma(r5415918, r5415915, r5415915);
        double r5415920 = exp(r5415919);
        double r5415921 = 1.0;
        double r5415922 = r5415921 * r5415921;
        double r5415923 = r5415922 * r5415921;
        double r5415924 = r5415920 - r5415923;
        double r5415925 = exp(r5415915);
        double r5415926 = r5415921 + r5415925;
        double r5415927 = r5415921 * r5415926;
        double r5415928 = fma(r5415925, r5415925, r5415927);
        double r5415929 = r5415924 / r5415928;
        double r5415930 = r5415929 / r5415915;
        double r5415931 = 0.16666666666666666;
        double r5415932 = 0.5;
        double r5415933 = fma(r5415931, r5415915, r5415932);
        double r5415934 = 1.0;
        double r5415935 = fma(r5415915, r5415933, r5415934);
        double r5415936 = r5415917 ? r5415930 : r5415935;
        return r5415936;
}

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

    1. Initial program 0.1

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

      \[\leadsto \frac{\color{blue}{\frac{{\left(e^{x}\right)}^{3} - {1}^{3}}{e^{x} \cdot e^{x} + \left(1 \cdot 1 + e^{x} \cdot 1\right)}}}{x}\]
    4. Simplified0.1

      \[\leadsto \frac{\frac{\color{blue}{e^{\mathsf{fma}\left(2, x, x\right)} - \left(1 \cdot 1\right) \cdot 1}}{e^{x} \cdot e^{x} + \left(1 \cdot 1 + e^{x} \cdot 1\right)}}{x}\]
    5. Simplified0.1

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

    if -0.00010910993504645059 < x

    1. Initial program 60.2

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{2}, x, \mathsf{fma}\left(\frac{1}{6}, x \cdot x, 1\right)\right)}\]
    4. Taylor expanded around 0 0.4

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

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