Accept-or-fallback mixture identity (source code)

= Accept-or-fallback mixture identity
{title2=$\mathbb P(X=x)=p_xa_x+\sum_y p_y(1-a_y)K(y,x)$}

Let a <discrete random variable> $Y$ have <probability mass function> $p_y$. Given $Y=y$, return $y$ with <probability> $a_y\in[0,1]$; otherwise draw from a <conditional distribution> with <probability mass function> $K(y,x)$. The <law of total probability> gives the displayed identity. Its total mass is $\sum_yp_y[a_y+(1-a_y)\sum_xK(y,x)]=1$. If the fallback is a <discrete uniform distribution> on $0,\ldots,y$, then $K(y,x)=\mathbf1_{\{0\leq x\leq y\}}/(y+1)$, so the fallback sum includes $y=x$.