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




Bits error versus wj




Bits error versus x
Results
| Original | 13.5 |
|---|---|
| Target | 12.9 |
| Herbie | 0.9 |
if wj < 1.896203624158786e-10Initial program 13.2
Simplified13.2
Taylor expanded around 0 0.8
if 1.896203624158786e-10 < wj Initial program 22.5
Simplified4.4
rmApplied *-un-lft-identity4.4
Applied flip-+4.4
Applied associate-/r/4.4
Applied times-frac4.4
Simplified4.4
Final simplification0.9
herbie shell --seed 2020173
(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))))))