wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \le 5.475491025907151 \cdot 10^{-09}:\\
\;\;\;\;\left(x \cdot wj\right) \cdot -2 + \mathsf{fma}\left(wj, wj, x\right)\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{e^{wj} \cdot wj - x}{e^{wj} \cdot \left(1 + wj\right)}\\
\end{array}double f(double wj, double x) {
double r7630386 = wj;
double r7630387 = exp(r7630386);
double r7630388 = r7630386 * r7630387;
double r7630389 = x;
double r7630390 = r7630388 - r7630389;
double r7630391 = r7630387 + r7630388;
double r7630392 = r7630390 / r7630391;
double r7630393 = r7630386 - r7630392;
return r7630393;
}
double f(double wj, double x) {
double r7630394 = wj;
double r7630395 = 5.475491025907151e-09;
bool r7630396 = r7630394 <= r7630395;
double r7630397 = x;
double r7630398 = r7630397 * r7630394;
double r7630399 = -2.0;
double r7630400 = r7630398 * r7630399;
double r7630401 = fma(r7630394, r7630394, r7630397);
double r7630402 = r7630400 + r7630401;
double r7630403 = exp(r7630394);
double r7630404 = r7630403 * r7630394;
double r7630405 = r7630404 - r7630397;
double r7630406 = 1.0;
double r7630407 = r7630406 + r7630394;
double r7630408 = r7630403 * r7630407;
double r7630409 = r7630405 / r7630408;
double r7630410 = r7630394 - r7630409;
double r7630411 = r7630396 ? r7630402 : r7630410;
return r7630411;
}




Bits error versus wj




Bits error versus x
| Original | 13.3 |
|---|---|
| Target | 12.6 |
| Herbie | 1.7 |
if wj < 5.475491025907151e-09Initial program 12.9
Taylor expanded around 0 0.9
Simplified0.9
if 5.475491025907151e-09 < wj Initial program 24.6
rmApplied distribute-rgt1-in24.8
Final simplification1.7
herbie shell --seed 2019129 +o rules:numerics
(FPCore (wj x)
:name "Jmat.Real.lambertw, newton loop step"
:herbie-target
(- wj (- (/ wj (+ wj 1)) (/ x (+ (exp wj) (* wj (exp wj))))))
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))