Discounted gambler's ruin hitting probability (source code)

= Discounted gambler's ruin hitting probability
{title2=$u_k=\mathbb E_k[s^\tau\mathbf1_{\{X_\tau=0\}}]$}

For a nearest-neighbour <random walk> on $\{0,\ldots,N\}$ with right-step probability $p$, left-step probability $q=1-p$, and absorption time $\tau$, first-step conditioning gives $u_k=s(pu_{k+1}+qu_{k-1})$, $u_0=1$, $u_N=0$. For $0<s<1$, the two positive distinct characteristic roots are $r_\pm=(1\pm\sqrt{1-4pqs^2})/(2ps)$. Solving the boundary equations gives $u_k=(r_+^Nr_-^k-r_-^Nr_+^k)/(r_+^N-r_-^N)$. The maximum principle $\|u-v\|_\infty\leq s\|u-v\|_\infty$ proves uniqueness for equal boundary data. This is the joint generating function of the absorption time and the lower-end absorption event.