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




Bits error versus wj




Bits error versus x
Results
| Original | 13.7 |
|---|---|
| Target | 13.1 |
| Herbie | 1.2 |
if wj < 1.0018755083909558e-09Initial program 13.4
Simplified13.4
Taylor expanded around 0 0.9
rmApplied add-sqr-sqrt29.3
Applied prod-diff29.3
Simplified0.9
Simplified0.9
if 1.0018755083909558e-09 < wj Initial program 25.7
Simplified2.8
rmApplied flip--11.3
Final simplification1.2
herbie shell --seed 2020049 +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))))))