Average Error: 41.3 → 0.9
Time: 6.3s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.0:\\ \;\;\;\;\frac{1}{1 - \frac{1}{e^{x}}}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{x} + \frac{1}{2}\right) + \frac{x}{12}\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \le 0.0:\\
\;\;\;\;\frac{1}{1 - \frac{1}{e^{x}}}\\

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

\end{array}
double f(double x) {
        double r377964 = x;
        double r377965 = exp(r377964);
        double r377966 = 1.0;
        double r377967 = r377965 - r377966;
        double r377968 = r377965 / r377967;
        return r377968;
}

double f(double x) {
        double r377969 = x;
        double r377970 = exp(r377969);
        double r377971 = 0.0;
        bool r377972 = r377970 <= r377971;
        double r377973 = 1.0;
        double r377974 = 1.0;
        double r377975 = r377974 / r377970;
        double r377976 = r377973 - r377975;
        double r377977 = r377973 / r377976;
        double r377978 = r377973 / r377969;
        double r377979 = 2.0;
        double r377980 = r377973 / r377979;
        double r377981 = r377978 + r377980;
        double r377982 = 12.0;
        double r377983 = r377969 / r377982;
        double r377984 = r377981 + r377983;
        double r377985 = r377972 ? r377977 : r377984;
        return r377985;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original41.3
Target40.8
Herbie0.9
\[\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 clear-num0

      \[\leadsto \color{blue}{\frac{1}{\frac{e^{x} - 1}{e^{x}}}}\]
    4. Simplified0

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

    if 0.0 < (exp x)

    1. Initial program 61.2

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

      \[\leadsto \color{blue}{\frac{1}{2} + \left(\frac{1}{12} \cdot x + \frac{1}{x}\right)}\]
    3. Simplified1.4

      \[\leadsto \color{blue}{\left(\frac{1}{x} + \frac{1}{2}\right) + \frac{x}{12}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

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

Reproduce

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

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

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