wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\begin{array}{l}
t_0 := \mathsf{fma}\left(wj, e^{wj}, e^{wj}\right)\\
\mathbf{if}\;wj \leq -1.7279931553913336 \cdot 10^{-158}:\\
\;\;\;\;wj - x \cdot -1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{t_0} + \left(wj - \frac{wj \cdot e^{wj}}{t_0}\right)\\
\end{array}
(FPCore (wj x) :precision binary64 (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))
(FPCore (wj x)
:precision binary64
(let* ((t_0 (fma wj (exp wj) (exp wj))))
(if (<= wj -1.7279931553913336e-158)
(- wj (* x -1.0))
(+ (/ x t_0) (- wj (/ (* wj (exp wj)) t_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 t_0 = fma(wj, exp(wj), exp(wj));
double tmp;
if (wj <= -1.7279931553913336e-158) {
tmp = wj - (x * -1.0);
} else {
tmp = (x / t_0) + (wj - ((wj * exp(wj)) / t_0));
}
return tmp;
}




Bits error versus wj




Bits error versus x
| Original | 13.2 |
|---|---|
| Target | 12.6 |
| Herbie | 10.7 |
if wj < -1.72799315539133361e-158Initial program 19.1
Taylor expanded in wj around 0 25.2
Simplified25.2
if -1.72799315539133361e-158 < wj Initial program 11.1
Taylor expanded in x around 0 11.1
Simplified5.6
Final simplification10.7
herbie shell --seed 2022127
(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))))))