wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \le 5.801891356124452416919000006471224262228 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(wj \cdot x, -2, \mathsf{fma}\left(wj, wj, x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(wj - 1, \frac{wj - \frac{x}{e^{wj}}}{\mathsf{fma}\left(wj, -wj, 1\right)}, wj\right) + \frac{wj - \frac{x}{e^{wj}}}{\mathsf{fma}\left(wj, -wj, 1\right)} \cdot \left(\left(wj - 1\right) + \left(1 - wj\right)\right)\\
\end{array}double f(double wj, double x) {
double r259661 = wj;
double r259662 = exp(r259661);
double r259663 = r259661 * r259662;
double r259664 = x;
double r259665 = r259663 - r259664;
double r259666 = r259662 + r259663;
double r259667 = r259665 / r259666;
double r259668 = r259661 - r259667;
return r259668;
}
double f(double wj, double x) {
double r259669 = wj;
double r259670 = 5.8018913561244524e-09;
bool r259671 = r259669 <= r259670;
double r259672 = x;
double r259673 = r259669 * r259672;
double r259674 = -2.0;
double r259675 = fma(r259669, r259669, r259672);
double r259676 = fma(r259673, r259674, r259675);
double r259677 = 1.0;
double r259678 = r259669 - r259677;
double r259679 = exp(r259669);
double r259680 = r259672 / r259679;
double r259681 = r259669 - r259680;
double r259682 = -r259669;
double r259683 = fma(r259669, r259682, r259677);
double r259684 = r259681 / r259683;
double r259685 = fma(r259678, r259684, r259669);
double r259686 = r259677 - r259669;
double r259687 = r259678 + r259686;
double r259688 = r259684 * r259687;
double r259689 = r259685 + r259688;
double r259690 = r259671 ? r259676 : r259689;
return r259690;
}




Bits error versus wj




Bits error versus x
| Original | 14.0 |
|---|---|
| Target | 13.4 |
| Herbie | 0.9 |
if wj < 5.8018913561244524e-09Initial program 13.6
Simplified13.6
Taylor expanded around 0 0.8
Simplified0.8
if 5.8018913561244524e-09 < wj Initial program 26.5
Simplified3.9
rmApplied flip-+4.1
Applied associate-/r/4.0
Applied add-sqr-sqrt4.4
Applied prod-diff4.3
Simplified3.8
Simplified3.8
Final simplification0.9
herbie shell --seed 2019326 +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))))))