Average Error: 41.3 → 0.7
Time: 2.7s
Precision: binary64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 2.9364953566114182 \cdot 10^{-64}:\\ \;\;\;\;\frac{1}{1 + \sqrt{e^{x}}} \cdot \frac{e^{x}}{\sqrt{e^{x}} + -1}\\ \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 2.9364953566114182 \cdot 10^{-64}:\\
\;\;\;\;\frac{1}{1 + \sqrt{e^{x}}} \cdot \frac{e^{x}}{\sqrt{e^{x}} + -1}\\

\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) 2.9364953566114182e-64)
   (* (/ 1.0 (+ 1.0 (sqrt (exp x)))) (/ (exp x) (+ (sqrt (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) <= 2.9364953566114182e-64) {
		tmp = (1.0 / (1.0 + sqrt(exp(x)))) * (exp(x) / (sqrt(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.3
Target40.9
Herbie0.7
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 0

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

      \[\leadsto \frac{e^{x}}{\color{blue}{\sqrt{e^{x}} \cdot \sqrt{e^{x}}} - 1}\]
    4. Applied difference-of-sqr-1_binary64_7210

      \[\leadsto \frac{e^{x}}{\color{blue}{\left(\sqrt{e^{x}} + 1\right) \cdot \left(\sqrt{e^{x}} - 1\right)}}\]
    5. Applied *-un-lft-identity_binary64_7510

      \[\leadsto \frac{\color{blue}{1 \cdot e^{x}}}{\left(\sqrt{e^{x}} + 1\right) \cdot \left(\sqrt{e^{x}} - 1\right)}\]
    6. Applied times-frac_binary64_7570

      \[\leadsto \color{blue}{\frac{1}{\sqrt{e^{x}} + 1} \cdot \frac{e^{x}}{\sqrt{e^{x}} - 1}}\]
    7. Simplified0

      \[\leadsto \color{blue}{\frac{1}{1 + \sqrt{e^{x}}}} \cdot \frac{e^{x}}{\sqrt{e^{x}} - 1}\]
    8. Simplified0

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

    if 2.9364953566114182e-64 < (exp.f64 x)

    1. Initial program 61.8

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

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

      \[\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 2.9364953566114182 \cdot 10^{-64}:\\ \;\;\;\;\frac{1}{1 + \sqrt{e^{x}}} \cdot \frac{e^{x}}{\sqrt{e^{x}} + -1}\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.08333333333333333 + \left(0.5 + \frac{1}{x}\right)\\ \end{array}\]

Reproduce

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

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

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