Average Error: 41.0 → 0.6
Time: 2.8s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.33936867890953548:\\ \;\;\;\;\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.33936867890953548:\\
\;\;\;\;\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 r91345 = x;
        double r91346 = exp(r91345);
        double r91347 = 1.0;
        double r91348 = r91346 - r91347;
        double r91349 = r91346 / r91348;
        return r91349;
}

double f(double x) {
        double r91350 = x;
        double r91351 = exp(r91350);
        double r91352 = 0.3393686789095355;
        bool r91353 = r91351 <= r91352;
        double r91354 = 1.0;
        double r91355 = 1.0;
        double r91356 = r91355 / r91351;
        double r91357 = r91354 - r91356;
        double r91358 = r91354 / r91357;
        double r91359 = 0.5;
        double r91360 = 0.08333333333333333;
        double r91361 = r91360 * r91350;
        double r91362 = r91354 / r91350;
        double r91363 = r91361 + r91362;
        double r91364 = r91359 + r91363;
        double r91365 = r91353 ? r91358 : r91364;
        return r91365;
}

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.3393686789095355

    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.3393686789095355 < (exp x)

    1. Initial program 61.8

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

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

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

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