Average Error: 41.9 → 0.8
Time: 7.5s
Precision: binary64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -4.229675408144548 \cdot 10^{-06}:\\ \;\;\;\;\frac{e^{x}}{e^{x + x} + -1} \cdot \left(e^{x} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;e^{x} \cdot \frac{1}{x + \frac{x \cdot x}{2}}\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;x \leq -4.229675408144548 \cdot 10^{-06}:\\
\;\;\;\;\frac{e^{x}}{e^{x + x} + -1} \cdot \left(e^{x} + 1\right)\\

\mathbf{else}:\\
\;\;\;\;e^{x} \cdot \frac{1}{x + \frac{x \cdot x}{2}}\\

\end{array}
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x)
 :precision binary64
 (if (<= x -4.229675408144548e-06)
   (* (/ (exp x) (+ (exp (+ x x)) -1.0)) (+ (exp x) 1.0))
   (* (exp x) (/ 1.0 (+ x (/ (* x x) 2.0))))))
double code(double x) {
	return exp(x) / (exp(x) - 1.0);
}
double code(double x) {
	double tmp;
	if (x <= -4.229675408144548e-06) {
		tmp = (exp(x) / (exp(x + x) + -1.0)) * (exp(x) + 1.0);
	} else {
		tmp = exp(x) * (1.0 / (x + ((x * x) / 2.0)));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original41.9
Target41.5
Herbie0.8
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -4.2296754081445479e-6

    1. Initial program 0.1

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

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

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

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

    if -4.2296754081445479e-6 < x

    1. Initial program 62.2

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

      \[\leadsto \frac{e^{x}}{\color{blue}{x + \frac{x \cdot x}{2}}}\]
    3. Using strategy rm
    4. Applied div-inv_binary641.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.229675408144548 \cdot 10^{-06}:\\ \;\;\;\;\frac{e^{x}}{e^{x + x} + -1} \cdot \left(e^{x} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;e^{x} \cdot \frac{1}{x + \frac{x \cdot x}{2}}\\ \end{array}\]

Reproduce

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

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

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