Average Error: 41.5 → 0.6
Time: 2.7s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.854721837892698066:\\ \;\;\;\;\frac{\frac{e^{x}}{\sqrt[3]{e^{x} - 1} \cdot \sqrt[3]{e^{x} - 1}}}{\sqrt[3]{e^{x} - 1}}\\ \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.854721837892698066:\\
\;\;\;\;\frac{\frac{e^{x}}{\sqrt[3]{e^{x} - 1} \cdot \sqrt[3]{e^{x} - 1}}}{\sqrt[3]{e^{x} - 1}}\\

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

\end{array}
double code(double x) {
	return (exp(x) / (exp(x) - 1.0));
}
double code(double x) {
	double VAR;
	if ((exp(x) <= 0.8547218378926981)) {
		VAR = ((exp(x) / (cbrt((exp(x) - 1.0)) * cbrt((exp(x) - 1.0)))) / cbrt((exp(x) - 1.0)));
	} else {
		VAR = (0.5 + ((0.08333333333333333 * x) + (1.0 / x)));
	}
	return VAR;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    1. Initial program 0.0

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

      \[\leadsto \frac{e^{x}}{\color{blue}{\left(\sqrt[3]{e^{x} - 1} \cdot \sqrt[3]{e^{x} - 1}\right) \cdot \sqrt[3]{e^{x} - 1}}}\]
    4. Applied associate-/r*0.0

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

    if 0.8547218378926981 < (exp x)

    1. Initial program 61.7

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

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

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

Reproduce

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

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

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