Average Error: 40.6 → 0.6
Time: 2.3s
Precision: binary64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 0.9705930332237138:\\ \;\;\;\;\frac{1}{\sqrt[3]{e^{x} - 1} \cdot \sqrt[3]{e^{x} - 1}} \cdot \frac{e^{x}}{\sqrt[3]{e^{x} - 1}}\\ \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}\;e^{x} \leq 0.9705930332237138:\\
\;\;\;\;\frac{1}{\sqrt[3]{e^{x} - 1} \cdot \sqrt[3]{e^{x} - 1}} \cdot \frac{e^{x}}{\sqrt[3]{e^{x} - 1}}\\

\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 (<= (exp x) 0.9705930332237138)
   (*
    (/ 1.0 (* (cbrt (- (exp x) 1.0)) (cbrt (- (exp x) 1.0))))
    (/ (exp x) (cbrt (- (exp x) 1.0))))
   (+ 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 (exp(x) <= 0.9705930332237138) {
		tmp = (1.0 / (cbrt(exp(x) - 1.0) * cbrt(exp(x) - 1.0))) * (exp(x) / cbrt(exp(x) - 1.0));
	} 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

Original40.6
Target40.2
Herbie0.6
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 0.0

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt_binary640.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\left(\sqrt[3]{e^{x} - 1} \cdot \sqrt[3]{e^{x} - 1}\right) \cdot \sqrt[3]{e^{x} - 1}}}\]
    4. Applied *-un-lft-identity_binary640.0

      \[\leadsto \frac{\color{blue}{1 \cdot e^{x}}}{\left(\sqrt[3]{e^{x} - 1} \cdot \sqrt[3]{e^{x} - 1}\right) \cdot \sqrt[3]{e^{x} - 1}}\]
    5. Applied times-frac_binary640.0

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

    if 0.97059303322371382 < (exp.f64 x)

    1. Initial program 61.7

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

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

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

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

Reproduce

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

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

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