wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\begin{array}{l}
t_0 := wj \cdot e^{wj}\\
t_1 := e^{wj} + t_0\\
\mathbf{if}\;wj - \frac{t_0 - x}{t_1} \leq 9.647393852269467 \cdot 10^{-16}:\\
\;\;\;\;\left(\mathsf{fma}\left(wj, wj, x\right) + x \cdot \mathsf{fma}\left(wj, \mathsf{fma}\left(2.5, wj, -2\right), {wj}^{3} \cdot -2.6666666666666665\right)\right) - {wj}^{3}\\
\mathbf{else}:\\
\;\;\;\;\left(wj - \frac{wj}{wj + 1}\right) + \frac{x}{t_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 (* wj (exp wj))) (t_1 (+ (exp wj) t_0)))
(if (<= (- wj (/ (- t_0 x) t_1)) 9.647393852269467e-16)
(-
(+
(fma wj wj x)
(* x (fma wj (fma 2.5 wj -2.0) (* (pow wj 3.0) -2.6666666666666665))))
(pow wj 3.0))
(+ (- wj (/ wj (+ wj 1.0))) (/ x t_1)))))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 = wj * exp(wj);
double t_1 = exp(wj) + t_0;
double tmp;
if ((wj - ((t_0 - x) / t_1)) <= 9.647393852269467e-16) {
tmp = (fma(wj, wj, x) + (x * fma(wj, fma(2.5, wj, -2.0), (pow(wj, 3.0) * -2.6666666666666665)))) - pow(wj, 3.0);
} else {
tmp = (wj - (wj / (wj + 1.0))) + (x / t_1);
}
return tmp;
}




Bits error versus wj




Bits error versus x
| Original | 13.7 |
|---|---|
| Target | 13.0 |
| Herbie | 0.5 |
if (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) < 9.647393852e-16Initial program 17.9
Simplified17.9
Taylor expanded in wj around 0 0.4
Simplified0.4
Applied fma-udef_binary640.4
Applied associate--r+_binary640.4
Simplified0.4
if 9.647393852e-16 < (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) Initial program 3.2
Applied div-sub_binary643.2
Applied associate--r-_binary643.2
Simplified0.6
Final simplification0.5
herbie shell --seed 2021280
(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))))))