Average Error: 41.2 → 0.7
Time: 15.5s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.9981915251211822548427221590827684849501:\\ \;\;\;\;\frac{e^{x}}{\frac{{\left({\left(e^{x}\right)}^{3}\right)}^{3} - {\left({1}^{3}\right)}^{3}}{\mathsf{fma}\left(1, 1 + e^{x}, e^{x + x}\right) \cdot \mathsf{fma}\left({1}^{3}, {\left(e^{x}\right)}^{3} + {1}^{3}, {\left(e^{x}\right)}^{6}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{x}}{\mathsf{fma}\left({x}^{3}, \frac{1}{6}, \mathsf{fma}\left(x \cdot x, \frac{1}{2}, x\right)\right)}\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \le 0.9981915251211822548427221590827684849501:\\
\;\;\;\;\frac{e^{x}}{\frac{{\left({\left(e^{x}\right)}^{3}\right)}^{3} - {\left({1}^{3}\right)}^{3}}{\mathsf{fma}\left(1, 1 + e^{x}, e^{x + x}\right) \cdot \mathsf{fma}\left({1}^{3}, {\left(e^{x}\right)}^{3} + {1}^{3}, {\left(e^{x}\right)}^{6}\right)}}\\

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

\end{array}
double f(double x) {
        double r64727 = x;
        double r64728 = exp(r64727);
        double r64729 = 1.0;
        double r64730 = r64728 - r64729;
        double r64731 = r64728 / r64730;
        return r64731;
}

double f(double x) {
        double r64732 = x;
        double r64733 = exp(r64732);
        double r64734 = 0.9981915251211823;
        bool r64735 = r64733 <= r64734;
        double r64736 = 3.0;
        double r64737 = pow(r64733, r64736);
        double r64738 = pow(r64737, r64736);
        double r64739 = 1.0;
        double r64740 = pow(r64739, r64736);
        double r64741 = pow(r64740, r64736);
        double r64742 = r64738 - r64741;
        double r64743 = r64739 + r64733;
        double r64744 = r64732 + r64732;
        double r64745 = exp(r64744);
        double r64746 = fma(r64739, r64743, r64745);
        double r64747 = r64737 + r64740;
        double r64748 = 6.0;
        double r64749 = pow(r64733, r64748);
        double r64750 = fma(r64740, r64747, r64749);
        double r64751 = r64746 * r64750;
        double r64752 = r64742 / r64751;
        double r64753 = r64733 / r64752;
        double r64754 = pow(r64732, r64736);
        double r64755 = 0.16666666666666666;
        double r64756 = r64732 * r64732;
        double r64757 = 0.5;
        double r64758 = fma(r64756, r64757, r64732);
        double r64759 = fma(r64754, r64755, r64758);
        double r64760 = r64733 / r64759;
        double r64761 = r64735 ? r64753 : r64760;
        return r64761;
}

Error

Bits error versus x

Target

Original41.2
Target40.9
Herbie0.7
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Split input into 2 regimes
  2. if (exp x) < 0.9981915251211823

    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, 1 + e^{x}, e^{x + x}\right)}}}\]
    5. Using strategy rm
    6. Applied flip3--0.0

      \[\leadsto \frac{e^{x}}{\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)}}}{\mathsf{fma}\left(1, 1 + e^{x}, e^{x + x}\right)}}\]
    7. Applied associate-/l/0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\frac{{\left({\left(e^{x}\right)}^{3}\right)}^{3} - {\left({1}^{3}\right)}^{3}}{\mathsf{fma}\left(1, 1 + e^{x}, e^{x + x}\right) \cdot \left({\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)\right)}}}\]
    8. Simplified0.0

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

    if 0.9981915251211823 < (exp x)

    1. Initial program 61.8

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

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

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

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

Reproduce

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

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

  (/ (exp x) (- (exp x) 1.0)))