Average Error: 40.4 → 0.8
Time: 3.5s
Precision: binary64
\[\frac{e^{x}}{e^{x} - 1} \]
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 1:\\ \;\;\;\;\frac{e^{x}}{x + 0.5 \cdot \left(x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := {\left(e^{x}\right)}^{-0.5}\\ \frac{\frac{1}{1 + t_0}}{e^{\log \left(1 - t_0\right)}} \end{array}\\ \end{array} \]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \leq 1:\\
\;\;\;\;\frac{e^{x}}{x + 0.5 \cdot \left(x \cdot x\right)}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := {\left(e^{x}\right)}^{-0.5}\\
\frac{\frac{1}{1 + t_0}}{e^{\log \left(1 - t_0\right)}}
\end{array}\\


\end{array}
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x)
 :precision binary64
 (if (<= (exp x) 1.0)
   (/ (exp x) (+ x (* 0.5 (* x x))))
   (let* ((t_0 (pow (exp x) -0.5)))
     (/ (/ 1.0 (+ 1.0 t_0)) (exp (log (- 1.0 t_0)))))))
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 + (0.5 * (x * x)));
	} else {
		double t_0 = pow(exp(x), -0.5);
		tmp = (1.0 / (1.0 + t_0)) / exp(log(1.0 - t_0));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original40.4
Target40.0
Herbie0.8
\[\frac{1}{1 - e^{-x}} \]

Derivation

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

    1. Initial program 40.6

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

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

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

    if 1 < (exp.f64 x)

    1. Initial program 33.5

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

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

      \[\leadsto \frac{1}{\color{blue}{1 - e^{-x}}} \]
    5. Using strategy rm
    6. Applied add-sqr-sqrt_binary6417.4

      \[\leadsto \frac{1}{1 - \color{blue}{\sqrt{e^{-x}} \cdot \sqrt{e^{-x}}}} \]
    7. Applied *-un-lft-identity_binary6417.4

      \[\leadsto \frac{1}{\color{blue}{1 \cdot 1} - \sqrt{e^{-x}} \cdot \sqrt{e^{-x}}} \]
    8. Applied difference-of-squares_binary6417.3

      \[\leadsto \frac{1}{\color{blue}{\left(1 + \sqrt{e^{-x}}\right) \cdot \left(1 - \sqrt{e^{-x}}\right)}} \]
    9. Applied associate-/r*_binary6417.3

      \[\leadsto \color{blue}{\frac{\frac{1}{1 + \sqrt{e^{-x}}}}{1 - \sqrt{e^{-x}}}} \]
    10. Simplified17.3

      \[\leadsto \frac{\color{blue}{\frac{1}{1 + {\left(e^{x}\right)}^{-0.5}}}}{1 - \sqrt{e^{-x}}} \]
    11. Using strategy rm
    12. Applied add-exp-log_binary6417.3

      \[\leadsto \frac{\frac{1}{1 + {\left(e^{x}\right)}^{-0.5}}}{\color{blue}{e^{\log \left(1 - \sqrt{e^{-x}}\right)}}} \]
    13. Simplified17.3

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

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

Reproduce

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

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

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