wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \leq 9.953616011917723 \cdot 10^{-07}:\\
\;\;\;\;x + \left(\left(wj \cdot wj\right) \cdot \left(\left(x \cdot 2.5 + 1\right) - wj\right) - x \cdot \left(\left(wj + wj\right) + {wj}^{3} \cdot 2.6666666666666665\right)\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 9.953616011917723e-07)
(+
x
(-
(* (* wj wj) (- (+ (* x 2.5) 1.0) wj))
(* x (+ (+ wj wj) (* (pow wj 3.0) 2.6666666666666665)))))
(+ 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 <= 9.953616011917723e-07) {
tmp = x + (((wj * wj) * (((x * 2.5) + 1.0) - wj)) - (x * ((wj + wj) + (pow(wj, 3.0) * 2.6666666666666665))));
} else {
tmp = wj + (((x * exp(-wj)) - wj) / (wj + 1.0));
}
return tmp;
}




Bits error versus wj




Bits error versus x
Results
| Original | 13.4 |
|---|---|
| Target | 12.8 |
| Herbie | 0.6 |
if wj < 9.953616011917723e-7Initial program 13.1
Simplified13.1
Taylor expanded around 0 0.6
Simplified0.6
rmApplied associate--r+_binary64_37650.6
Simplified0.6
if 9.953616011917723e-7 < wj Initial program 28.2
Simplified1.7
rmApplied div-inv_binary64_38261.7
Simplified1.7
Final simplification0.6
herbie shell --seed 2020357
(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))))))