Average Error: 41.2 → 0.7
Time: 2.7s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.994377561105835306:\\ \;\;\;\;\frac{e^{x}}{\log \left(e^{e^{x} - 1}\right)}\\ \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.994377561105835306:\\
\;\;\;\;\frac{e^{x}}{\log \left(e^{e^{x} - 1}\right)}\\

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

\end{array}
double f(double x) {
        double r100260 = x;
        double r100261 = exp(r100260);
        double r100262 = 1.0;
        double r100263 = r100261 - r100262;
        double r100264 = r100261 / r100263;
        return r100264;
}

double f(double x) {
        double r100265 = x;
        double r100266 = exp(r100265);
        double r100267 = 0.9943775611058353;
        bool r100268 = r100266 <= r100267;
        double r100269 = 1.0;
        double r100270 = r100266 - r100269;
        double r100271 = exp(r100270);
        double r100272 = log(r100271);
        double r100273 = r100266 / r100272;
        double r100274 = 0.5;
        double r100275 = 0.08333333333333333;
        double r100276 = r100275 * r100265;
        double r100277 = 1.0;
        double r100278 = r100277 / r100265;
        double r100279 = r100276 + r100278;
        double r100280 = r100274 + r100279;
        double r100281 = r100268 ? r100273 : r100280;
        return r100281;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original41.2
Target40.8
Herbie0.7
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 0.0

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied add-log-exp0.0

      \[\leadsto \frac{e^{x}}{e^{x} - \color{blue}{\log \left(e^{1}\right)}}\]
    4. Applied add-log-exp0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\log \left(e^{e^{x}}\right)} - \log \left(e^{1}\right)}\]
    5. Applied diff-log0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\log \left(\frac{e^{e^{x}}}{e^{1}}\right)}}\]
    6. Simplified0.0

      \[\leadsto \frac{e^{x}}{\log \color{blue}{\left(e^{e^{x} - 1}\right)}}\]

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

Reproduce

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

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

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