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.233670756457821 \cdot 10^{-18}:\\
\;\;\;\;x + wj \cdot \left(wj + x \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;wj + \frac{1}{\sqrt{wj + 1}} \cdot \frac{\frac{x}{e^{wj}} - wj}{\sqrt{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.233670756457821e-18)
(+ x (* wj (+ wj (* x -2.0))))
(+
wj
(*
(/ 1.0 (sqrt (+ wj 1.0)))
(/ (- (/ x (exp wj)) wj) (sqrt (+ 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.233670756457821e-18) {
tmp = x + (wj * (wj + (x * -2.0)));
} else {
tmp = wj + ((1.0 / sqrt(wj + 1.0)) * (((x / exp(wj)) - wj) / sqrt(wj + 1.0)));
}
return tmp;
}




Bits error versus wj




Bits error versus x
Results
| Original | 13.9 |
|---|---|
| Target | 13.2 |
| Herbie | 0.9 |
if (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) < 2.23367076e-18Initial program 18.3
Simplified18.3
Taylor expanded around 0 0.8
Simplified0.8
if 2.23367076e-18 < (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) Initial program 3.1
Simplified0.7
rmApplied add-sqr-sqrt_binary64_31691.0
Applied *-un-lft-identity_binary64_31471.0
Applied times-frac_binary64_31531.0
Final simplification0.9
herbie shell --seed 2020346
(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))))))