Average Error: 41.0 → 0.8
Time: 2.4s
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 r85456 = x;
        double r85457 = exp(r85456);
        double r85458 = 1.0;
        double r85459 = r85457 - r85458;
        double r85460 = r85457 / r85459;
        return r85460;
}

double f(double x) {
        double r85461 = x;
        double r85462 = exp(r85461);
        double r85463 = 0.0;
        bool r85464 = r85462 <= r85463;
        double r85465 = 1.0;
        double r85466 = 1.0;
        double r85467 = r85466 / r85462;
        double r85468 = r85465 - r85467;
        double r85469 = r85465 / r85468;
        double r85470 = 0.5;
        double r85471 = 0.08333333333333333;
        double r85472 = r85471 * r85461;
        double r85473 = r85465 / r85461;
        double r85474 = r85472 + r85473;
        double r85475 = r85470 + r85474;
        double r85476 = r85464 ? r85469 : r85475;
        return r85476;
}

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

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

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

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

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