Average Error: 41.2 → 0.7
Time: 2.5s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.994377561105835306:\\ \;\;\;\;\frac{e^{x}}{\log \left(e^{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.994377561105835306:\\
\;\;\;\;\frac{e^{x}}{\log \left(e^{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 r105978 = x;
        double r105979 = exp(r105978);
        double r105980 = 1.0;
        double r105981 = r105979 - r105980;
        double r105982 = r105979 / r105981;
        return r105982;
}

double f(double x) {
        double r105983 = x;
        double r105984 = exp(r105983);
        double r105985 = 0.9943775611058353;
        bool r105986 = r105984 <= r105985;
        double r105987 = 1.0;
        double r105988 = r105984 - r105987;
        double r105989 = exp(r105988);
        double r105990 = log(r105989);
        double r105991 = r105984 / r105990;
        double r105992 = 0.5;
        double r105993 = 0.08333333333333333;
        double r105994 = r105993 * r105983;
        double r105995 = 1.0;
        double r105996 = r105995 / r105983;
        double r105997 = r105994 + r105996;
        double r105998 = r105992 + r105997;
        double r105999 = r105986 ? r105991 : r105998;
        return r105999;
}

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.7
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 0.0

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied add-log-exp0.0

      \[\leadsto \frac{e^{x}}{e^{x} - \color{blue}{\log \left(e^{1}\right)}}\]
    4. Applied add-log-exp0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\log \left(e^{e^{x}}\right)} - \log \left(e^{1}\right)}\]
    5. Applied diff-log0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\log \left(\frac{e^{e^{x}}}{e^{1}}\right)}}\]
    6. Simplified0.0

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

    if 0.9943775611058353 < (exp x)

    1. Initial program 61.9

      \[\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.994377561105835306:\\ \;\;\;\;\frac{e^{x}}{\log \left(e^{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 2020036 
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

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

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