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

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

\end{array}
double f(double x) {
        double r3545373 = x;
        double r3545374 = exp(r3545373);
        double r3545375 = 1.0;
        double r3545376 = r3545374 - r3545375;
        double r3545377 = r3545374 / r3545376;
        return r3545377;
}

double f(double x) {
        double r3545378 = x;
        double r3545379 = exp(r3545378);
        double r3545380 = 0.0;
        bool r3545381 = r3545379 <= r3545380;
        double r3545382 = 1.0;
        double r3545383 = r3545379 - r3545382;
        double r3545384 = exp(r3545383);
        double r3545385 = log(r3545384);
        double r3545386 = r3545379 / r3545385;
        double r3545387 = 1.0;
        double r3545388 = r3545387 / r3545378;
        double r3545389 = 0.08333333333333333;
        double r3545390 = r3545389 * r3545378;
        double r3545391 = r3545388 + r3545390;
        double r3545392 = 0.5;
        double r3545393 = r3545391 + r3545392;
        double r3545394 = r3545381 ? r3545386 : r3545393;
        return r3545394;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original41.0
Target40.6
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 add-log-exp0

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

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

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

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

    if 0.0 < (exp x)

    1. Initial program 61.4

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{1}{12}, \frac{1}{x}\right) + \frac{1}{2}}\]
    4. Using strategy rm
    5. Applied fma-udef1.3

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

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

Reproduce

herbie shell --seed 2019169 +o rules:numerics
(FPCore (x)
  :name "expq2 (section 3.11)"

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

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