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

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

\end{array}
double f(double x) {
        double r73808 = x;
        double r73809 = exp(r73808);
        double r73810 = 1.0;
        double r73811 = r73809 - r73810;
        double r73812 = r73809 / r73811;
        return r73812;
}

double f(double x) {
        double r73813 = x;
        double r73814 = exp(r73813);
        double r73815 = 0.013991682066964498;
        bool r73816 = r73814 <= r73815;
        double r73817 = 3.0;
        double r73818 = pow(r73814, r73817);
        double r73819 = 1.0;
        double r73820 = pow(r73819, r73817);
        double r73821 = r73818 - r73820;
        double r73822 = r73814 / r73821;
        double r73823 = r73814 * r73814;
        double r73824 = r73819 * r73819;
        double r73825 = r73814 * r73819;
        double r73826 = r73824 + r73825;
        double r73827 = r73823 + r73826;
        double r73828 = r73822 * r73827;
        double r73829 = 0.08333333333333333;
        double r73830 = 1.0;
        double r73831 = r73830 / r73813;
        double r73832 = fma(r73829, r73813, r73831);
        double r73833 = 0.5;
        double r73834 = r73832 + r73833;
        double r73835 = r73816 ? r73828 : r73834;
        return r73835;
}

Error

Bits error versus x

Target

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

Derivation

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

    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. Applied associate-/r/0.0

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

    if 0.013991682066964498 < (exp x)

    1. Initial program 62.0

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

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

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

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

Reproduce

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

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

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