Average Error: 41.2 → 0.7
Time: 3.3s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.900874639949274303:\\ \;\;\;\;\frac{e^{x}}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}\\ \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.900874639949274303:\\
\;\;\;\;\frac{e^{x}}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}\\

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

\end{array}
double f(double x) {
        double r105119 = x;
        double r105120 = exp(r105119);
        double r105121 = 1.0;
        double r105122 = r105120 - r105121;
        double r105123 = r105120 / r105122;
        return r105123;
}

double f(double x) {
        double r105124 = x;
        double r105125 = exp(r105124);
        double r105126 = 0.9008746399492743;
        bool r105127 = r105125 <= r105126;
        double r105128 = r105125 * r105125;
        double r105129 = 1.0;
        double r105130 = r105129 * r105129;
        double r105131 = r105128 - r105130;
        double r105132 = r105125 + r105129;
        double r105133 = r105131 / r105132;
        double r105134 = r105125 / r105133;
        double r105135 = 0.5;
        double r105136 = 0.08333333333333333;
        double r105137 = r105136 * r105124;
        double r105138 = 1.0;
        double r105139 = r105138 / r105124;
        double r105140 = r105137 + r105139;
        double r105141 = r105135 + r105140;
        double r105142 = r105127 ? r105134 : r105141;
        return r105142;
}

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.9008746399492743

    1. Initial program 0.0

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied flip--0.0

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

    if 0.9008746399492743 < (exp x)

    1. Initial program 61.9

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

Reproduce

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

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

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