Average Error: 40.5 → 0.3
Time: 9.8s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.0 \lor \neg \left(e^{x} \le 1.0001616862874831\right):\\ \;\;\;\;\frac{1}{1 - \frac{1}{e^{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.0 \lor \neg \left(e^{x} \le 1.0001616862874831\right):\\
\;\;\;\;\frac{1}{1 - \frac{1}{e^{x}}}\\

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

\end{array}
double f(double x) {
        double r117424 = x;
        double r117425 = exp(r117424);
        double r117426 = 1.0;
        double r117427 = r117425 - r117426;
        double r117428 = r117425 / r117427;
        return r117428;
}

double f(double x) {
        double r117429 = x;
        double r117430 = exp(r117429);
        double r117431 = 0.0;
        bool r117432 = r117430 <= r117431;
        double r117433 = 1.0001616862874831;
        bool r117434 = r117430 <= r117433;
        double r117435 = !r117434;
        bool r117436 = r117432 || r117435;
        double r117437 = 1.0;
        double r117438 = 1.0;
        double r117439 = r117438 / r117430;
        double r117440 = r117437 - r117439;
        double r117441 = r117437 / r117440;
        double r117442 = 0.5;
        double r117443 = 0.08333333333333333;
        double r117444 = r117443 * r117429;
        double r117445 = r117437 / r117429;
        double r117446 = r117444 + r117445;
        double r117447 = r117442 + r117446;
        double r117448 = r117436 ? r117441 : r117447;
        return r117448;
}

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.3
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Split input into 2 regimes
  2. if (exp x) < 0.0 or 1.0001616862874831 < (exp x)

    1. Initial program 1.3

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

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

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

    if 0.0 < (exp x) < 1.0001616862874831

    1. Initial program 62.0

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

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

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

Reproduce

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

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

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