Average Error: 41.5 → 0.1
Time: 2.6s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.88704448357346632:\\ \;\;\;\;\frac{e^{x}}{e^{x} - 1}\\ \mathbf{elif}\;e^{x} \le 1.00000012358749735:\\ \;\;\;\;\frac{1}{2} + \left(\frac{1}{12} \cdot x + \frac{1}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 - \frac{1}{e^{x}}}\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \le 0.88704448357346632:\\
\;\;\;\;\frac{e^{x}}{e^{x} - 1}\\

\mathbf{elif}\;e^{x} \le 1.00000012358749735:\\
\;\;\;\;\frac{1}{2} + \left(\frac{1}{12} \cdot x + \frac{1}{x}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{1 - \frac{1}{e^{x}}}\\

\end{array}
double f(double x) {
        double r98691 = x;
        double r98692 = exp(r98691);
        double r98693 = 1.0;
        double r98694 = r98692 - r98693;
        double r98695 = r98692 / r98694;
        return r98695;
}

double f(double x) {
        double r98696 = x;
        double r98697 = exp(r98696);
        double r98698 = 0.8870444835734663;
        bool r98699 = r98697 <= r98698;
        double r98700 = 1.0;
        double r98701 = r98697 - r98700;
        double r98702 = r98697 / r98701;
        double r98703 = 1.0000001235874973;
        bool r98704 = r98697 <= r98703;
        double r98705 = 0.5;
        double r98706 = 0.08333333333333333;
        double r98707 = r98706 * r98696;
        double r98708 = 1.0;
        double r98709 = r98708 / r98696;
        double r98710 = r98707 + r98709;
        double r98711 = r98705 + r98710;
        double r98712 = r98700 / r98697;
        double r98713 = r98708 - r98712;
        double r98714 = r98708 / r98713;
        double r98715 = r98704 ? r98711 : r98714;
        double r98716 = r98699 ? r98702 : r98715;
        return r98716;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    1. Initial program 0.0

      \[\frac{e^{x}}{e^{x} - 1}\]

    if 0.8870444835734663 < (exp x) < 1.0000001235874973

    1. Initial program 62.7

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

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

    if 1.0000001235874973 < (exp x)

    1. Initial program 34.3

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

      \[\leadsto \color{blue}{\frac{1}{\frac{e^{x} - 1}{e^{x}}}}\]
    4. Simplified4.1

      \[\leadsto \frac{1}{\color{blue}{1 - \frac{1}{e^{x}}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{x} \le 0.88704448357346632:\\ \;\;\;\;\frac{e^{x}}{e^{x} - 1}\\ \mathbf{elif}\;e^{x} \le 1.00000012358749735:\\ \;\;\;\;\frac{1}{2} + \left(\frac{1}{12} \cdot x + \frac{1}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 - \frac{1}{e^{x}}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020059 
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

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

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