wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \leq 5.067437279036206 \cdot 10^{-16}:\\
\;\;\;\;x + wj \cdot \left(wj + x \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;wj + \frac{\frac{\frac{x}{e^{wj}} - wj}{\sqrt{wj + 1}}}{\sqrt{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 5.067437279036206e-16) (+ x (* wj (+ wj (* x -2.0)))) (+ wj (/ (/ (- (/ x (exp wj)) wj) (sqrt (+ wj 1.0))) (sqrt (+ 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 <= 5.067437279036206e-16) {
tmp = x + (wj * (wj + (x * -2.0)));
} else {
tmp = wj + ((((x / exp(wj)) - wj) / sqrt(wj + 1.0)) / sqrt(wj + 1.0));
}
return tmp;
}




Bits error versus wj




Bits error versus x
Results
| Original | 13.5 |
|---|---|
| Target | 12.9 |
| Herbie | 1.1 |
if wj < 5.0674372790362063e-16Initial program 13.2
Simplified13.2
Taylor expanded around 0 0.9
Simplified0.9
if 5.0674372790362063e-16 < wj Initial program 20.6
Simplified5.5
rmApplied add-sqr-sqrt_binary645.8
Applied associate-/r*_binary645.8
Final simplification1.1
herbie shell --seed 2020219
(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))))))