Average Error: 41.2 → 0.7
Time: 2.6s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.992731153252632281:\\ \;\;\;\;\frac{e^{x}}{\log \left(\sqrt{e^{e^{x} - 1}}\right) + \log \left(\sqrt{e^{e^{x} - 1}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} + \left(\frac{1}{12} \cdot x + \frac{1}{x}\right)\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \le 0.992731153252632281:\\
\;\;\;\;\frac{e^{x}}{\log \left(\sqrt{e^{e^{x} - 1}}\right) + \log \left(\sqrt{e^{e^{x} - 1}}\right)}\\

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

\end{array}
double f(double x) {
        double r133912 = x;
        double r133913 = exp(r133912);
        double r133914 = 1.0;
        double r133915 = r133913 - r133914;
        double r133916 = r133913 / r133915;
        return r133916;
}

double f(double x) {
        double r133917 = x;
        double r133918 = exp(r133917);
        double r133919 = 0.9927311532526323;
        bool r133920 = r133918 <= r133919;
        double r133921 = 1.0;
        double r133922 = r133918 - r133921;
        double r133923 = exp(r133922);
        double r133924 = sqrt(r133923);
        double r133925 = log(r133924);
        double r133926 = r133925 + r133925;
        double r133927 = r133918 / r133926;
        double r133928 = 0.5;
        double r133929 = 0.08333333333333333;
        double r133930 = r133929 * r133917;
        double r133931 = 1.0;
        double r133932 = r133931 / r133917;
        double r133933 = r133930 + r133932;
        double r133934 = r133928 + r133933;
        double r133935 = r133920 ? r133927 : r133934;
        return r133935;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    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)}}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt0.0

      \[\leadsto \frac{e^{x}}{\log \color{blue}{\left(\sqrt{e^{e^{x} - 1}} \cdot \sqrt{e^{e^{x} - 1}}\right)}}\]
    9. Applied log-prod0.0

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

    if 0.9927311532526323 < (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. Recombined 2 regimes into one program.
  4. Final simplification0.7

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

Reproduce

herbie shell --seed 2020062 
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

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

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