Average Error: 41.4 → 0.9
Time: 10.6s
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 r68109 = x;
        double r68110 = exp(r68109);
        double r68111 = 1.0;
        double r68112 = r68110 - r68111;
        double r68113 = r68110 / r68112;
        return r68113;
}

double f(double x) {
        double r68114 = x;
        double r68115 = exp(r68114);
        double r68116 = 0.0;
        bool r68117 = r68115 <= r68116;
        double r68118 = 1.0;
        double r68119 = 1.0;
        double r68120 = r68119 / r68115;
        double r68121 = r68118 - r68120;
        double r68122 = r68118 / r68121;
        double r68123 = 0.5;
        double r68124 = 0.08333333333333333;
        double r68125 = r68124 * r68114;
        double r68126 = r68118 / r68114;
        double r68127 = r68125 + r68126;
        double r68128 = r68123 + r68127;
        double r68129 = r68117 ? r68122 : r68128;
        return r68129;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original41.4
Target40.9
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.4

      \[\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 2019212 
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

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

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