Average Error: 39.8 → 0.4
Time: 11.0s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.670496352740291341569534022681864371407 \cdot 10^{-4}:\\ \;\;\;\;\frac{\frac{{\left({\left(e^{x}\right)}^{3}\right)}^{3} - {\left({1}^{3}\right)}^{3}}{\mathsf{fma}\left({1}^{3}, {\left(e^{x}\right)}^{3} + {1}^{3}, {\left(e^{x}\right)}^{6}\right)}}{x \cdot \mathsf{fma}\left(1, e^{x} + 1, e^{x + 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.670496352740291341569534022681864371407 \cdot 10^{-4}:\\
\;\;\;\;\frac{\frac{{\left({\left(e^{x}\right)}^{3}\right)}^{3} - {\left({1}^{3}\right)}^{3}}{\mathsf{fma}\left({1}^{3}, {\left(e^{x}\right)}^{3} + {1}^{3}, {\left(e^{x}\right)}^{6}\right)}}{x \cdot \mathsf{fma}\left(1, e^{x} + 1, e^{x + 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 r60002 = x;
        double r60003 = exp(r60002);
        double r60004 = 1.0;
        double r60005 = r60003 - r60004;
        double r60006 = r60005 / r60002;
        return r60006;
}

double f(double x) {
        double r60007 = x;
        double r60008 = -0.00016704963527402913;
        bool r60009 = r60007 <= r60008;
        double r60010 = exp(r60007);
        double r60011 = 3.0;
        double r60012 = pow(r60010, r60011);
        double r60013 = pow(r60012, r60011);
        double r60014 = 1.0;
        double r60015 = pow(r60014, r60011);
        double r60016 = pow(r60015, r60011);
        double r60017 = r60013 - r60016;
        double r60018 = r60012 + r60015;
        double r60019 = 6.0;
        double r60020 = pow(r60010, r60019);
        double r60021 = fma(r60015, r60018, r60020);
        double r60022 = r60017 / r60021;
        double r60023 = r60010 + r60014;
        double r60024 = r60007 + r60007;
        double r60025 = exp(r60024);
        double r60026 = fma(r60014, r60023, r60025);
        double r60027 = r60007 * r60026;
        double r60028 = r60022 / r60027;
        double r60029 = 0.16666666666666666;
        double r60030 = 0.5;
        double r60031 = fma(r60029, r60007, r60030);
        double r60032 = 1.0;
        double r60033 = fma(r60007, r60031, r60032);
        double r60034 = r60009 ? r60028 : r60033;
        return r60034;
}

Error

Bits error versus x

Target

Original39.8
Target40.2
Herbie0.4
\[\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.00016704963527402913

    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. Applied associate-/l/0.1

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

      \[\leadsto \frac{{\left(e^{x}\right)}^{3} - {1}^{3}}{\color{blue}{x \cdot \mathsf{fma}\left(1, 1 + e^{x}, e^{x + x}\right)}}\]
    6. Using strategy rm
    7. Applied flip3--0.1

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

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

    if -0.00016704963527402913 < 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, \frac{1}{2}, \mathsf{fma}\left(\frac{1}{6}, x \cdot x, 1\right)\right)}\]
    4. Taylor expanded around 0 0.5

      \[\leadsto \color{blue}{\frac{1}{2} \cdot x + \left(\frac{1}{6} \cdot {x}^{2} + 1\right)}\]
    5. 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.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.670496352740291341569534022681864371407 \cdot 10^{-4}:\\ \;\;\;\;\frac{\frac{{\left({\left(e^{x}\right)}^{3}\right)}^{3} - {\left({1}^{3}\right)}^{3}}{\mathsf{fma}\left({1}^{3}, {\left(e^{x}\right)}^{3} + {1}^{3}, {\left(e^{x}\right)}^{6}\right)}}{x \cdot \mathsf{fma}\left(1, e^{x} + 1, e^{x + 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 2019195 +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))