Average Error: 41.3 → 0.7
Time: 17.4s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.9920261382877882949671288770332466810942:\\ \;\;\;\;\frac{e^{x}}{\log \left(e^{e^{x} - 1}\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.9920261382877882949671288770332466810942:\\
\;\;\;\;\frac{e^{x}}{\log \left(e^{e^{x} - 1}\right)}\\

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

\end{array}
double f(double x) {
        double r36940 = x;
        double r36941 = exp(r36940);
        double r36942 = 1.0;
        double r36943 = r36941 - r36942;
        double r36944 = r36941 / r36943;
        return r36944;
}

double f(double x) {
        double r36945 = x;
        double r36946 = exp(r36945);
        double r36947 = 0.9920261382877883;
        bool r36948 = r36946 <= r36947;
        double r36949 = 1.0;
        double r36950 = r36946 - r36949;
        double r36951 = exp(r36950);
        double r36952 = log(r36951);
        double r36953 = r36946 / r36952;
        double r36954 = 0.08333333333333333;
        double r36955 = 1.0;
        double r36956 = r36955 / r36945;
        double r36957 = fma(r36954, r36945, r36956);
        double r36958 = 0.5;
        double r36959 = r36957 + r36958;
        double r36960 = r36948 ? r36953 : r36959;
        return r36960;
}

Error

Bits error versus x

Target

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

Derivation

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

    1. Initial program 0.0

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied add-log-exp0.0

      \[\leadsto \frac{e^{x}}{e^{x} - \color{blue}{\log \left(e^{1}\right)}}\]
    4. Applied add-log-exp0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\log \left(e^{e^{x}}\right)} - \log \left(e^{1}\right)}\]
    5. Applied diff-log0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\log \left(\frac{e^{e^{x}}}{e^{1}}\right)}}\]
    6. Simplified0.0

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

    if 0.9920261382877883 < (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.7

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

Reproduce

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

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

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