\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;
}




Bits error versus x
Results
| Original | 40.4 |
|---|---|
| Target | 40.0 |
| Herbie | 0.8 |
if (exp.f64 x) < 1Initial program 40.6
Taylor expanded around 0 0.4
Simplified0.4
if 1 < (exp.f64 x) Initial program 33.5
rmApplied clear-num_binary6433.5
Simplified16.7
rmApplied add-sqr-sqrt_binary6417.4
Applied *-un-lft-identity_binary6417.4
Applied difference-of-squares_binary6417.3
Applied associate-/r*_binary6417.3
Simplified17.3
rmApplied add-exp-log_binary6417.3
Simplified17.3
Final simplification0.8
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)))