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




Bits error versus wj




Bits error versus x
Results
| Original | 13.8 |
|---|---|
| Target | 13.2 |
| Herbie | 1.2 |
if wj < 1.397615986833905e-07Initial program 13.5
Simplified13.5
Taylor expanded around 0 0.9
if 1.397615986833905e-07 < wj Initial program 27.0
Simplified2.6
rmApplied flip-+11.6
Applied frac-sub11.7
Final simplification1.2
herbie shell --seed 2020053 +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))))))