wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \le -8.775235746042734 \cdot 10^{-09}:\\
\;\;\;\;wj - \frac{\left(wj - 1\right) \cdot \frac{e^{wj} \cdot wj - x}{\mathsf{fma}\left(wj, wj, -1\right)}}{e^{wj}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(wj, wj, x\right) - \left(wj + wj\right) \cdot x\\
\end{array}double f(double wj, double x) {
double r6849313 = wj;
double r6849314 = exp(r6849313);
double r6849315 = r6849313 * r6849314;
double r6849316 = x;
double r6849317 = r6849315 - r6849316;
double r6849318 = r6849314 + r6849315;
double r6849319 = r6849317 / r6849318;
double r6849320 = r6849313 - r6849319;
return r6849320;
}
double f(double wj, double x) {
double r6849321 = wj;
double r6849322 = -8.775235746042734e-09;
bool r6849323 = r6849321 <= r6849322;
double r6849324 = 1.0;
double r6849325 = r6849321 - r6849324;
double r6849326 = exp(r6849321);
double r6849327 = r6849326 * r6849321;
double r6849328 = x;
double r6849329 = r6849327 - r6849328;
double r6849330 = -1.0;
double r6849331 = fma(r6849321, r6849321, r6849330);
double r6849332 = r6849329 / r6849331;
double r6849333 = r6849325 * r6849332;
double r6849334 = r6849333 / r6849326;
double r6849335 = r6849321 - r6849334;
double r6849336 = fma(r6849321, r6849321, r6849328);
double r6849337 = r6849321 + r6849321;
double r6849338 = r6849337 * r6849328;
double r6849339 = r6849336 - r6849338;
double r6849340 = r6849323 ? r6849335 : r6849339;
return r6849340;
}




Bits error versus wj




Bits error versus x
| Original | 13.7 |
|---|---|
| Target | 13.0 |
| Herbie | 1.6 |
if wj < -8.775235746042734e-09Initial program 5.8
rmApplied distribute-rgt1-in5.8
Applied associate-/r*5.8
rmApplied flip-+5.9
Applied associate-/r/6.1
Simplified6.1
if -8.775235746042734e-09 < wj Initial program 13.9
Taylor expanded around 0 1.5
Simplified1.5
Final simplification1.6
herbie shell --seed 2019143 +o rules:numerics
(FPCore (wj x)
:name "Jmat.Real.lambertw, newton loop step"
:herbie-target
(- wj (- (/ wj (+ wj 1)) (/ x (+ (exp wj) (* wj (exp wj))))))
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))