Average Error: 40.1 → 0.9
Time: 16.2s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;\frac{e^{x}}{e^{x} - 1} \le 1.0:\\ \;\;\;\;\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}\;\frac{e^{x}}{e^{x} - 1} \le 1.0:\\
\;\;\;\;\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 r6838897 = x;
        double r6838898 = exp(r6838897);
        double r6838899 = 1.0;
        double r6838900 = r6838898 - r6838899;
        double r6838901 = r6838898 / r6838900;
        return r6838901;
}

double f(double x) {
        double r6838902 = x;
        double r6838903 = exp(r6838902);
        double r6838904 = 1.0;
        double r6838905 = r6838903 - r6838904;
        double r6838906 = r6838903 / r6838905;
        double r6838907 = 1.0;
        bool r6838908 = r6838906 <= r6838907;
        double r6838909 = 0.08333333333333333;
        double r6838910 = r6838909 * r6838902;
        double r6838911 = 0.5;
        double r6838912 = r6838904 / r6838902;
        double r6838913 = r6838911 + r6838912;
        double r6838914 = r6838910 + r6838913;
        double r6838915 = r6838908 ? r6838906 : r6838914;
        return r6838915;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original40.1
Target39.7
Herbie0.9
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Split input into 2 regimes
  2. if (/ (exp x) (- (exp x) 1)) < 1.0

    1. Initial program 1.3

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

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

    if 1.0 < (/ (exp x) (- (exp x) 1))

    1. Initial program 61.0

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

      \[\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.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{e^{x}}{e^{x} - 1} \le 1.0:\\ \;\;\;\;\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 2019125 
(FPCore (x)
  :name "expq2 (section 3.11)"

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

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