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

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

\end{array}
double f(double x) {
        double r47167 = x;
        double r47168 = exp(r47167);
        double r47169 = 1.0;
        double r47170 = r47168 - r47169;
        double r47171 = r47170 / r47167;
        return r47171;
}

double f(double x) {
        double r47172 = x;
        double r47173 = -0.0001470771277477194;
        bool r47174 = r47172 <= r47173;
        double r47175 = r47172 + r47172;
        double r47176 = exp(r47175);
        double r47177 = r47176 * r47176;
        double r47178 = 1.0;
        double r47179 = r47178 * r47178;
        double r47180 = r47179 * r47179;
        double r47181 = r47177 - r47180;
        double r47182 = 2.0;
        double r47183 = r47182 * r47172;
        double r47184 = exp(r47183);
        double r47185 = fma(r47178, r47178, r47184);
        double r47186 = exp(r47172);
        double r47187 = r47178 + r47186;
        double r47188 = r47185 * r47187;
        double r47189 = r47181 / r47188;
        double r47190 = r47189 / r47172;
        double r47191 = pow(r47172, r47182);
        double r47192 = 0.16666666666666666;
        double r47193 = 0.5;
        double r47194 = fma(r47172, r47192, r47193);
        double r47195 = fma(r47191, r47194, r47172);
        double r47196 = r47195 / r47172;
        double r47197 = r47174 ? r47190 : r47196;
        return r47197;
}

Error

Bits error versus x

Target

Original39.7
Target40.1
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.0001470771277477194

    1. Initial program 0.0

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

      \[\leadsto \frac{\color{blue}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}}{x}\]
    4. Simplified0.0

      \[\leadsto \frac{\frac{\color{blue}{e^{x + x} - 1 \cdot 1}}{e^{x} + 1}}{x}\]
    5. Simplified0.0

      \[\leadsto \frac{\frac{e^{x + x} - 1 \cdot 1}{\color{blue}{1 + e^{x}}}}{x}\]
    6. Using strategy rm
    7. Applied flip--0.0

      \[\leadsto \frac{\frac{\color{blue}{\frac{e^{x + x} \cdot e^{x + x} - \left(1 \cdot 1\right) \cdot \left(1 \cdot 1\right)}{e^{x + x} + 1 \cdot 1}}}{1 + e^{x}}}{x}\]
    8. Applied associate-/l/0.0

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

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

    if -0.0001470771277477194 < x

    1. Initial program 60.1

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

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left(x, \frac{1}{6}, \frac{1}{2}\right), x\right)}}{x}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.470771277477194002771682113106521683221 \cdot 10^{-4}:\\ \;\;\;\;\frac{\frac{e^{x + x} \cdot e^{x + x} - \left(1 \cdot 1\right) \cdot \left(1 \cdot 1\right)}{\mathsf{fma}\left(1, 1, e^{2 \cdot x}\right) \cdot \left(1 + e^{x}\right)}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left(x, \frac{1}{6}, \frac{1}{2}\right), x\right)}{x}\\ \end{array}\]

Reproduce

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