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

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

\end{array}
double f(double x) {
        double r4506673 = x;
        double r4506674 = exp(r4506673);
        double r4506675 = 1.0;
        double r4506676 = r4506674 - r4506675;
        double r4506677 = r4506674 / r4506676;
        return r4506677;
}

double f(double x) {
        double r4506678 = x;
        double r4506679 = -0.0014245372640456257;
        bool r4506680 = r4506678 <= r4506679;
        double r4506681 = exp(r4506678);
        double r4506682 = 2.0;
        double r4506683 = fma(r4506682, r4506678, r4506678);
        double r4506684 = exp(r4506683);
        double r4506685 = 1.0;
        double r4506686 = r4506685 * r4506685;
        double r4506687 = r4506685 * r4506686;
        double r4506688 = r4506684 - r4506687;
        double r4506689 = r4506681 + r4506685;
        double r4506690 = r4506681 * r4506681;
        double r4506691 = fma(r4506685, r4506689, r4506690);
        double r4506692 = r4506688 / r4506691;
        double r4506693 = r4506692 * r4506692;
        double r4506694 = r4506693 * r4506692;
        double r4506695 = cbrt(r4506694);
        double r4506696 = r4506681 / r4506695;
        double r4506697 = 1.0;
        double r4506698 = r4506697 / r4506678;
        double r4506699 = 0.08333333333333333;
        double r4506700 = 0.5;
        double r4506701 = fma(r4506699, r4506678, r4506700);
        double r4506702 = r4506698 + r4506701;
        double r4506703 = r4506680 ? r4506696 : r4506702;
        return r4506703;
}

Error

Bits error versus x

Target

Original41.8
Target41.6
Herbie0.4
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    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-cbrt-cube0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\sqrt[3]{\left(\frac{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)} \cdot \frac{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)}\right) \cdot \frac{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.0014245372640456257 < x

    1. Initial program 61.9

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right) + \frac{1}{x}}\]
    4. Using strategy rm
    5. Applied +-commutative0.7

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

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

Reproduce

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

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

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