Stationary position of a transposed distinguished book (source code)

= Stationary position of a transposed distinguished book
{title2=$\pi_i\propto\left(\frac{1-p}{p(N-1)}\right)^{i-1}$}

Place $N\geq2$ books in a row and distinguish one of them. At each step select the distinguished book with <Probability> $p\in(0,1)$ and each of the other $N-1$ books with <Probability> $q=(1-p)/(N-1)$. Swap the selected book with its left neighbour; selecting the leftmost book leaves the ordering unchanged.

The distinguished book's position $I\in\{1,\ldots,N\}$ is a <birth-death chain>. From an interior position it moves left with <Probability> $p$, moves right with <Probability> $q$ when the book immediately to its right is selected, and otherwise holds. Missing outward moves at the endpoints become <holding probability of a Markov chain>[holding]. <Detailed balance> therefore gives $\pi_ip=\pi_{i-1}q$ for $i\geq2$. With $r=q/p$,
$$
\pi_i=\begin{cases}
(1-r)r^{i-1}/(1-r^N),&r\ne1,\\
1/N,&r=1.
\end{cases}
$$
This finite <Truncated geometric distribution> is valid even when $r>1$: both numerator and denominator then have the same negative sign. The uniform case is $p=q=1/N$, when every book is selected equally often. Large selection <Probability> for the distinguished book biases it toward the left end. The strict range of $p$ ensures positive motion in both directions and avoids division by zero in the ratio.