wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \le 8.74113048810989798 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(wj, wj, x - 2 \cdot \left(wj \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;wj + \left(\frac{\frac{x}{wj \cdot wj - 1}}{\frac{e^{wj}}{wj - 1}} - \frac{wj}{wj + 1}\right)\\
\end{array}double code(double wj, double x) {
return (wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj)))));
}
double code(double wj, double x) {
double VAR;
if ((wj <= 8.741130488109898e-09)) {
VAR = fma(wj, wj, (x - (2.0 * (wj * x))));
} else {
VAR = (wj + (((x / ((wj * wj) - 1.0)) / (exp(wj) / (wj - 1.0))) - (wj / (wj + 1.0))));
}
return VAR;
}




Bits error versus wj




Bits error versus x
Results
| Original | 13.7 |
|---|---|
| Target | 13.2 |
| Herbie | 1.0 |
if wj < 8.741130488109898e-09Initial program 13.4
Simplified13.4
Taylor expanded around 0 1.0
Simplified0.9
if 8.741130488109898e-09 < wj Initial program 23.9
Simplified3.8
rmApplied +-commutative3.8
Applied associate--l+3.8
rmApplied flip-+3.8
Applied associate-/r/3.8
Applied associate-/l*3.8
Final simplification1.0
herbie shell --seed 2020078 +o rules:numerics
(FPCore (wj x)
:name "Jmat.Real.lambertw, newton loop step"
:precision binary64
:herbie-target
(- wj (- (/ wj (+ wj 1)) (/ x (+ (exp wj) (* wj (exp wj))))))
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))