Average Error: 41.3 → 0.9
Time: 3.9s
Precision: binary64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;\frac{e^{x}}{e^{x} - 1} \leq 6.7951388768857965:\\ \;\;\;\;\frac{e^{x}}{\sqrt[3]{\left(e^{x} - 1\right) \cdot \left(\left(e^{x} - 1\right) \cdot \left(e^{x} - 1\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\left(\left(0.5 + \frac{1}{x}\right) + x \cdot 0.08333333333333333\right) - {x}^{3} \cdot 0.001388888888888889\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;\frac{e^{x}}{e^{x} - 1} \leq 6.7951388768857965:\\
\;\;\;\;\frac{e^{x}}{\sqrt[3]{\left(e^{x} - 1\right) \cdot \left(\left(e^{x} - 1\right) \cdot \left(e^{x} - 1\right)\right)}}\\

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

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

Derivation

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

    1. Initial program 1.2

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied add-cbrt-cube_binary64_14781.2

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

    if 6.79513887688579654 < (/.f64 (exp.f64 x) (-.f64 (exp.f64 x) 1))

    1. Initial program 63.0

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

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

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

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

Reproduce

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

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

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