wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \le 1.0018755083909558 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(wj, wj, x\right) - 2 \cdot \left(wj \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) \cdot \left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) - \frac{wj}{wj + 1} \cdot \frac{wj}{wj + 1}}{\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) + \frac{wj}{wj + 1}}\\
\end{array}double f(double wj, double x) {
double r220693 = wj;
double r220694 = exp(r220693);
double r220695 = r220693 * r220694;
double r220696 = x;
double r220697 = r220695 - r220696;
double r220698 = r220694 + r220695;
double r220699 = r220697 / r220698;
double r220700 = r220693 - r220699;
return r220700;
}
double f(double wj, double x) {
double r220701 = wj;
double r220702 = 1.0018755083909558e-09;
bool r220703 = r220701 <= r220702;
double r220704 = x;
double r220705 = fma(r220701, r220701, r220704);
double r220706 = 2.0;
double r220707 = r220701 * r220704;
double r220708 = r220706 * r220707;
double r220709 = r220705 - r220708;
double r220710 = 1.0;
double r220711 = r220701 + r220710;
double r220712 = r220704 / r220711;
double r220713 = exp(r220701);
double r220714 = r220712 / r220713;
double r220715 = r220714 + r220701;
double r220716 = r220715 * r220715;
double r220717 = r220701 / r220711;
double r220718 = r220717 * r220717;
double r220719 = r220716 - r220718;
double r220720 = r220715 + r220717;
double r220721 = r220719 / r220720;
double r220722 = r220703 ? r220709 : r220721;
return r220722;
}




Bits error versus wj




Bits error versus x
| Original | 13.7 |
|---|---|
| Target | 13.1 |
| Herbie | 1.2 |
if wj < 1.0018755083909558e-09Initial program 13.4
Simplified13.4
Taylor expanded around 0 0.9
Taylor expanded around 0 0.9
Simplified0.9
if 1.0018755083909558e-09 < wj Initial program 25.7
Simplified2.8
rmApplied flip--11.3
Final simplification1.2
herbie shell --seed 2020049 +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))))))