wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \leq 2.8502121317239544 \cdot 10^{-14}:\\
\;\;\;\;x + wj \cdot \left(wj + x \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;wj + \frac{x \cdot e^{-wj} - wj}{wj + 1}\\
\end{array}(FPCore (wj x) :precision binary64 (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))
(FPCore (wj x) :precision binary64 (if (<= wj 2.8502121317239544e-14) (+ x (* wj (+ wj (* x -2.0)))) (+ wj (/ (- (* x (exp (- wj))) wj) (+ wj 1.0)))))
double code(double wj, double x) {
return wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj))));
}
double code(double wj, double x) {
double tmp;
if (wj <= 2.8502121317239544e-14) {
tmp = x + (wj * (wj + (x * -2.0)));
} else {
tmp = wj + (((x * exp(-wj)) - wj) / (wj + 1.0));
}
return tmp;
}




Bits error versus wj




Bits error versus x
Results
| Original | 13.5 |
|---|---|
| Target | 13.0 |
| Herbie | 1.0 |
if wj < 2.85021213172395437e-14Initial program 13.2
Simplified13.2
Taylor expanded around 0 0.7
Simplified0.8
if 2.85021213172395437e-14 < wj Initial program 21.7
Simplified6.7
rmApplied div-inv_binary646.7
Simplified6.6
Final simplification1.0
herbie shell --seed 2020253
(FPCore (wj x)
:name "Jmat.Real.lambertw, newton loop step"
:precision binary64
:herbie-target
(- wj (- (/ wj (+ wj 1.0)) (/ x (+ (exp wj) (* wj (exp wj))))))
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))