Average Error: 41.4 → 0.9
Time: 3.1s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.0:\\ \;\;\;\;\frac{1}{1 - \frac{1}{e^{x}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} + \left(\frac{1}{12} \cdot x + \frac{1}{x}\right)\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \le 0.0:\\
\;\;\;\;\frac{1}{1 - \frac{1}{e^{x}}}\\

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

\end{array}
double f(double x) {
        double r102081 = x;
        double r102082 = exp(r102081);
        double r102083 = 1.0;
        double r102084 = r102082 - r102083;
        double r102085 = r102082 / r102084;
        return r102085;
}

double f(double x) {
        double r102086 = x;
        double r102087 = exp(r102086);
        double r102088 = 0.0;
        bool r102089 = r102087 <= r102088;
        double r102090 = 1.0;
        double r102091 = 1.0;
        double r102092 = r102091 / r102087;
        double r102093 = r102090 - r102092;
        double r102094 = r102090 / r102093;
        double r102095 = 0.5;
        double r102096 = 0.08333333333333333;
        double r102097 = r102096 * r102086;
        double r102098 = r102090 / r102086;
        double r102099 = r102097 + r102098;
        double r102100 = r102095 + r102099;
        double r102101 = r102089 ? r102094 : r102100;
        return r102101;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    1. Initial program 0

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

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

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

    if 0.0 < (exp x)

    1. Initial program 61.3

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

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

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

Reproduce

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

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

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