wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\begin{array}{l}
t_0 := \frac{x}{e^{wj}} - wj\\
\mathbf{if}\;wj \leq -1.3031958808623259 \cdot 10^{-6}:\\
\;\;\;\;wj + t_0 \cdot \frac{1}{wj + 1}\\
\mathbf{elif}\;wj \leq 7.73535415808421 \cdot 10^{-12}:\\
\;\;\;\;\mathsf{fma}\left(wj, wj, x\right) + x \cdot \left(wj \cdot \mathsf{fma}\left(2.5, wj, -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;wj + \frac{t_0}{wj + 1}\\
\end{array}
(FPCore (wj x) :precision binary64 (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))
(FPCore (wj x)
:precision binary64
(let* ((t_0 (- (/ x (exp wj)) wj)))
(if (<= wj -1.3031958808623259e-6)
(+ wj (* t_0 (/ 1.0 (+ wj 1.0))))
(if (<= wj 7.73535415808421e-12)
(+ (fma wj wj x) (* x (* wj (fma 2.5 wj -2.0))))
(+ wj (/ t_0 (+ wj 1.0)))))))double code(double wj, double x) {
return wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj))));
}
double code(double wj, double x) {
double t_0 = (x / exp(wj)) - wj;
double tmp;
if (wj <= -1.3031958808623259e-6) {
tmp = wj + (t_0 * (1.0 / (wj + 1.0)));
} else if (wj <= 7.73535415808421e-12) {
tmp = fma(wj, wj, x) + (x * (wj * fma(2.5, wj, -2.0)));
} else {
tmp = wj + (t_0 / (wj + 1.0));
}
return tmp;
}




Bits error versus wj




Bits error versus x
| Original | 14.4 |
|---|---|
| Target | 13.7 |
| Herbie | 0.4 |
if wj < -1.30319588086232587e-6Initial program 29.3
Simplified1.9
Applied div-inv_binary642.1
if -1.30319588086232587e-6 < wj < 7.7353541580842095e-12Initial program 13.6
Simplified13.6
Taylor expanded in wj around 0 0.2
Simplified0.2
Taylor expanded in wj around 0 0.2
Simplified0.2
if 7.7353541580842095e-12 < wj Initial program 27.5
Simplified5.2
Final simplification0.4
herbie shell --seed 2022067
(FPCore (wj x)
:name "Jmat.Real.lambertw, newton loop step"
:precision binary64
:herbie-target
(- wj (- (/ wj (+ wj 1.0)) (/ x (+ (exp wj) (* wj (exp wj))))))
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))