\frac{e^{x}}{e^{x} - 1}\begin{array}{l}
\mathbf{if}\;e^{x} \leq 1.0000000004016756:\\
\;\;\;\;\log \left(e^{e^{x} \cdot \left(x \cdot 0.08333333333333333\right)}\right) + e^{x} \cdot \left(\frac{1}{x} - 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x)
:precision binary64
(if (<= (exp x) 1.0000000004016756)
(+
(log (exp (* (exp x) (* x 0.08333333333333333))))
(* (exp x) (- (/ 1.0 x) 0.5)))
1.0))double code(double x) {
return exp(x) / (exp(x) - 1.0);
}
double code(double x) {
double tmp;
if (exp(x) <= 1.0000000004016756) {
tmp = log(exp(exp(x) * (x * 0.08333333333333333))) + (exp(x) * ((1.0 / x) - 0.5));
} else {
tmp = 1.0;
}
return tmp;
}















Bits error versus x
Results
| Original | 41.4 |
|---|---|
| Target | 41.0 |
| Herbie | 0.9 |
| Alternative 1 | |
|---|---|
| Error | 0.9 |
| Cost | 26496 |
| Alternative 2 | |
|---|---|
| Error | 0.9 |
| Cost | 13632 |
| Alternative 3 | |
|---|---|
| Error | 0.9 |
| Cost | 7104 |
| Alternative 4 | |
|---|---|
| Error | 0.8 |
| Cost | 7105 |
| Alternative 5 | |
|---|---|
| Error | 1.6 |
| Cost | 6592 |
| Alternative 6 | |
|---|---|
| Error | 0.8 |
| Cost | 897 |
| Alternative 7 | |
|---|---|
| Error | 1.1 |
| Cost | 641 |
| Alternative 8 | |
|---|---|
| Error | 1.5 |
| Cost | 513 |
| Alternative 9 | |
|---|---|
| Error | 41.0 |
| Cost | 385 |
| Alternative 10 | |
|---|---|
| Error | 42.1 |
| Cost | 64 |
| Alternative 11 | |
|---|---|
| Error | 62.0 |
| Cost | 64 |

if (exp.f64 x) < 1.0000000004016756Initial program 41.7
rmApplied div-inv_binary64_178041.7
Taylor expanded around 0 0.2
Simplified0.2
rmApplied distribute-rgt-in_binary64_17330.2
rmApplied add-log-exp_binary64_18220.2
Simplified0.2
if 1.0000000004016756 < (exp.f64 x) Initial program 33.2
Simplified33.2
Final simplification0.9
herbie shell --seed 2021014
(FPCore (x)
:name "expq2 (section 3.11)"
:precision binary64
:herbie-target
(/ 1.0 (- 1.0 (exp (- x))))
(/ (exp x) (- (exp x) 1.0)))