wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \le 8.767711148869109 \cdot 10^{-5}:\\
\;\;\;\;\frac{\frac{x}{wj + 1}}{e^{wj}} + \left(\left({wj}^{4} + {wj}^{2}\right) - {wj}^{3}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{\frac{x}{wj \cdot wj - 1} \cdot \left(wj - 1\right)}{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 <= 8.767711148869109e-05)) {
VAR = ((double) (((double) (((double) (x / ((double) (wj + 1.0)))) / ((double) exp(wj)))) + ((double) (((double) (((double) pow(wj, 4.0)) + ((double) pow(wj, 2.0)))) - ((double) pow(wj, 3.0))))));
} else {
VAR = ((double) (((double) (((double) (((double) (((double) (x / ((double) (((double) (wj * wj)) - 1.0)))) * ((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.8 |
|---|---|
| Target | 13.2 |
| Herbie | 0.3 |
if wj < 8.767711148869109e-5Initial program 13.4
Simplified13.4
rmApplied associate--l+7.2
Taylor expanded around 0 0.3
if 8.767711148869109e-5 < wj Initial program 30.4
Simplified0.7
rmApplied flip-+0.8
Applied associate-/r/0.8
Simplified0.8
Final simplification0.3
herbie shell --seed 2020171
(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))))))