Average Error: 40.5 → 0.7
Time: 3.0s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.0184360243772397382:\\ \;\;\;\;\frac{1}{1 - e^{\log 1 - x}}\\ \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.0184360243772397382:\\
\;\;\;\;\frac{1}{1 - e^{\log 1 - x}}\\

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

\end{array}
double f(double x) {
        double r87935 = x;
        double r87936 = exp(r87935);
        double r87937 = 1.0;
        double r87938 = r87936 - r87937;
        double r87939 = r87936 / r87938;
        return r87939;
}

double f(double x) {
        double r87940 = x;
        double r87941 = exp(r87940);
        double r87942 = 0.018436024377239738;
        bool r87943 = r87941 <= r87942;
        double r87944 = 1.0;
        double r87945 = 1.0;
        double r87946 = log(r87945);
        double r87947 = r87946 - r87940;
        double r87948 = exp(r87947);
        double r87949 = r87944 - r87948;
        double r87950 = r87944 / r87949;
        double r87951 = 0.5;
        double r87952 = 0.08333333333333333;
        double r87953 = r87952 * r87940;
        double r87954 = r87944 / r87940;
        double r87955 = r87953 + r87954;
        double r87956 = r87951 + r87955;
        double r87957 = r87943 ? r87950 : r87956;
        return r87957;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original40.5
Target40.1
Herbie0.7
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    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.018436024377239738 < (exp x)

    1. Initial program 61.4

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

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

Reproduce

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

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

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