Solution (source code)

= Solution

Let $\pi$ denote the posterior and let the proposal density satisfy $q(\theta'\mid\theta)=q(\theta\mid\theta')$. For distinct states, the Metropolis transition density is
$$
P(\theta,\theta')=q(\theta'\mid\theta)
\min\{1,\pi(\theta')/\pi(\theta)\}.
$$
Consequently
$$
\pi(\theta)P(\theta,\theta')
=q(\theta'\mid\theta)\min\{\pi(\theta),\pi(\theta')\}
=\pi(\theta')P(\theta',\theta).
$$
The rejection mass on the diagonal also satisfies <detailed balance>, so the posterior is invariant.