wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \le 8.77502422596044175 \cdot 10^{-9}:\\
\;\;\;\;\left(x + {wj}^{2}\right) - 2 \cdot \left(wj \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) - \frac{\sqrt{wj}}{\frac{wj + 1}{\sqrt{wj}}}\\
\end{array}double code(double wj, double x) {
return ((double) (wj - ((double) (((double) (((double) (wj * ((double) exp(wj)))) - x)) / ((double) (((double) exp(wj)) + ((double) (wj * ((double) exp(wj))))))))));
}
double code(double wj, double x) {
double VAR;
if ((wj <= 8.775024225960442e-09)) {
VAR = ((double) (((double) (x + ((double) pow(wj, 2.0)))) - ((double) (2.0 * ((double) (wj * x))))));
} else {
VAR = ((double) (((double) (((double) (((double) (x / ((double) (wj + 1.0)))) / ((double) exp(wj)))) + wj)) - ((double) (((double) sqrt(wj)) / ((double) (((double) (wj + 1.0)) / ((double) sqrt(wj))))))));
}
return VAR;
}




Bits error versus wj




Bits error versus x
Results
| Original | 13.4 |
|---|---|
| Target | 12.8 |
| Herbie | 0.8 |
if wj < 8.775024225960442e-09Initial program 13.1
Simplified13.1
Taylor expanded around 0 0.8
if 8.775024225960442e-09 < wj Initial program 25.5
Simplified2.8
rmApplied add-sqr-sqrt2.9
Applied associate-/l*2.9
Final simplification0.8
herbie shell --seed 2020126
(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))))))