Average Error: 41.6 → 0.6
Time: 3.8s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0016580727144551504:\\ \;\;\;\;\frac{e^{x}}{\frac{{\left(e^{x}\right)}^{3} - {1}^{3}}{\mathsf{fma}\left(1, e^{x} + 1, e^{x + x}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{x}\right) + \frac{1}{2}\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;x \le -0.0016580727144551504:\\
\;\;\;\;\frac{e^{x}}{\frac{{\left(e^{x}\right)}^{3} - {1}^{3}}{\mathsf{fma}\left(1, e^{x} + 1, e^{x + x}\right)}}\\

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

\end{array}
double f(double x) {
        double r66714 = x;
        double r66715 = exp(r66714);
        double r66716 = 1.0;
        double r66717 = r66715 - r66716;
        double r66718 = r66715 / r66717;
        return r66718;
}

double f(double x) {
        double r66719 = x;
        double r66720 = -0.0016580727144551504;
        bool r66721 = r66719 <= r66720;
        double r66722 = exp(r66719);
        double r66723 = 3.0;
        double r66724 = pow(r66722, r66723);
        double r66725 = 1.0;
        double r66726 = pow(r66725, r66723);
        double r66727 = r66724 - r66726;
        double r66728 = r66722 + r66725;
        double r66729 = r66719 + r66719;
        double r66730 = exp(r66729);
        double r66731 = fma(r66725, r66728, r66730);
        double r66732 = r66727 / r66731;
        double r66733 = r66722 / r66732;
        double r66734 = 0.08333333333333333;
        double r66735 = 1.0;
        double r66736 = r66735 / r66719;
        double r66737 = fma(r66734, r66719, r66736);
        double r66738 = 0.5;
        double r66739 = r66737 + r66738;
        double r66740 = r66721 ? r66733 : r66739;
        return r66740;
}

Error

Bits error versus x

Target

Original41.6
Target41.2
Herbie0.6
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -0.0016580727144551504

    1. Initial program 0.0

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

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

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

    if -0.0016580727144551504 < x

    1. Initial program 62.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0016580727144551504:\\ \;\;\;\;\frac{e^{x}}{\frac{{\left(e^{x}\right)}^{3} - {1}^{3}}{\mathsf{fma}\left(1, e^{x} + 1, e^{x + x}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{x}\right) + \frac{1}{2}\\ \end{array}\]

Reproduce

herbie shell --seed 2020021 +o rules:numerics
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

  :herbie-target
  (/ 1 (- 1 (exp (- x))))

  (/ (exp x) (- (exp x) 1)))