Average Error: 41.4 → 0.7
Time: 2.5s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.00315224065076235996:\\ \;\;\;\;\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.00315224065076235996:\\
\;\;\;\;\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 r97193 = x;
        double r97194 = exp(r97193);
        double r97195 = 1.0;
        double r97196 = r97194 - r97195;
        double r97197 = r97194 / r97196;
        return r97197;
}

double f(double x) {
        double r97198 = x;
        double r97199 = exp(r97198);
        double r97200 = 0.00315224065076236;
        bool r97201 = r97199 <= r97200;
        double r97202 = 1.0;
        double r97203 = r97199 - r97202;
        double r97204 = exp(r97203);
        double r97205 = log(r97204);
        double r97206 = r97199 / r97205;
        double r97207 = 0.5;
        double r97208 = 0.08333333333333333;
        double r97209 = r97208 * r97198;
        double r97210 = 1.0;
        double r97211 = r97210 / r97198;
        double r97212 = r97209 + r97211;
        double r97213 = r97207 + r97212;
        double r97214 = r97201 ? r97206 : r97213;
        return r97214;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original41.4
Target41.0
Herbie0.7
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

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

    1. Initial program 61.7

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

      \[\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.00315224065076235996:\\ \;\;\;\;\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 2020047 
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

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

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