Average Error: 41.1 → 0.7
Time: 3.4s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.39816171502576508 \cdot 10^{-4}:\\ \;\;\;\;\frac{\sqrt[3]{e^{x}} \cdot \sqrt[3]{e^{x}}}{\frac{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{\sqrt[3]{e^{x} + 1} \cdot \sqrt[3]{e^{x} + 1}}} \cdot \frac{\sqrt[3]{e^{x}}}{\frac{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{\sqrt[3]{e^{x} + 1}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{x}}{\mathsf{fma}\left(\frac{1}{2}, {x}^{2}, \mathsf{fma}\left(\frac{1}{6}, {x}^{3}, x\right)\right)}\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;x \le -1.39816171502576508 \cdot 10^{-4}:\\
\;\;\;\;\frac{\sqrt[3]{e^{x}} \cdot \sqrt[3]{e^{x}}}{\frac{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{\sqrt[3]{e^{x} + 1} \cdot \sqrt[3]{e^{x} + 1}}} \cdot \frac{\sqrt[3]{e^{x}}}{\frac{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{\sqrt[3]{e^{x} + 1}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{e^{x}}{\mathsf{fma}\left(\frac{1}{2}, {x}^{2}, \mathsf{fma}\left(\frac{1}{6}, {x}^{3}, x\right)\right)}\\

\end{array}
double f(double x) {
        double r114662 = x;
        double r114663 = exp(r114662);
        double r114664 = 1.0;
        double r114665 = r114663 - r114664;
        double r114666 = r114663 / r114665;
        return r114666;
}

double f(double x) {
        double r114667 = x;
        double r114668 = -0.0001398161715025765;
        bool r114669 = r114667 <= r114668;
        double r114670 = exp(r114667);
        double r114671 = cbrt(r114670);
        double r114672 = r114671 * r114671;
        double r114673 = 1.0;
        double r114674 = -r114673;
        double r114675 = r114667 + r114667;
        double r114676 = exp(r114675);
        double r114677 = fma(r114674, r114673, r114676);
        double r114678 = cbrt(r114677);
        double r114679 = r114678 * r114678;
        double r114680 = r114670 + r114673;
        double r114681 = cbrt(r114680);
        double r114682 = r114681 * r114681;
        double r114683 = r114679 / r114682;
        double r114684 = r114672 / r114683;
        double r114685 = r114678 / r114681;
        double r114686 = r114671 / r114685;
        double r114687 = r114684 * r114686;
        double r114688 = 0.5;
        double r114689 = 2.0;
        double r114690 = pow(r114667, r114689);
        double r114691 = 0.16666666666666666;
        double r114692 = 3.0;
        double r114693 = pow(r114667, r114692);
        double r114694 = fma(r114691, r114693, r114667);
        double r114695 = fma(r114688, r114690, r114694);
        double r114696 = r114670 / r114695;
        double r114697 = r114669 ? r114687 : r114696;
        return r114697;
}

Error

Bits error versus x

Target

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

Derivation

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

    1. Initial program 0.0

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

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

      \[\leadsto \frac{e^{x}}{\frac{\color{blue}{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{e^{x} + 1}}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt0.0

      \[\leadsto \frac{e^{x}}{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{\color{blue}{\left(\sqrt[3]{e^{x} + 1} \cdot \sqrt[3]{e^{x} + 1}\right) \cdot \sqrt[3]{e^{x} + 1}}}}\]
    7. Applied add-cube-cbrt0.0

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

      \[\leadsto \frac{e^{x}}{\color{blue}{\frac{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{\sqrt[3]{e^{x} + 1} \cdot \sqrt[3]{e^{x} + 1}} \cdot \frac{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{\sqrt[3]{e^{x} + 1}}}}\]
    9. Applied add-cube-cbrt0.1

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

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

    if -0.0001398161715025765 < x

    1. Initial program 62.0

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

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

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

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

Reproduce

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

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

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