Average Error: 40.1 → 0.9
Time: 3.6s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.0:\\ \;\;\;\;\frac{\left(\left({\left(e^{x}\right)}^{6} + \left(-{1}^{3} \cdot {1}^{3}\right)\right) \cdot \left(1 \cdot \left(1 + e^{x}\right) + {\left(e^{x}\right)}^{2}\right)\right) \cdot \frac{e^{x}}{{\left(e^{x}\right)}^{3} \cdot {\left(e^{x}\right)}^{3} - {1}^{3} \cdot {1}^{3}}}{{\left(e^{x}\right)}^{3} - {1}^{3}}\\ \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.0:\\
\;\;\;\;\frac{\left(\left({\left(e^{x}\right)}^{6} + \left(-{1}^{3} \cdot {1}^{3}\right)\right) \cdot \left(1 \cdot \left(1 + e^{x}\right) + {\left(e^{x}\right)}^{2}\right)\right) \cdot \frac{e^{x}}{{\left(e^{x}\right)}^{3} \cdot {\left(e^{x}\right)}^{3} - {1}^{3} \cdot {1}^{3}}}{{\left(e^{x}\right)}^{3} - {1}^{3}}\\

\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.0)) {
		VAR = ((((pow(exp(x), 6.0) + -(pow(1.0, 3.0) * pow(1.0, 3.0))) * ((1.0 * (1.0 + exp(x))) + pow(exp(x), 2.0))) * (exp(x) / ((pow(exp(x), 3.0) * pow(exp(x), 3.0)) - (pow(1.0, 3.0) * pow(1.0, 3.0))))) / (pow(exp(x), 3.0) - pow(1.0, 3.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

Original40.1
Target39.7
Herbie0.9
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 0

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

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

      \[\leadsto \color{blue}{\frac{e^{x}}{{\left(e^{x}\right)}^{3} - {1}^{3}} \cdot \left(e^{x} \cdot e^{x} + \left(1 \cdot 1 + e^{x} \cdot 1\right)\right)}\]
    5. Using strategy rm
    6. Applied flip--0

      \[\leadsto \frac{e^{x}}{\color{blue}{\frac{{\left(e^{x}\right)}^{3} \cdot {\left(e^{x}\right)}^{3} - {1}^{3} \cdot {1}^{3}}{{\left(e^{x}\right)}^{3} + {1}^{3}}}} \cdot \left(e^{x} \cdot e^{x} + \left(1 \cdot 1 + e^{x} \cdot 1\right)\right)\]
    7. Applied associate-/r/0

      \[\leadsto \color{blue}{\left(\frac{e^{x}}{{\left(e^{x}\right)}^{3} \cdot {\left(e^{x}\right)}^{3} - {1}^{3} \cdot {1}^{3}} \cdot \left({\left(e^{x}\right)}^{3} + {1}^{3}\right)\right)} \cdot \left(e^{x} \cdot e^{x} + \left(1 \cdot 1 + e^{x} \cdot 1\right)\right)\]
    8. Applied associate-*l*0

      \[\leadsto \color{blue}{\frac{e^{x}}{{\left(e^{x}\right)}^{3} \cdot {\left(e^{x}\right)}^{3} - {1}^{3} \cdot {1}^{3}} \cdot \left(\left({\left(e^{x}\right)}^{3} + {1}^{3}\right) \cdot \left(e^{x} \cdot e^{x} + \left(1 \cdot 1 + e^{x} \cdot 1\right)\right)\right)}\]
    9. Simplified0

      \[\leadsto \frac{e^{x}}{{\left(e^{x}\right)}^{3} \cdot {\left(e^{x}\right)}^{3} - {1}^{3} \cdot {1}^{3}} \cdot \color{blue}{\left(\left(1 \cdot \left(1 + e^{x}\right) + {\left(e^{x}\right)}^{2}\right) \cdot \left({\left(e^{x}\right)}^{3} + {1}^{3}\right)\right)}\]
    10. Using strategy rm
    11. Applied flip-+0

      \[\leadsto \frac{e^{x}}{{\left(e^{x}\right)}^{3} \cdot {\left(e^{x}\right)}^{3} - {1}^{3} \cdot {1}^{3}} \cdot \left(\left(1 \cdot \left(1 + e^{x}\right) + {\left(e^{x}\right)}^{2}\right) \cdot \color{blue}{\frac{{\left(e^{x}\right)}^{3} \cdot {\left(e^{x}\right)}^{3} - {1}^{3} \cdot {1}^{3}}{{\left(e^{x}\right)}^{3} - {1}^{3}}}\right)\]
    12. Applied associate-*r/0

      \[\leadsto \frac{e^{x}}{{\left(e^{x}\right)}^{3} \cdot {\left(e^{x}\right)}^{3} - {1}^{3} \cdot {1}^{3}} \cdot \color{blue}{\frac{\left(1 \cdot \left(1 + e^{x}\right) + {\left(e^{x}\right)}^{2}\right) \cdot \left({\left(e^{x}\right)}^{3} \cdot {\left(e^{x}\right)}^{3} - {1}^{3} \cdot {1}^{3}\right)}{{\left(e^{x}\right)}^{3} - {1}^{3}}}\]
    13. Applied associate-*r/0

      \[\leadsto \color{blue}{\frac{\frac{e^{x}}{{\left(e^{x}\right)}^{3} \cdot {\left(e^{x}\right)}^{3} - {1}^{3} \cdot {1}^{3}} \cdot \left(\left(1 \cdot \left(1 + e^{x}\right) + {\left(e^{x}\right)}^{2}\right) \cdot \left({\left(e^{x}\right)}^{3} \cdot {\left(e^{x}\right)}^{3} - {1}^{3} \cdot {1}^{3}\right)\right)}{{\left(e^{x}\right)}^{3} - {1}^{3}}}\]
    14. Simplified0

      \[\leadsto \frac{\color{blue}{\left(\left({\left(e^{x}\right)}^{6} + \left(-{1}^{3} \cdot {1}^{3}\right)\right) \cdot \left(1 \cdot \left(1 + e^{x}\right) + {\left(e^{x}\right)}^{2}\right)\right) \cdot \frac{e^{x}}{{\left(e^{x}\right)}^{3} \cdot {\left(e^{x}\right)}^{3} - {1}^{3} \cdot {1}^{3}}}}{{\left(e^{x}\right)}^{3} - {1}^{3}}\]

    if 0.0 < (exp x)

    1. Initial program 61.1

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

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

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

Reproduce

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

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

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