wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \le 7.68538994010771746 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(wj, wj, x\right) - 2 \cdot \left(wj \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{\frac{\frac{x}{wj + 1}}{e^{wj}} + wj}, \sqrt{\frac{\frac{x}{wj + 1}}{e^{wj}} + wj}, -\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 <= 7.685389940107717e-07)) {
VAR = (fma(wj, wj, x) - (2.0 * (wj * x)));
} else {
VAR = fma(sqrt((((x / (wj + 1.0)) / exp(wj)) + wj)), sqrt((((x / (wj + 1.0)) / exp(wj)) + wj)), -(wj / (wj + 1.0)));
}
return VAR;
}




Bits error versus wj




Bits error versus x
Results
| Original | 13.5 |
|---|---|
| Target | 12.7 |
| Herbie | 1.2 |
if wj < 7.685389940107717e-07Initial program 13.0
Simplified13.0
Taylor expanded around 0 0.9
Taylor expanded around 0 0.9
Simplified0.9
if 7.685389940107717e-07 < wj Initial program 32.9
Simplified2.1
rmApplied add-sqr-sqrt11.3
Applied fma-neg11.2
Final simplification1.2
herbie shell --seed 2020075 +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))))))