Average Error: 41.0 → 0.6
Time: 13.8s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.8605720028923194986347766644030343741179:\\ \;\;\;\;\frac{1}{e^{3 \cdot x} - \left(1 \cdot 1\right) \cdot 1} \cdot \left(\mathsf{fma}\left(e^{x}, e^{x}, \left(e^{x} + 1\right) \cdot 1\right) \cdot e^{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{1}{12}, \frac{1}{x}\right) + \frac{1}{2}\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \le 0.8605720028923194986347766644030343741179:\\
\;\;\;\;\frac{1}{e^{3 \cdot x} - \left(1 \cdot 1\right) \cdot 1} \cdot \left(\mathsf{fma}\left(e^{x}, e^{x}, \left(e^{x} + 1\right) \cdot 1\right) \cdot e^{x}\right)\\

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

\end{array}
double f(double x) {
        double r3018445 = x;
        double r3018446 = exp(r3018445);
        double r3018447 = 1.0;
        double r3018448 = r3018446 - r3018447;
        double r3018449 = r3018446 / r3018448;
        return r3018449;
}

double f(double x) {
        double r3018450 = x;
        double r3018451 = exp(r3018450);
        double r3018452 = 0.8605720028923195;
        bool r3018453 = r3018451 <= r3018452;
        double r3018454 = 1.0;
        double r3018455 = 3.0;
        double r3018456 = r3018455 * r3018450;
        double r3018457 = exp(r3018456);
        double r3018458 = 1.0;
        double r3018459 = r3018458 * r3018458;
        double r3018460 = r3018459 * r3018458;
        double r3018461 = r3018457 - r3018460;
        double r3018462 = r3018454 / r3018461;
        double r3018463 = r3018451 + r3018458;
        double r3018464 = r3018463 * r3018458;
        double r3018465 = fma(r3018451, r3018451, r3018464);
        double r3018466 = r3018465 * r3018451;
        double r3018467 = r3018462 * r3018466;
        double r3018468 = 0.08333333333333333;
        double r3018469 = r3018454 / r3018450;
        double r3018470 = fma(r3018450, r3018468, r3018469);
        double r3018471 = 0.5;
        double r3018472 = r3018470 + r3018471;
        double r3018473 = r3018453 ? r3018467 : r3018472;
        return r3018473;
}

Error

Bits error versus x

Target

Original41.0
Target40.6
Herbie0.6
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 0.0

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied flip3--0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\frac{{\left(e^{x}\right)}^{3} - {1}^{3}}{e^{x} \cdot e^{x} + \left(1 \cdot 1 + e^{x} \cdot 1\right)}}}\]
    4. Simplified0.0

      \[\leadsto \frac{e^{x}}{\frac{\color{blue}{e^{\mathsf{fma}\left(2, x, x\right)} - \left(1 \cdot 1\right) \cdot 1}}{e^{x} \cdot e^{x} + \left(1 \cdot 1 + e^{x} \cdot 1\right)}}\]
    5. Simplified0.0

      \[\leadsto \frac{e^{x}}{\frac{e^{\mathsf{fma}\left(2, x, x\right)} - \left(1 \cdot 1\right) \cdot 1}{\color{blue}{\mathsf{fma}\left(e^{x}, e^{x}, \left(e^{x} + 1\right) \cdot 1\right)}}}\]
    6. Using strategy rm
    7. Applied div-inv0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\left(e^{\mathsf{fma}\left(2, x, x\right)} - \left(1 \cdot 1\right) \cdot 1\right) \cdot \frac{1}{\mathsf{fma}\left(e^{x}, e^{x}, \left(e^{x} + 1\right) \cdot 1\right)}}}\]
    8. Applied *-un-lft-identity0.0

      \[\leadsto \frac{\color{blue}{1 \cdot e^{x}}}{\left(e^{\mathsf{fma}\left(2, x, x\right)} - \left(1 \cdot 1\right) \cdot 1\right) \cdot \frac{1}{\mathsf{fma}\left(e^{x}, e^{x}, \left(e^{x} + 1\right) \cdot 1\right)}}\]
    9. Applied times-frac0.0

      \[\leadsto \color{blue}{\frac{1}{e^{\mathsf{fma}\left(2, x, x\right)} - \left(1 \cdot 1\right) \cdot 1} \cdot \frac{e^{x}}{\frac{1}{\mathsf{fma}\left(e^{x}, e^{x}, \left(e^{x} + 1\right) \cdot 1\right)}}}\]
    10. Simplified0.0

      \[\leadsto \color{blue}{\frac{1}{e^{x \cdot 3} - 1 \cdot \left(1 \cdot 1\right)}} \cdot \frac{e^{x}}{\frac{1}{\mathsf{fma}\left(e^{x}, e^{x}, \left(e^{x} + 1\right) \cdot 1\right)}}\]
    11. Simplified0.0

      \[\leadsto \frac{1}{e^{x \cdot 3} - 1 \cdot \left(1 \cdot 1\right)} \cdot \color{blue}{\left(e^{x} \cdot \mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(e^{x} + 1\right)\right)\right)}\]

    if 0.8605720028923195 < (exp x)

    1. Initial program 61.7

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

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

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

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

Reproduce

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

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

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