Average Error: 41.3 → 0.8
Time: 5.2s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 1.207074665252874015274792571886515262982 \cdot 10^{-52}:\\ \;\;\;\;\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 1.207074665252874015274792571886515262982 \cdot 10^{-52}:\\
\;\;\;\;\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 r47921 = x;
        double r47922 = exp(r47921);
        double r47923 = 1.0;
        double r47924 = r47922 - r47923;
        double r47925 = r47922 / r47924;
        return r47925;
}

double f(double x) {
        double r47926 = x;
        double r47927 = exp(r47926);
        double r47928 = 1.207074665252874e-52;
        bool r47929 = r47927 <= r47928;
        double r47930 = 1.0;
        double r47931 = 1.0;
        double r47932 = r47931 / r47927;
        double r47933 = r47930 - r47932;
        double r47934 = r47930 / r47933;
        double r47935 = 0.5;
        double r47936 = 0.08333333333333333;
        double r47937 = r47936 * r47926;
        double r47938 = r47930 / r47926;
        double r47939 = r47937 + r47938;
        double r47940 = r47935 + r47939;
        double r47941 = r47929 ? r47934 : r47940;
        return r47941;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original41.3
Target40.9
Herbie0.8
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Split input into 2 regimes
  2. if (exp x) < 1.207074665252874e-52

    1. Initial program 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 1.207074665252874e-52 < (exp x)

    1. Initial program 61.5

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

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

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

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

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