Average Error: 41.8 → 0.6
Time: 2.9s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0021727830323339213:\\ \;\;\;\;\frac{1}{1 - e^{\log 1 - x}}\\ \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}\;x \le -0.0021727830323339213:\\
\;\;\;\;\frac{1}{1 - e^{\log 1 - x}}\\

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

\end{array}
double f(double x) {
        double r85179 = x;
        double r85180 = exp(r85179);
        double r85181 = 1.0;
        double r85182 = r85180 - r85181;
        double r85183 = r85180 / r85182;
        return r85183;
}

double f(double x) {
        double r85184 = x;
        double r85185 = -0.0021727830323339213;
        bool r85186 = r85184 <= r85185;
        double r85187 = 1.0;
        double r85188 = 1.0;
        double r85189 = log(r85188);
        double r85190 = r85189 - r85184;
        double r85191 = exp(r85190);
        double r85192 = r85187 - r85191;
        double r85193 = r85187 / r85192;
        double r85194 = 0.08333333333333333;
        double r85195 = r85187 / r85184;
        double r85196 = fma(r85194, r85184, r85195);
        double r85197 = 0.5;
        double r85198 = r85196 + r85197;
        double r85199 = r85186 ? r85193 : r85198;
        return r85199;
}

Error

Bits error versus x

Target

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

Derivation

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

    1. Initial program 0.0

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied clear-num0.0

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

      \[\leadsto \frac{1}{\color{blue}{1 - \frac{1}{e^{x}}}}\]
    5. Using strategy rm
    6. Applied add-exp-log0.0

      \[\leadsto \frac{1}{1 - \frac{\color{blue}{e^{\log 1}}}{e^{x}}}\]
    7. Applied div-exp0.0

      \[\leadsto \frac{1}{1 - \color{blue}{e^{\log 1 - x}}}\]

    if -0.0021727830323339213 < x

    1. Initial program 62.1

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

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

      \[\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}\;x \le -0.0021727830323339213:\\ \;\;\;\;\frac{1}{1 - e^{\log 1 - x}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{x}\right) + \frac{1}{2}\\ \end{array}\]

Reproduce

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

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

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