Solution (source code)

= Solution

A <reversible Markov chain> has a stationary law $\pi$ for which every finite path has the same distribution as its time-reversed path:
$$
\boxed{(X_0,\ldots,X_k)\overset d=(X_k,\ldots,X_0)\quad\text{for every }k\ge0.}
$$
For a transition matrix $P$, the equivalent <detailed balance> condition is $\pi_iP_{ij}=\pi_jP_{ji}$ for all $i,j$. It implies $\pi P=\pi$ by summing over $i$. Multiplying the balance identities along a path shows equality of its forward and reverse probabilities when $X_0\sim\pi$; conversely, taking paths of length one gives those identities.