Average Error: 41.5 → 0.6
Time: 10.2s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.0220815666007950252:\\ \;\;\;\;\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.0220815666007950252:\\
\;\;\;\;\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 r65786 = x;
        double r65787 = exp(r65786);
        double r65788 = 1.0;
        double r65789 = r65787 - r65788;
        double r65790 = r65787 / r65789;
        return r65790;
}

double f(double x) {
        double r65791 = x;
        double r65792 = exp(r65791);
        double r65793 = 0.022081566600795025;
        bool r65794 = r65792 <= r65793;
        double r65795 = 1.0;
        double r65796 = 1.0;
        double r65797 = r65796 / r65792;
        double r65798 = r65795 - r65797;
        double r65799 = r65795 / r65798;
        double r65800 = 0.5;
        double r65801 = 0.08333333333333333;
        double r65802 = r65801 * r65791;
        double r65803 = r65795 / r65791;
        double r65804 = r65802 + r65803;
        double r65805 = r65800 + r65804;
        double r65806 = r65794 ? r65799 : r65805;
        return r65806;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original41.5
Target41.1
Herbie0.6
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Split input into 2 regimes
  2. if (exp x) < 0.022081566600795025

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

    1. Initial program 61.8

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

      \[\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.0220815666007950252:\\ \;\;\;\;\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 2019198 
(FPCore (x)
  :name "expq2 (section 3.11)"

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

  (/ (exp x) (- (exp x) 1.0)))