wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \leq 2.70938624467473 \cdot 10^{-12}:\\
\;\;\;\;x + \left(\left(x \cdot 2.5 + 1\right) \cdot \left(wj \cdot wj\right) - \left({wj}^{3} + x \cdot \left(\left(wj + wj\right) + {wj}^{3} \cdot 2.6666666666666665\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\
\end{array}(FPCore (wj x) :precision binary64 (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))
(FPCore (wj x)
:precision binary64
(if (<=
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))
2.70938624467473e-12)
(+
x
(-
(* (+ (* x 2.5) 1.0) (* wj wj))
(+ (pow wj 3.0) (* x (+ (+ wj wj) (* (pow wj 3.0) 2.6666666666666665))))))
(+ wj (/ (- (/ x (exp wj)) wj) (+ wj 1.0)))))double code(double wj, double x) {
return wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj))));
}
double code(double wj, double x) {
double tmp;
if ((wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj))))) <= 2.70938624467473e-12) {
tmp = x + ((((x * 2.5) + 1.0) * (wj * wj)) - (pow(wj, 3.0) + (x * ((wj + wj) + (pow(wj, 3.0) * 2.6666666666666665)))));
} else {
tmp = wj + (((x / exp(wj)) - wj) / (wj + 1.0));
}
return tmp;
}




Bits error versus wj




Bits error versus x
Results
| Original | 13.5 |
|---|---|
| Target | 12.9 |
| Herbie | 0.4 |
if (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) < 2.70938624467e-12Initial program 17.9
Simplified17.9
Taylor expanded around 0 0.5
Simplified0.5
if 2.70938624467e-12 < (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) Initial program 2.4
Simplified0.3
Final simplification0.4
herbie shell --seed 2021098
(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))))))