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

\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.0)
   (/
    (exp x)
    (+
     x
     (*
      (* x x)
      (+ 0.5 (* x (+ 0.16666666666666666 (* x 0.041666666666666664)))))))
   (/ 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.0) {
		tmp = exp(x) / (x + ((x * x) * (0.5 + (x * (0.16666666666666666 + (x * 0.041666666666666664))))));
	} 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.7
Target41.3
Herbie0.7
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 42.0

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

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

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

    if 1 < (exp.f64 x)

    1. Initial program 32.9

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

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

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

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

Reproduce

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

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

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