Average Error: 41.1 → 0.7
Time: 2.4s
Precision: binary64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -0.0016413502069231225:\\ \;\;\;\;\sqrt{e^{x} + 1} \cdot \frac{\sqrt{e^{x} + 1}}{e^{x} - e^{-x}}\\ \mathbf{else}:\\ \;\;\;\;0.5 + \left(x \cdot 0.08333333333333333 + \frac{1}{x}\right)\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;x \leq -0.0016413502069231225:\\
\;\;\;\;\sqrt{e^{x} + 1} \cdot \frac{\sqrt{e^{x} + 1}}{e^{x} - e^{-x}}\\

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

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

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    1. Initial program 0.0

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

      \[\leadsto \frac{e^{x}}{\color{blue}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}}\]
    4. Applied associate-/r/_binary640.0

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

      \[\leadsto \color{blue}{\frac{1}{e^{x} - e^{-x}}} \cdot \left(e^{x} + 1\right)\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt_binary640.0

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

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

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

    if -0.0016413502069231225 < x

    1. Initial program 61.7

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

      \[\leadsto \color{blue}{0.5 + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)}\]
    3. Simplified1.0

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

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

Reproduce

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

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

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