wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \le 7.377123706691067175607606942237539690999 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(wj, wj, {wj}^{4}\right)}, \sqrt{\mathsf{fma}\left(wj, wj, {wj}^{4}\right)}, -{wj}^{3}\right) + \frac{\frac{x}{e^{wj}}}{1 + wj}\\
\mathbf{else}:\\
\;\;\;\;\left(wj - \frac{wj}{1 + wj}\right) + \frac{x}{\left(wj + 1\right) \cdot e^{wj}}\\
\end{array}double f(double wj, double x) {
double r119943 = wj;
double r119944 = exp(r119943);
double r119945 = r119943 * r119944;
double r119946 = x;
double r119947 = r119945 - r119946;
double r119948 = r119944 + r119945;
double r119949 = r119947 / r119948;
double r119950 = r119943 - r119949;
return r119950;
}
double f(double wj, double x) {
double r119951 = wj;
double r119952 = 7.377123706691067e-20;
bool r119953 = r119951 <= r119952;
double r119954 = 4.0;
double r119955 = pow(r119951, r119954);
double r119956 = fma(r119951, r119951, r119955);
double r119957 = sqrt(r119956);
double r119958 = 3.0;
double r119959 = pow(r119951, r119958);
double r119960 = -r119959;
double r119961 = fma(r119957, r119957, r119960);
double r119962 = x;
double r119963 = exp(r119951);
double r119964 = r119962 / r119963;
double r119965 = 1.0;
double r119966 = r119965 + r119951;
double r119967 = r119964 / r119966;
double r119968 = r119961 + r119967;
double r119969 = r119951 / r119966;
double r119970 = r119951 - r119969;
double r119971 = r119951 + r119965;
double r119972 = r119971 * r119963;
double r119973 = r119962 / r119972;
double r119974 = r119970 + r119973;
double r119975 = r119953 ? r119968 : r119974;
return r119975;
}




Bits error versus wj




Bits error versus x
| Original | 13.7 |
|---|---|
| Target | 13.0 |
| Herbie | 0.8 |
if wj < 7.377123706691067e-20Initial program 13.2
Simplified13.2
rmApplied div-sub13.2
Applied associate--r-6.7
Taylor expanded around 0 0.3
Simplified0.3
rmApplied add-sqr-sqrt0.3
Applied fma-neg0.3
if 7.377123706691067e-20 < wj Initial program 23.8
Simplified10.1
rmApplied div-sub10.1
Applied associate--r-10.1
rmApplied div-inv10.1
Applied associate-/l*10.1
Simplified10.1
Final simplification0.8
herbie shell --seed 2019347 +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))))))