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

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

\end{array}
double f(double x) {
        double r5075202 = x;
        double r5075203 = exp(r5075202);
        double r5075204 = 1.0;
        double r5075205 = r5075203 - r5075204;
        double r5075206 = r5075203 / r5075205;
        return r5075206;
}

double f(double x) {
        double r5075207 = x;
        double r5075208 = -0.0005386962406274384;
        bool r5075209 = r5075207 <= r5075208;
        double r5075210 = exp(r5075207);
        double r5075211 = expm1(r5075207);
        double r5075212 = r5075210 / r5075211;
        double r5075213 = r5075212 * r5075212;
        double r5075214 = r5075212 * r5075213;
        double r5075215 = cbrt(r5075214);
        double r5075216 = 0.08333333333333333;
        double r5075217 = 0.5;
        double r5075218 = 1.0;
        double r5075219 = r5075218 / r5075207;
        double r5075220 = r5075217 + r5075219;
        double r5075221 = fma(r5075207, r5075216, r5075220);
        double r5075222 = r5075209 ? r5075215 : r5075221;
        return r5075222;
}

Error

Bits error versus x

Target

Original40.2
Target39.8
Herbie0.6
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 0.0

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

      \[\leadsto \frac{e^{x}}{\color{blue}{\sqrt[3]{\left(\left(e^{x} - 1\right) \cdot \left(e^{x} - 1\right)\right) \cdot \left(e^{x} - 1\right)}}}\]
    4. Applied add-cbrt-cube0.1

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(e^{x} \cdot e^{x}\right) \cdot e^{x}}}}{\sqrt[3]{\left(\left(e^{x} - 1\right) \cdot \left(e^{x} - 1\right)\right) \cdot \left(e^{x} - 1\right)}}\]
    5. Applied cbrt-undiv0.1

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

      \[\leadsto \sqrt[3]{\color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)} \cdot \left(\frac{e^{x}}{\mathsf{expm1}\left(x\right)} \cdot \frac{e^{x}}{\mathsf{expm1}\left(x\right)}\right)}}\]

    if -0.0005386962406274384 < x

    1. Initial program 60.2

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{1}{12}, \left(\frac{1}{2} + \frac{1}{x}\right)\right)}\]
    4. Taylor expanded around inf 0.8

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

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

Reproduce

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

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

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