Average Error: 39.6 → 0.3
Time: 10.2s
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}, \left(e^{x} + 1\right) \cdot 1\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}, \left(e^{x} + 1\right) \cdot 1\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 r4372958 = x;
        double r4372959 = exp(r4372958);
        double r4372960 = 1.0;
        double r4372961 = r4372959 - r4372960;
        double r4372962 = r4372961 / r4372958;
        return r4372962;
}

double f(double x) {
        double r4372963 = x;
        double r4372964 = -0.00010910993504645059;
        bool r4372965 = r4372963 <= r4372964;
        double r4372966 = 2.0;
        double r4372967 = fma(r4372966, r4372963, r4372963);
        double r4372968 = exp(r4372967);
        double r4372969 = 1.0;
        double r4372970 = r4372969 * r4372969;
        double r4372971 = r4372970 * r4372969;
        double r4372972 = r4372968 - r4372971;
        double r4372973 = exp(r4372963);
        double r4372974 = r4372973 + r4372969;
        double r4372975 = r4372974 * r4372969;
        double r4372976 = fma(r4372973, r4372973, r4372975);
        double r4372977 = r4372972 / r4372976;
        double r4372978 = r4372977 / r4372963;
        double r4372979 = 0.16666666666666666;
        double r4372980 = 0.5;
        double r4372981 = fma(r4372979, r4372963, r4372980);
        double r4372982 = 1.0;
        double r4372983 = fma(r4372963, r4372981, r4372982);
        double r4372984 = r4372965 ? r4372978 : r4372983;
        return r4372984;
}

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(e^{x} + 1\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(x, \frac{1}{2}, \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}, \left(e^{x} + 1\right) \cdot 1\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))