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

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

\end{array}
double f(double x) {
        double r2392208 = x;
        double r2392209 = exp(r2392208);
        double r2392210 = 1.0;
        double r2392211 = r2392209 - r2392210;
        double r2392212 = r2392209 / r2392211;
        return r2392212;
}

double f(double x) {
        double r2392213 = x;
        double r2392214 = exp(r2392213);
        double r2392215 = 0.8316784421012647;
        bool r2392216 = r2392214 <= r2392215;
        double r2392217 = 1.0;
        double r2392218 = r2392214 - r2392217;
        double r2392219 = r2392214 / r2392218;
        double r2392220 = 0.08333333333333333;
        double r2392221 = r2392220 * r2392213;
        double r2392222 = 0.5;
        double r2392223 = r2392217 / r2392213;
        double r2392224 = r2392222 + r2392223;
        double r2392225 = r2392221 + r2392224;
        double r2392226 = r2392216 ? r2392219 : r2392225;
        return r2392226;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original40.0
Target39.6
Herbie0.6
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 0.0

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

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

    if 0.8316784421012647 < (exp x)

    1. Initial program 59.9

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

      \[\leadsto \color{blue}{\frac{1}{12} \cdot x + \left(\frac{1}{x} + \frac{1}{2}\right)}\]
    3. Taylor expanded around inf 0.9

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

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

Reproduce

herbie shell --seed 2019144 
(FPCore (x)
  :name "expq2 (section 3.11)"

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

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