Average Error: 41.0 → 0.5
Time: 21.3s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.9935258382624282402773019384767394512892:\\ \;\;\;\;\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}\;e^{x} \le 0.9935258382624282402773019384767394512892:\\
\;\;\;\;\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 r52633 = x;
        double r52634 = exp(r52633);
        double r52635 = 1.0;
        double r52636 = r52634 - r52635;
        double r52637 = r52634 / r52636;
        return r52637;
}

double f(double x) {
        double r52638 = x;
        double r52639 = exp(r52638);
        double r52640 = 0.9935258382624282;
        bool r52641 = r52639 <= r52640;
        double r52642 = 3.0;
        double r52643 = pow(r52639, r52642);
        double r52644 = 1.0;
        double r52645 = pow(r52644, r52642);
        double r52646 = r52643 - r52645;
        double r52647 = r52639 + r52644;
        double r52648 = r52638 + r52638;
        double r52649 = exp(r52648);
        double r52650 = fma(r52644, r52647, r52649);
        double r52651 = r52646 / r52650;
        double r52652 = r52639 / r52651;
        double r52653 = 0.08333333333333333;
        double r52654 = 1.0;
        double r52655 = r52654 / r52638;
        double r52656 = fma(r52653, r52638, r52655);
        double r52657 = 0.5;
        double r52658 = r52656 + r52657;
        double r52659 = r52641 ? r52652 : r52658;
        return r52659;
}

Error

Bits error versus x

Target

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

Derivation

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

    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.9935258382624282 < (exp x)

    1. Initial program 61.9

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

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

      \[\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.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{x} \le 0.9935258382624282402773019384767394512892:\\ \;\;\;\;\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 2019303 +o rules:numerics
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

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

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