Solution (source code)

= Solution

Insert the two observed spins into the configuration sum for the <transfer matrix for a classical spin chain> <trace>. Since the diagonal matrix $\sigma^z$ has entry $s$ on state $s$, multiplication by it at positions $j$ and $j+r$ produces the factor $\sigma_j\sigma_{j+r}$. The <trace> representation is consequently
$$
\boxed{g(r)=\frac1{Z_N}\operatorname{Tr}\!\left[T^{j-1}\sigma^zT^r\sigma^zT^{N+1-j-r}\right].}
$$
There are exactly $N$ transfer factors: $(j-1)+r+(N+1-j-r)=N$. The distance between the two insertions is $r$ bonds, not $r-1$. Cyclicity of the <trace> combines the outside factors and gives the equivalent expression
$$
g(r)=Z_N^{-1}\operatorname{Tr}(\sigma^zT^r\sigma^zT^{N-r}),
$$
which makes independence of the starting site manifest. No assumption that $T$ commutes with $\sigma^z$ is used; in general it does not. For $r=0$ the two insertions multiply to the identity and $g(0)=1$, a useful <normalization> check.