Average Error: 41.0 → 0.6
Time: 11.2s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.957041714000110066:\\ \;\;\;\;\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.957041714000110066:\\
\;\;\;\;\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 r65924 = x;
        double r65925 = exp(r65924);
        double r65926 = 1.0;
        double r65927 = r65925 - r65926;
        double r65928 = r65925 / r65927;
        return r65928;
}

double f(double x) {
        double r65929 = x;
        double r65930 = exp(r65929);
        double r65931 = 0.9570417140001101;
        bool r65932 = r65930 <= r65931;
        double r65933 = 1.0;
        double r65934 = 1.0;
        double r65935 = r65934 / r65930;
        double r65936 = r65933 - r65935;
        double r65937 = r65933 / r65936;
        double r65938 = 0.5;
        double r65939 = 0.08333333333333333;
        double r65940 = r65939 * r65929;
        double r65941 = r65933 / r65929;
        double r65942 = r65940 + r65941;
        double r65943 = r65938 + r65942;
        double r65944 = r65932 ? r65937 : r65943;
        return r65944;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    1. Initial program 0.0

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

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

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

    if 0.9570417140001101 < (exp x)

    1. Initial program 61.8

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

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

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

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

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