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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(e^{\log \left(\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\right) \cdot \frac{2}{3}}, \sqrt[3]{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)}, \frac{1}{x}\right)\\

\end{array}
double f(double x) {
        double r4423271 = x;
        double r4423272 = exp(r4423271);
        double r4423273 = 1.0;
        double r4423274 = r4423272 - r4423273;
        double r4423275 = r4423272 / r4423274;
        return r4423275;
}

double f(double x) {
        double r4423276 = x;
        double r4423277 = exp(r4423276);
        double r4423278 = 0.9967130846117588;
        bool r4423279 = r4423277 <= r4423278;
        double r4423280 = 2.0;
        double r4423281 = fma(r4423280, r4423276, r4423276);
        double r4423282 = exp(r4423281);
        double r4423283 = 1.0;
        double r4423284 = r4423283 * r4423283;
        double r4423285 = r4423283 * r4423284;
        double r4423286 = r4423282 - r4423285;
        double r4423287 = r4423283 + r4423277;
        double r4423288 = r4423277 * r4423277;
        double r4423289 = fma(r4423283, r4423287, r4423288);
        double r4423290 = r4423286 / r4423289;
        double r4423291 = r4423277 / r4423290;
        double r4423292 = 0.08333333333333333;
        double r4423293 = 0.5;
        double r4423294 = fma(r4423292, r4423276, r4423293);
        double r4423295 = log(r4423294);
        double r4423296 = 0.6666666666666666;
        double r4423297 = r4423295 * r4423296;
        double r4423298 = exp(r4423297);
        double r4423299 = cbrt(r4423294);
        double r4423300 = 1.0;
        double r4423301 = r4423300 / r4423276;
        double r4423302 = fma(r4423298, r4423299, r4423301);
        double r4423303 = r4423279 ? r4423291 : r4423302;
        return r4423303;
}

Error

Bits error versus x

Target

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

Derivation

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

    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(1, 1 + e^{x}, e^{x} \cdot e^{x}\right)}}}\]

    if 0.9967130846117588 < (exp x)

    1. Initial program 62.0

      \[\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(\frac{1}{12}, x, \frac{1}{2}\right) + \frac{1}{x}}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt0.9

      \[\leadsto \color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)}} + \frac{1}{x}\]
    6. Applied fma-def0.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)}, \sqrt[3]{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)}, \frac{1}{x}\right)}\]
    7. Using strategy rm
    8. Applied pow1/30.9

      \[\leadsto \mathsf{fma}\left(\sqrt[3]{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)} \cdot \color{blue}{{\left(\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\right)}^{\frac{1}{3}}}, \sqrt[3]{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)}, \frac{1}{x}\right)\]
    9. Applied pow1/30.9

      \[\leadsto \mathsf{fma}\left(\color{blue}{{\left(\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\right)}^{\frac{1}{3}}} \cdot {\left(\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\right)}^{\frac{1}{3}}, \sqrt[3]{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)}, \frac{1}{x}\right)\]
    10. Applied pow-prod-up0.9

      \[\leadsto \mathsf{fma}\left(\color{blue}{{\left(\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\right)}^{\left(\frac{1}{3} + \frac{1}{3}\right)}}, \sqrt[3]{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)}, \frac{1}{x}\right)\]
    11. Simplified0.9

      \[\leadsto \mathsf{fma}\left({\left(\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\right)}^{\color{blue}{\frac{2}{3}}}, \sqrt[3]{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)}, \frac{1}{x}\right)\]
    12. Using strategy rm
    13. Applied add-exp-log0.9

      \[\leadsto \mathsf{fma}\left({\color{blue}{\left(e^{\log \left(\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\right)}\right)}}^{\frac{2}{3}}, \sqrt[3]{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)}, \frac{1}{x}\right)\]
    14. Applied pow-exp0.9

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

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

Reproduce

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

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

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