Average Error: 41.2 → 0.8
Time: 3.3s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.0:\\ \;\;\;\;\frac{e^{x}}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}\\ \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{e^{x}}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{2} + \left(\frac{1}{12} \cdot x + \frac{1}{x}\right)\\

\end{array}
double f(double x) {
        double r99512 = x;
        double r99513 = exp(r99512);
        double r99514 = 1.0;
        double r99515 = r99513 - r99514;
        double r99516 = r99513 / r99515;
        return r99516;
}

double f(double x) {
        double r99517 = x;
        double r99518 = exp(r99517);
        double r99519 = 0.0;
        bool r99520 = r99518 <= r99519;
        double r99521 = r99518 * r99518;
        double r99522 = 1.0;
        double r99523 = r99522 * r99522;
        double r99524 = r99521 - r99523;
        double r99525 = r99518 + r99522;
        double r99526 = r99524 / r99525;
        double r99527 = r99518 / r99526;
        double r99528 = 0.5;
        double r99529 = 0.08333333333333333;
        double r99530 = r99529 * r99517;
        double r99531 = 1.0;
        double r99532 = r99531 / r99517;
        double r99533 = r99530 + r99532;
        double r99534 = r99528 + r99533;
        double r99535 = r99520 ? r99527 : r99534;
        return r99535;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original41.2
Target40.8
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 flip--0

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

    if 0.0 < (exp x)

    1. Initial program 61.5

      \[\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{e^{x}}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} + \left(\frac{1}{12} \cdot x + \frac{1}{x}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020089 
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

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

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