wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\begin{array}{l}
\mathbf{if}\;\begin{array}{l}
t_0 := wj \cdot e^{wj}\\
wj - \frac{t_0 - x}{e^{wj} + t_0} \leq 9.406397361605653 \cdot 10^{-16}
\end{array}:\\
\;\;\;\;x \cdot \frac{e^{-wj}}{wj + 1} + \left(\left({wj}^{4} + {wj}^{2}\right) - {wj}^{3}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(wj + \frac{x}{e^{wj} \cdot \left(wj + 1\right)}\right) - \frac{wj}{wj + 1}\\
\end{array}
(FPCore (wj x) :precision binary64 (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))
(FPCore (wj x)
:precision binary64
(if (let* ((t_0 (* wj (exp wj))))
(<= (- wj (/ (- t_0 x) (+ (exp wj) t_0))) 9.406397361605653e-16))
(+
(* x (/ (exp (- wj)) (+ wj 1.0)))
(- (+ (pow wj 4.0) (pow wj 2.0)) (pow wj 3.0)))
(- (+ wj (/ x (* (exp wj) (+ wj 1.0)))) (/ wj (+ 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 = wj * exp(wj);
double tmp;
if ((wj - ((t_0 - x) / (exp(wj) + t_0))) <= 9.406397361605653e-16) {
tmp = (x * (exp(-wj) / (wj + 1.0))) + ((pow(wj, 4.0) + pow(wj, 2.0)) - pow(wj, 3.0));
} else {
tmp = (wj + (x / (exp(wj) * (wj + 1.0)))) - (wj / (wj + 1.0));
}
return tmp;
}




Bits error versus wj




Bits error versus x
Results
| Original | 14.1 |
|---|---|
| Target | 13.4 |
| Herbie | 0.2 |
if (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) < 9.406397362e-16Initial program 18.6
Simplified18.6
Applied *-un-lft-identity_binary6418.6
Applied *-un-lft-identity_binary6418.6
Applied distribute-lft-out_binary6418.6
Simplified9.4
Taylor expanded in wj around 0 0.2
Applied div-inv_binary640.2
Simplified0.2
if 9.406397362e-16 < (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) Initial program 2.6
Simplified0.3
Taylor expanded in x around 0 0.3
Final simplification0.2
herbie shell --seed 2022055
(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))))))