Average Error: 41.5 → 0.8
Time: 2.7s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.00171217474424922053:\\ \;\;\;\;\frac{1}{\log \left(e^{1 - e^{\log 1 - x}}\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}\;x \le -0.00171217474424922053:\\
\;\;\;\;\frac{1}{\log \left(e^{1 - e^{\log 1 - x}}\right)}\\

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

\end{array}
double f(double x) {
        double r95263 = x;
        double r95264 = exp(r95263);
        double r95265 = 1.0;
        double r95266 = r95264 - r95265;
        double r95267 = r95264 / r95266;
        return r95267;
}

double f(double x) {
        double r95268 = x;
        double r95269 = -0.0017121747442492205;
        bool r95270 = r95268 <= r95269;
        double r95271 = 1.0;
        double r95272 = 1.0;
        double r95273 = log(r95272);
        double r95274 = r95273 - r95268;
        double r95275 = exp(r95274);
        double r95276 = r95271 - r95275;
        double r95277 = exp(r95276);
        double r95278 = log(r95277);
        double r95279 = r95271 / r95278;
        double r95280 = 0.5;
        double r95281 = 0.08333333333333333;
        double r95282 = r95281 * r95268;
        double r95283 = r95271 / r95268;
        double r95284 = r95282 + r95283;
        double r95285 = r95280 + r95284;
        double r95286 = r95270 ? r95279 : r95285;
        return r95286;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -0.0017121747442492205

    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}}}}\]
    5. Using strategy rm
    6. Applied add-exp-log0.0

      \[\leadsto \frac{1}{1 - \frac{\color{blue}{e^{\log 1}}}{e^{x}}}\]
    7. Applied div-exp0.0

      \[\leadsto \frac{1}{1 - \color{blue}{e^{\log 1 - x}}}\]
    8. Using strategy rm
    9. Applied add-log-exp0.7

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

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

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

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

    if -0.0017121747442492205 < x

    1. Initial program 61.9

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

      \[\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.8

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

Reproduce

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

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

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