Average Error: 41.5 → 0.7
Time: 12.2s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.0:\\ \;\;\;\;\frac{e^{x}}{e^{x + x} - 1 \cdot 1} \cdot \left(e^{x} + 1\right)\\ \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}}{e^{x + x} - 1 \cdot 1} \cdot \left(e^{x} + 1\right)\\

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

\end{array}
double f(double x) {
        double r114707 = x;
        double r114708 = exp(r114707);
        double r114709 = 1.0;
        double r114710 = r114708 - r114709;
        double r114711 = r114708 / r114710;
        return r114711;
}

double f(double x) {
        double r114712 = x;
        double r114713 = exp(r114712);
        double r114714 = 0.0;
        bool r114715 = r114713 <= r114714;
        double r114716 = r114712 + r114712;
        double r114717 = exp(r114716);
        double r114718 = 1.0;
        double r114719 = r114718 * r114718;
        double r114720 = r114717 - r114719;
        double r114721 = r114713 / r114720;
        double r114722 = r114713 + r114718;
        double r114723 = r114721 * r114722;
        double r114724 = 0.5;
        double r114725 = 0.08333333333333333;
        double r114726 = r114725 * r114712;
        double r114727 = 1.0;
        double r114728 = r114727 / r114712;
        double r114729 = r114726 + r114728;
        double r114730 = r114724 + r114729;
        double r114731 = r114715 ? r114723 : r114730;
        return r114731;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original41.5
Target41.2
Herbie0.7
\[\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}}}\]
    4. Applied associate-/r/0

      \[\leadsto \color{blue}{\frac{e^{x}}{e^{x} \cdot e^{x} - 1 \cdot 1} \cdot \left(e^{x} + 1\right)}\]
    5. Simplified0

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

    if 0.0 < (exp x)

    1. Initial program 61.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{x} \le 0.0:\\ \;\;\;\;\frac{e^{x}}{e^{x + x} - 1 \cdot 1} \cdot \left(e^{x} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} + \left(\frac{1}{12} \cdot x + \frac{1}{x}\right)\\ \end{array}\]

Reproduce

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

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

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