Average Error: 40.1 → 0.5
Time: 26.5s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0015615142324954692:\\ \;\;\;\;\frac{e^{x}}{e^{x} - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{12} \cdot x + \left(\frac{1}{2} + \frac{1}{x}\right)\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;x \le -0.0015615142324954692:\\
\;\;\;\;\frac{e^{x}}{e^{x} - 1}\\

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

\end{array}
double f(double x) {
        double r11154132 = x;
        double r11154133 = exp(r11154132);
        double r11154134 = 1.0;
        double r11154135 = r11154133 - r11154134;
        double r11154136 = r11154133 / r11154135;
        return r11154136;
}

double f(double x) {
        double r11154137 = x;
        double r11154138 = -0.0015615142324954692;
        bool r11154139 = r11154137 <= r11154138;
        double r11154140 = exp(r11154137);
        double r11154141 = 1.0;
        double r11154142 = r11154140 - r11154141;
        double r11154143 = r11154140 / r11154142;
        double r11154144 = 0.08333333333333333;
        double r11154145 = r11154144 * r11154137;
        double r11154146 = 0.5;
        double r11154147 = r11154141 / r11154137;
        double r11154148 = r11154146 + r11154147;
        double r11154149 = r11154145 + r11154148;
        double r11154150 = r11154139 ? r11154143 : r11154149;
        return r11154150;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original40.1
Target39.8
Herbie0.5
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 0.0

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

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

    if -0.0015615142324954692 < x

    1. Initial program 60.1

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

      \[\leadsto \color{blue}{\frac{1}{12} \cdot x + \left(\frac{1}{x} + \frac{1}{2}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

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

Reproduce

herbie shell --seed 2019104 
(FPCore (x)
  :name "expq2 (section 3.11)"

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

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