Average Error: 41.4 → 0.3
Time: 2.7s
Precision: binary64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \leq 0.00015152468779096654:\\ \;\;\;\;\frac{e^{x}}{x + x \cdot \left(x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{1 - e^{-x}}} \cdot \frac{1}{\sqrt{1 - e^{-x}}}\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;x \leq 0.00015152468779096654:\\
\;\;\;\;\frac{e^{x}}{x + x \cdot \left(x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{1 - e^{-x}}} \cdot \frac{1}{\sqrt{1 - e^{-x}}}\\

\end{array}
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x)
 :precision binary64
 (if (<= x 0.00015152468779096654)
   (/ (exp x) (+ x (* x (* x (+ 0.5 (* x 0.16666666666666666))))))
   (* (/ 1.0 (sqrt (- 1.0 (exp (- x))))) (/ 1.0 (sqrt (- 1.0 (exp (- x))))))))
double code(double x) {
	return exp(x) / (exp(x) - 1.0);
}
double code(double x) {
	double tmp;
	if (x <= 0.00015152468779096654) {
		tmp = exp(x) / (x + (x * (x * (0.5 + (x * 0.16666666666666666)))));
	} else {
		tmp = (1.0 / sqrt(1.0 - exp(-x))) * (1.0 / sqrt(1.0 - exp(-x)));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original41.4
Target41.1
Herbie0.3
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < 1.5152468779096654e-4

    1. Initial program 41.6

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

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

      \[\leadsto \frac{e^{x}}{\color{blue}{x + x \cdot \left(x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)}}\]

    if 1.5152468779096654e-4 < x

    1. Initial program 29.1

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

      \[\leadsto \color{blue}{\frac{1}{\frac{e^{x} - 1}{e^{x}}}}\]
    4. Simplified1.2

      \[\leadsto \frac{1}{\color{blue}{1 - e^{-x}}}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt_binary64_7891.2

      \[\leadsto \frac{1}{\color{blue}{\sqrt{1 - e^{-x}} \cdot \sqrt{1 - e^{-x}}}}\]
    7. Applied add-sqr-sqrt_binary64_7891.2

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{\sqrt{1 - e^{-x}} \cdot \sqrt{1 - e^{-x}}}\]
    8. Applied times-frac_binary64_7731.3

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

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

      \[\leadsto \frac{1}{\sqrt{1 - e^{-x}}} \cdot \color{blue}{\frac{1}{\sqrt{1 - e^{-x}}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.00015152468779096654:\\ \;\;\;\;\frac{e^{x}}{x + x \cdot \left(x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{1 - e^{-x}}} \cdot \frac{1}{\sqrt{1 - e^{-x}}}\\ \end{array}\]

Reproduce

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

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

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