\frac{e^{x}}{e^{x} - 1}\begin{array}{l}
\mathbf{if}\;e^{x} \le 0.0:\\
\;\;\;\;\frac{e^{x}}{\log \left(e^{e^{x} - 1}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} + e^{\log \left(\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(x, \frac{1}{12}, \frac{1}{2}\right)\right)\right)\right)}\\
\end{array}double f(double x) {
double r3058453 = x;
double r3058454 = exp(r3058453);
double r3058455 = 1.0;
double r3058456 = r3058454 - r3058455;
double r3058457 = r3058454 / r3058456;
return r3058457;
}
double f(double x) {
double r3058458 = x;
double r3058459 = exp(r3058458);
double r3058460 = 0.0;
bool r3058461 = r3058459 <= r3058460;
double r3058462 = 1.0;
double r3058463 = r3058459 - r3058462;
double r3058464 = exp(r3058463);
double r3058465 = log(r3058464);
double r3058466 = r3058459 / r3058465;
double r3058467 = 1.0;
double r3058468 = r3058467 / r3058458;
double r3058469 = 0.08333333333333333;
double r3058470 = 0.5;
double r3058471 = fma(r3058458, r3058469, r3058470);
double r3058472 = log1p(r3058471);
double r3058473 = expm1(r3058472);
double r3058474 = log(r3058473);
double r3058475 = exp(r3058474);
double r3058476 = r3058468 + r3058475;
double r3058477 = r3058461 ? r3058466 : r3058476;
return r3058477;
}




Bits error versus x
| Original | 41.5 |
|---|---|
| Target | 41.2 |
| Herbie | 0.8 |
if (exp x) < 0.0Initial program 0
rmApplied add-log-exp0
Applied add-log-exp0
Applied diff-log0
Simplified0
if 0.0 < (exp x) Initial program 61.6
Taylor expanded around 0 1.1
Simplified1.1
rmApplied add-sqr-sqrt1.1
rmApplied add-exp-log1.1
Applied add-exp-log1.1
Applied prod-exp1.1
Simplified1.1
rmApplied expm1-log1p-u1.1
Final simplification0.8
herbie shell --seed 2019171 +o rules:numerics
(FPCore (x)
:name "expq2 (section 3.11)"
:herbie-target
(/ 1.0 (- 1.0 (exp (- x))))
(/ (exp x) (- (exp x) 1.0)))