wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \le 1.372239400346965385374027503503547198611 \cdot 10^{-12}:\\
\;\;\;\;\mathsf{fma}\left(wj, wj, x\right) - 2 \cdot \left(wj \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(wj - \frac{wj - e^{-wj} \cdot x}{1 + {wj}^{3}}\right) - \frac{wj - e^{-wj} \cdot x}{1 + {wj}^{3}} \cdot \left(wj \cdot wj - wj\right)\\
\end{array}double f(double wj, double x) {
double r127211 = wj;
double r127212 = exp(r127211);
double r127213 = r127211 * r127212;
double r127214 = x;
double r127215 = r127213 - r127214;
double r127216 = r127212 + r127213;
double r127217 = r127215 / r127216;
double r127218 = r127211 - r127217;
return r127218;
}
double f(double wj, double x) {
double r127219 = wj;
double r127220 = 1.3722394003469654e-12;
bool r127221 = r127219 <= r127220;
double r127222 = x;
double r127223 = fma(r127219, r127219, r127222);
double r127224 = 2.0;
double r127225 = r127219 * r127222;
double r127226 = r127224 * r127225;
double r127227 = r127223 - r127226;
double r127228 = -r127219;
double r127229 = exp(r127228);
double r127230 = r127229 * r127222;
double r127231 = r127219 - r127230;
double r127232 = 1.0;
double r127233 = 3.0;
double r127234 = pow(r127219, r127233);
double r127235 = r127232 + r127234;
double r127236 = r127231 / r127235;
double r127237 = r127219 - r127236;
double r127238 = r127219 * r127219;
double r127239 = r127238 - r127219;
double r127240 = r127236 * r127239;
double r127241 = r127237 - r127240;
double r127242 = r127221 ? r127227 : r127241;
return r127242;
}




Bits error versus wj




Bits error versus x
| Original | 13.6 |
|---|---|
| Target | 13.1 |
| Herbie | 1.0 |
if wj < 1.3722394003469654e-12Initial program 13.3
Simplified13.3
Taylor expanded around 0 0.9
Simplified0.9
if 1.3722394003469654e-12 < wj Initial program 23.0
Simplified5.5
rmApplied div-inv5.5
Simplified5.4
rmApplied flip3-+5.5
Applied associate-/r/5.4
Simplified5.4
rmApplied distribute-rgt-in5.4
Applied associate--r+1.7
Simplified1.7
Final simplification1.0
herbie shell --seed 2019208 +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))))))