Average Error: 40.9 → 0.6
Time: 3.0s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.002237729744276147157006073840079807268921:\\ \;\;\;\;\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.002237729744276147157006073840079807268921:\\
\;\;\;\;\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 r51979 = x;
        double r51980 = exp(r51979);
        double r51981 = 1.0;
        double r51982 = r51980 - r51981;
        double r51983 = r51980 / r51982;
        return r51983;
}

double f(double x) {
        double r51984 = x;
        double r51985 = -0.002237729744276147;
        bool r51986 = r51984 <= r51985;
        double r51987 = 1.0;
        double r51988 = 1.0;
        double r51989 = log(r51988);
        double r51990 = r51989 - r51984;
        double r51991 = exp(r51990);
        double r51992 = r51987 - r51991;
        double r51993 = r51987 / r51992;
        double r51994 = 0.08333333333333333;
        double r51995 = r51987 / r51984;
        double r51996 = fma(r51994, r51984, r51995);
        double r51997 = 0.5;
        double r51998 = r51996 + r51997;
        double r51999 = r51986 ? r51993 : r51998;
        return r51999;
}

Error

Bits error versus x

Target

Original40.9
Target40.4
Herbie0.6
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    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.002237729744276147 < 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.002237729744276147157006073840079807268921:\\ \;\;\;\;\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 2020002 +o rules:numerics
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

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

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