Average Error: 41.2 → 0.7
Time: 2.9s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.0018202857526859206:\\ \;\;\;\;\frac{e^{x}}{\mathsf{fma}\left(\sqrt[3]{e^{x}} \cdot \sqrt[3]{e^{x}}, \sqrt[3]{e^{x}}, -1\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{x}\right) + \frac{1}{2}\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \le 0.0018202857526859206:\\
\;\;\;\;\frac{e^{x}}{\mathsf{fma}\left(\sqrt[3]{e^{x}} \cdot \sqrt[3]{e^{x}}, \sqrt[3]{e^{x}}, -1\right)}\\

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

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

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    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}} \cdot \sqrt[3]{e^{x}}\right) \cdot \sqrt[3]{e^{x}}} - 1}\]
    4. Applied fma-neg0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{fma}\left(\sqrt[3]{e^{x}} \cdot \sqrt[3]{e^{x}}, \sqrt[3]{e^{x}}, -1\right)}}\]

    if 0.0018202857526859206 < (exp x)

    1. Initial program 61.6

      \[\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. Simplified1.0

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

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

Reproduce

herbie shell --seed 2020078 +o rules:numerics
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

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

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