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

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

\end{array}
double f(double x) {
        double r4686816 = x;
        double r4686817 = exp(r4686816);
        double r4686818 = 1.0;
        double r4686819 = r4686817 - r4686818;
        double r4686820 = r4686817 / r4686819;
        return r4686820;
}

double f(double x) {
        double r4686821 = x;
        double r4686822 = -0.001088340742756658;
        bool r4686823 = r4686821 <= r4686822;
        double r4686824 = exp(r4686821);
        double r4686825 = 2.0;
        double r4686826 = fma(r4686825, r4686821, r4686821);
        double r4686827 = exp(r4686826);
        double r4686828 = 1.0;
        double r4686829 = r4686828 * r4686828;
        double r4686830 = r4686828 * r4686829;
        double r4686831 = r4686827 - r4686830;
        double r4686832 = cbrt(r4686831);
        double r4686833 = r4686832 * r4686832;
        double r4686834 = r4686832 * r4686833;
        double r4686835 = r4686824 + r4686828;
        double r4686836 = r4686824 * r4686824;
        double r4686837 = fma(r4686828, r4686835, r4686836);
        double r4686838 = r4686834 / r4686837;
        double r4686839 = r4686824 / r4686838;
        double r4686840 = 0.08333333333333333;
        double r4686841 = 0.5;
        double r4686842 = 1.0;
        double r4686843 = r4686842 / r4686821;
        double r4686844 = r4686841 + r4686843;
        double r4686845 = fma(r4686840, r4686821, r4686844);
        double r4686846 = r4686823 ? r4686839 : r4686845;
        return r4686846;
}

Error

Bits error versus x

Target

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

Derivation

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

    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)}}}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt0.0

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

    if -0.001088340742756658 < 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}{x + \left(\frac{1}{6} \cdot {x}^{3} + \frac{1}{2} \cdot {x}^{2}\right)}}\]
    3. Simplified1.1

      \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{fma}\left(x \cdot \left(x \cdot x\right), \frac{1}{6}, \mathsf{fma}\left(x \cdot x, \frac{1}{2}, x\right)\right)}}\]
    4. Taylor expanded around 0 0.9

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

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

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

Reproduce

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

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

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