Average Error: 41.7 → 0.6
Time: 3.4s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.00154165786243278392:\\ \;\;\;\;\frac{\frac{e^{x}}{\sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}}{\sqrt[3]{\frac{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{\sqrt[3]{e^{x} + 1} \cdot \sqrt[3]{e^{x} + 1}}} \cdot \sqrt[3]{\frac{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{\sqrt[3]{e^{x} + 1}}}}\\ \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}\;x \le -0.00154165786243278392:\\
\;\;\;\;\frac{\frac{e^{x}}{\sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}}{\sqrt[3]{\frac{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{\sqrt[3]{e^{x} + 1} \cdot \sqrt[3]{e^{x} + 1}}} \cdot \sqrt[3]{\frac{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{\sqrt[3]{e^{x} + 1}}}}\\

\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 ((x <= -0.001541657862432784)) {
		VAR = ((exp(x) / (cbrt((fma(-1.0, 1.0, exp((x + x))) / (exp(x) + 1.0))) * cbrt((fma(-1.0, 1.0, exp((x + x))) / (exp(x) + 1.0))))) / (cbrt(((cbrt(fma(-1.0, 1.0, exp((x + x)))) * cbrt(fma(-1.0, 1.0, exp((x + x))))) / (cbrt((exp(x) + 1.0)) * cbrt((exp(x) + 1.0))))) * cbrt((cbrt(fma(-1.0, 1.0, exp((x + 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.7
Target41.2
Herbie0.6
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -0.001541657862432784

    1. Initial program 0.0

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied flip--0.0

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

      \[\leadsto \frac{e^{x}}{\frac{\color{blue}{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{e^{x} + 1}}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt0.0

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

      \[\leadsto \color{blue}{\frac{\frac{e^{x}}{\sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}}{\sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}}\]
    8. Using strategy rm
    9. Applied add-cube-cbrt0.0

      \[\leadsto \frac{\frac{e^{x}}{\sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}}{\sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{\color{blue}{\left(\sqrt[3]{e^{x} + 1} \cdot \sqrt[3]{e^{x} + 1}\right) \cdot \sqrt[3]{e^{x} + 1}}}}}\]
    10. Applied add-cube-cbrt0.0

      \[\leadsto \frac{\frac{e^{x}}{\sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}}{\sqrt[3]{\frac{\color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}}{\left(\sqrt[3]{e^{x} + 1} \cdot \sqrt[3]{e^{x} + 1}\right) \cdot \sqrt[3]{e^{x} + 1}}}}\]
    11. Applied times-frac0.0

      \[\leadsto \frac{\frac{e^{x}}{\sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}}{\sqrt[3]{\color{blue}{\frac{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{\sqrt[3]{e^{x} + 1} \cdot \sqrt[3]{e^{x} + 1}} \cdot \frac{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{\sqrt[3]{e^{x} + 1}}}}}\]
    12. Applied cbrt-prod0.0

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

    if -0.001541657862432784 < x

    1. Initial program 62.0

      \[\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. Simplified0.9

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

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

Reproduce

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

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

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