Average Error: 39.6 → 0.3
Time: 15.6s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.248950464724178875501603425135499492171 \cdot 10^{-5}:\\ \;\;\;\;\frac{\frac{\frac{e^{\mathsf{fma}\left(2, 3 \cdot x, 3 \cdot x\right)} - \left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(1 \cdot 1\right) \cdot 1\right)\right)}{\mathsf{fma}\left(\left(1 \cdot 1\right) \cdot 1, \left(1 \cdot 1\right) \cdot 1, \left(\left(1 \cdot 1\right) \cdot 1 + e^{3 \cdot x}\right) \cdot e^{3 \cdot x}\right)}}{\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 -9.248950464724178875501603425135499492171 \cdot 10^{-5}:\\
\;\;\;\;\frac{\frac{\frac{e^{\mathsf{fma}\left(2, 3 \cdot x, 3 \cdot x\right)} - \left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(1 \cdot 1\right) \cdot 1\right)\right)}{\mathsf{fma}\left(\left(1 \cdot 1\right) \cdot 1, \left(1 \cdot 1\right) \cdot 1, \left(\left(1 \cdot 1\right) \cdot 1 + e^{3 \cdot x}\right) \cdot e^{3 \cdot x}\right)}}{\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 r3594881 = x;
        double r3594882 = exp(r3594881);
        double r3594883 = 1.0;
        double r3594884 = r3594882 - r3594883;
        double r3594885 = r3594884 / r3594881;
        return r3594885;
}

double f(double x) {
        double r3594886 = x;
        double r3594887 = -9.248950464724179e-05;
        bool r3594888 = r3594886 <= r3594887;
        double r3594889 = 2.0;
        double r3594890 = 3.0;
        double r3594891 = r3594890 * r3594886;
        double r3594892 = fma(r3594889, r3594891, r3594891);
        double r3594893 = exp(r3594892);
        double r3594894 = 1.0;
        double r3594895 = r3594894 * r3594894;
        double r3594896 = r3594895 * r3594894;
        double r3594897 = r3594896 * r3594896;
        double r3594898 = r3594896 * r3594897;
        double r3594899 = r3594893 - r3594898;
        double r3594900 = exp(r3594891);
        double r3594901 = r3594896 + r3594900;
        double r3594902 = r3594901 * r3594900;
        double r3594903 = fma(r3594896, r3594896, r3594902);
        double r3594904 = r3594899 / r3594903;
        double r3594905 = exp(r3594886);
        double r3594906 = r3594905 + r3594894;
        double r3594907 = r3594906 * r3594894;
        double r3594908 = fma(r3594905, r3594905, r3594907);
        double r3594909 = r3594904 / r3594908;
        double r3594910 = r3594909 / r3594886;
        double r3594911 = 0.16666666666666666;
        double r3594912 = 0.5;
        double r3594913 = fma(r3594911, r3594886, r3594912);
        double r3594914 = 1.0;
        double r3594915 = fma(r3594886, r3594913, r3594914);
        double r3594916 = r3594888 ? r3594910 : r3594915;
        return r3594916;
}

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 < -9.248950464724179e-05

    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(x, 2, x\right)} - 1 \cdot \left(1 \cdot 1\right)}}{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(x, 2, x\right)} - 1 \cdot \left(1 \cdot 1\right)}{\color{blue}{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(e^{x} + 1\right)\right)}}}{x}\]
    6. Using strategy rm
    7. Applied flip3--0.1

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

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

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

    if -9.248950464724179e-05 < 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, \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 -9.248950464724178875501603425135499492171 \cdot 10^{-5}:\\ \;\;\;\;\frac{\frac{\frac{e^{\mathsf{fma}\left(2, 3 \cdot x, 3 \cdot x\right)} - \left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(1 \cdot 1\right) \cdot 1\right)\right)}{\mathsf{fma}\left(\left(1 \cdot 1\right) \cdot 1, \left(1 \cdot 1\right) \cdot 1, \left(\left(1 \cdot 1\right) \cdot 1 + e^{3 \cdot x}\right) \cdot e^{3 \cdot x}\right)}}{\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 2019169 +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))