wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \le 2.1610528876044702 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(wj, wj - x \cdot 2, 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 r249830 = wj;
double r249831 = exp(r249830);
double r249832 = r249830 * r249831;
double r249833 = x;
double r249834 = r249832 - r249833;
double r249835 = r249831 + r249832;
double r249836 = r249834 / r249835;
double r249837 = r249830 - r249836;
return r249837;
}
double f(double wj, double x) {
double r249838 = wj;
double r249839 = 2.1610528876044702e-05;
bool r249840 = r249838 <= r249839;
double r249841 = x;
double r249842 = 2.0;
double r249843 = r249841 * r249842;
double r249844 = r249838 - r249843;
double r249845 = fma(r249838, r249844, r249841);
double r249846 = 1.0;
double r249847 = r249838 + r249846;
double r249848 = r249841 / r249847;
double r249849 = exp(r249838);
double r249850 = r249848 / r249849;
double r249851 = r249850 + r249838;
double r249852 = r249851 * r249851;
double r249853 = r249838 / r249847;
double r249854 = r249853 * r249853;
double r249855 = r249852 - r249854;
double r249856 = r249851 + r249853;
double r249857 = r249855 / r249856;
double r249858 = r249840 ? r249845 : r249857;
return r249858;
}




Bits error versus wj




Bits error versus x
| Original | 14.0 |
|---|---|
| Target | 13.4 |
| Herbie | 1.2 |
if wj < 2.1610528876044702e-05Initial program 13.7
Simplified13.7
Taylor expanded around 0 0.9
Taylor expanded around 0 0.9
Simplified1.0
if 2.1610528876044702e-05 < wj Initial program 27.8
Simplified1.6
rmApplied flip--9.9
Final simplification1.2
herbie shell --seed 2020020 +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))))))