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




Bits error versus wj




Bits error versus x
Results
| Original | 13.1 |
|---|---|
| Target | 12.5 |
| Herbie | 0.4 |
if wj < -6.0987596589411748e-9Initial program 5.4
if -6.0987596589411748e-9 < wj < 5.27181032987001212e-9Initial program 13.0
Simplified13.0
Taylor expanded around 0 0.2
if 5.27181032987001212e-9 < wj Initial program 23.8
Simplified2.9
rmApplied *-un-lft-identity2.9
Applied div-inv2.9
Applied times-frac2.9
Simplified2.9
Final simplification0.4
herbie shell --seed 2020163
(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))))))