Average Error: 41.6 → 0.7
Time: 2.7s
Precision: binary64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 0.000290255873774867:\\ \;\;\;\;\frac{e^{x}}{\log \left(e^{e^{x} - 1}\right)}\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.08333333333333333 + \left(0.5 + \frac{1}{x}\right)\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \leq 0.000290255873774867:\\
\;\;\;\;\frac{e^{x}}{\log \left(e^{e^{x} - 1}\right)}\\

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

\end{array}
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x)
 :precision binary64
 (if (<= (exp x) 0.000290255873774867)
   (/ (exp x) (log (exp (- (exp x) 1.0))))
   (+ (* x 0.08333333333333333) (+ 0.5 (/ 1.0 x)))))
double code(double x) {
	return exp(x) / (exp(x) - 1.0);
}
double code(double x) {
	double tmp;
	if (exp(x) <= 0.000290255873774867) {
		tmp = exp(x) / log(exp(exp(x) - 1.0));
	} else {
		tmp = (x * 0.08333333333333333) + (0.5 + (1.0 / x));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (exp.f64 x) < 2.90255873774866973e-4

    1. Initial program 0

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

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

      \[\leadsto \frac{e^{x}}{\color{blue}{\log \left(e^{e^{x}}\right)} - \log \left(e^{1}\right)}\]
    5. Applied diff-log_binary64_11770.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 2.90255873774866973e-4 < (exp.f64 x)

    1. Initial program 61.4

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

      \[\leadsto \color{blue}{0.08333333333333333 \cdot x + \left(\frac{1}{x} + 0.5\right)}\]
    3. Simplified1.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{x} \leq 0.000290255873774867:\\ \;\;\;\;\frac{e^{x}}{\log \left(e^{e^{x} - 1}\right)}\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.08333333333333333 + \left(0.5 + \frac{1}{x}\right)\\ \end{array}\]

Reproduce

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

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

  (/ (exp x) (- (exp x) 1.0)))