wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \le 3.072499520511824 \cdot 10^{-09}:\\
\;\;\;\;\mathsf{fma}\left(wj, wj, x\right) - x \cdot \left(wj + wj\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{wj}, \sqrt{wj}, -\frac{e^{wj} \cdot wj - x}{e^{wj} \cdot wj + e^{wj}}\right)\\
\end{array}double f(double wj, double x) {
double r11313727 = wj;
double r11313728 = exp(r11313727);
double r11313729 = r11313727 * r11313728;
double r11313730 = x;
double r11313731 = r11313729 - r11313730;
double r11313732 = r11313728 + r11313729;
double r11313733 = r11313731 / r11313732;
double r11313734 = r11313727 - r11313733;
return r11313734;
}
double f(double wj, double x) {
double r11313735 = wj;
double r11313736 = 3.072499520511824e-09;
bool r11313737 = r11313735 <= r11313736;
double r11313738 = x;
double r11313739 = fma(r11313735, r11313735, r11313738);
double r11313740 = r11313735 + r11313735;
double r11313741 = r11313738 * r11313740;
double r11313742 = r11313739 - r11313741;
double r11313743 = sqrt(r11313735);
double r11313744 = exp(r11313735);
double r11313745 = r11313744 * r11313735;
double r11313746 = r11313745 - r11313738;
double r11313747 = r11313745 + r11313744;
double r11313748 = r11313746 / r11313747;
double r11313749 = -r11313748;
double r11313750 = fma(r11313743, r11313743, r11313749);
double r11313751 = r11313737 ? r11313742 : r11313750;
return r11313751;
}




Bits error versus wj




Bits error versus x
| Original | 13.9 |
|---|---|
| Target | 13.2 |
| Herbie | 1.6 |
if wj < 3.072499520511824e-09Initial program 13.6
Taylor expanded around 0 0.8
Simplified0.8
if 3.072499520511824e-09 < wj Initial program 25.1
rmApplied add-sqr-sqrt25.4
Applied fma-neg25.4
Final simplification1.6
herbie shell --seed 2019151 +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))))))