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 9.135447308520993 \cdot 10^{-21}:\\
\;\;\;\;x + wj \cdot \left(wj + x \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{1 + {wj}^{3}} \cdot \left(wj \cdot wj + \left(1 - wj\right)\right)\\
\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)))))
9.135447308520993e-21)
(+ x (* wj (+ wj (* x -2.0))))
(+
wj
(*
(/ (- (/ x (exp wj)) wj) (+ 1.0 (pow wj 3.0)))
(+ (* wj wj) (- 1.0 wj))))))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))))) <= 9.135447308520993e-21) {
tmp = x + (wj * (wj + (x * -2.0)));
} else {
tmp = wj + ((((x / exp(wj)) - wj) / (1.0 + pow(wj, 3.0))) * ((wj * wj) + (1.0 - wj)));
}
return tmp;
}




Bits error versus wj




Bits error versus x
Results
| Original | 13.4 |
|---|---|
| Target | 12.9 |
| Herbie | 0.8 |
if (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) < 9.1354473e-21Initial program 18.1
Simplified18.1
Taylor expanded around 0 0.8
Simplified0.8
if 9.1354473e-21 < (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) Initial program 2.5
Simplified0.9
rmApplied flip3-+_binary64_34910.9
Applied associate-/r/_binary64_34340.9
Simplified0.9
Final simplification0.8
herbie shell --seed 2020358
(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))))))