Solution (source code)

= Solution

For the off-diagonal moves, the <Metropolis–Hastings acceptance probability> gives
$$
\pi(x)q(y\mid x)\alpha(x,y)
=\min\{\pi(x)q(y\mid x),\pi(y)q(x\mid y)\}.
$$
This expression is unchanged by interchanging $x$ and $y$. The rejected-move measure $\pi(dx)r(x)\delta_x(dy)$ is supported on the diagonal and is also symmetric. Therefore the whole transition measure satisfies
$$
\boxed{\pi(dx)K(x,dy)=\pi(dy)K(y,dx),}
$$
which proves <detailed balance>, including the atom that an off-diagonal density alone would omit. Consequently the <Metropolis–Hastings algorithm> kernel preserves the normalized target measure.