Average Error: 41.1 → 0.9
Time: 4.0s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 1.166841640166349666900712269954744631923 \cdot 10^{-47}:\\ \;\;\;\;\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 1.166841640166349666900712269954744631923 \cdot 10^{-47}:\\
\;\;\;\;\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 r99781 = x;
        double r99782 = exp(r99781);
        double r99783 = 1.0;
        double r99784 = r99782 - r99783;
        double r99785 = r99782 / r99784;
        return r99785;
}

double f(double x) {
        double r99786 = x;
        double r99787 = exp(r99786);
        double r99788 = 1.1668416401663497e-47;
        bool r99789 = r99787 <= r99788;
        double r99790 = 1.0;
        double r99791 = 1.0;
        double r99792 = r99791 / r99787;
        double r99793 = r99790 - r99792;
        double r99794 = r99790 / r99793;
        double r99795 = 0.5;
        double r99796 = 0.08333333333333333;
        double r99797 = r99796 * r99786;
        double r99798 = r99790 / r99786;
        double r99799 = r99797 + r99798;
        double r99800 = r99795 + r99799;
        double r99801 = r99789 ? r99794 : r99800;
        return r99801;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original41.1
Target40.6
Herbie0.9
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Split input into 2 regimes
  2. if (exp x) < 1.1668416401663497e-47

    1. Initial program 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 1.1668416401663497e-47 < (exp x)

    1. Initial program 61.5

      \[\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 1.166841640166349666900712269954744631923 \cdot 10^{-47}:\\ \;\;\;\;\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 2019322 
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

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

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