Average Error: 41.3 → 0.5
Time: 3.5s
Precision: binary64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 1.00000001162283:\\ \;\;\;\;\frac{e^{x}}{x + 0.5 \cdot {x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 - e^{-x}}\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \leq 1.00000001162283:\\
\;\;\;\;\frac{e^{x}}{x + 0.5 \cdot {x}^{2}}\\

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

\end{array}
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x)
 :precision binary64
 (if (<= (exp x) 1.00000001162283)
   (/ (exp x) (+ x (* 0.5 (pow x 2.0))))
   (/ 1.0 (- 1.0 (exp (- x))))))
double code(double x) {
	return exp(x) / (exp(x) - 1.0);
}
double code(double x) {
	double tmp;
	if (exp(x) <= 1.00000001162283) {
		tmp = exp(x) / (x + (0.5 * pow(x, 2.0)));
	} else {
		tmp = 1.0 / (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.3
Target40.9
Herbie0.5
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 41.5

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

      \[\leadsto \frac{e^{x}}{\color{blue}{x + 0.5 \cdot {x}^{2}}}\]

    if 1.00000001162283003 < (exp.f64 x)

    1. Initial program 26.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{x} \leq 1.00000001162283:\\ \;\;\;\;\frac{e^{x}}{x + 0.5 \cdot {x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 - e^{-x}}\\ \end{array}\]

Reproduce

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

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

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