In perturbation theory, one frequently encounters the following summation: \[\begin{equation} S\equiv \sum_m (E_m-E_n)|\langle m|X|n\rangle|^2 \tag{1} \end{equation}\] where \(|m\rangle\) and \(|n\rangle\) are eigenstates of \(H=P^2/2m+V(X)\), and we want to prove that the summation is equal to \(\frac{\hbar^2}{2 m}\).
We first convert \(E_m-E_n\) term into a commutation as follows. \[\begin{equation} (E_m-E_n)\langle m|X|n\rangle=\langle m|[H,X]|n\rangle=\langle m|[\frac{P^2}{2 \mu},X]|n\rangle=\frac{-i}{\mu}\langle m|P|n\rangle\tag{2} \end{equation}\] So we have, \[\begin{eqnarray} S&=&\frac{-i}{\mu}\sum_m\langle m|P|n\rangle\langle n|X|m\rangle=\frac{-i}{m}\langle n|X|\sum_m|m\rangle\langle m|P|n\rangle\nonumber\\ &=&\frac{-i \hbar}{m}\langle n|X P|n\rangle\tag{3} \end{eqnarray}\] Note that \(S\) is manifestly real from its definition, so we can add up its complex conjugate which will simply double it. \[\begin{eqnarray} S &=& \frac{S+S^*}{2}= \frac{-i \hbar}{2m}\langle n|X P|n\rangle+\frac{i \hbar}{2m} \langle n|P X|n\rangle \nonumber\\ &=&\frac{ \hbar^2}{2m}\langle n|[X, P]|n\rangle=\frac{1}{2m} \tag{4} \end{eqnarray}\]
Let’s test the sum rule on the \(n\)th state of the oscillator. For the harmonic oscillator, \[\begin{eqnarray} S&=& w \sum_m (m+1/2-n-1/2)|\langle m|X|n\rangle|^2\nonumber\\ &=&w\sum_m (m-n)\frac{\hbar^2}{2 m w} \left(\sqrt{n+1}\delta_{m,n+1} +\sqrt{n}\delta_{m,n-1}\right)^2\nonumber\\ &=&\frac{\hbar^2}{2 m}(n+1-n)=\frac{\hbar^2}{2 m}, \tag{5} \end{eqnarray}\] which agrees with the sum rule.