Average Error: 41.2 → 0.7
Time: 2.5s
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 r64928 = x;
        double r64929 = exp(r64928);
        double r64930 = 1.0;
        double r64931 = r64929 - r64930;
        double r64932 = r64929 / r64931;
        return r64932;
}

double f(double x) {
        double r64933 = x;
        double r64934 = exp(r64933);
        double r64935 = 0.9927311532526323;
        bool r64936 = r64934 <= r64935;
        double r64937 = 1.0;
        double r64938 = r64934 - r64937;
        double r64939 = exp(r64938);
        double r64940 = sqrt(r64939);
        double r64941 = log(r64940);
        double r64942 = r64941 + r64941;
        double r64943 = r64934 / r64942;
        double r64944 = 0.5;
        double r64945 = 0.08333333333333333;
        double r64946 = r64945 * r64933;
        double r64947 = 1.0;
        double r64948 = r64947 / r64933;
        double r64949 = r64946 + r64948;
        double r64950 = r64944 + r64949;
        double r64951 = r64936 ? r64943 : r64950;
        return r64951;
}

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)))