Average Error: 41.5 → 0.8
Time: 3.6s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.0:\\ \;\;\;\;\sqrt{e^{x}} \cdot \frac{\sqrt{e^{x}}}{e^{x} - 1}\\ \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.0:\\
\;\;\;\;\sqrt{e^{x}} \cdot \frac{\sqrt{e^{x}}}{e^{x} - 1}\\

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

\end{array}
double f(double x) {
        double r94286 = x;
        double r94287 = exp(r94286);
        double r94288 = 1.0;
        double r94289 = r94287 - r94288;
        double r94290 = r94287 / r94289;
        return r94290;
}

double f(double x) {
        double r94291 = x;
        double r94292 = exp(r94291);
        double r94293 = 0.0;
        bool r94294 = r94292 <= r94293;
        double r94295 = sqrt(r94292);
        double r94296 = 1.0;
        double r94297 = r94292 - r94296;
        double r94298 = r94295 / r94297;
        double r94299 = r94295 * r94298;
        double r94300 = 0.08333333333333333;
        double r94301 = 1.0;
        double r94302 = r94301 / r94291;
        double r94303 = fma(r94300, r94291, r94302);
        double r94304 = 0.5;
        double r94305 = r94303 + r94304;
        double r94306 = r94294 ? r94299 : r94305;
        return r94306;
}

Error

Bits error versus x

Target

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

Derivation

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

    1. Initial program 0

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity0

      \[\leadsto \frac{e^{x}}{\color{blue}{1 \cdot \left(e^{x} - 1\right)}}\]
    4. Applied add-sqr-sqrt0

      \[\leadsto \frac{\color{blue}{\sqrt{e^{x}} \cdot \sqrt{e^{x}}}}{1 \cdot \left(e^{x} - 1\right)}\]
    5. Applied times-frac0

      \[\leadsto \color{blue}{\frac{\sqrt{e^{x}}}{1} \cdot \frac{\sqrt{e^{x}}}{e^{x} - 1}}\]
    6. Simplified0

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

    if 0.0 < (exp x)

    1. Initial program 61.5

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

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

      \[\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.8

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

Reproduce

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

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

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