For the harmonic-oscillator number-state second moments, the number operator gives , while the canonical commutation relation gives . Terms with or have zero diagonal matrix elements, since they change the occupation number by two. Therefore
Consequently the potential energy and kinetic energy means are
Their sum is the oscillator energy eigenvalue . Their equality is also the virial theorem result for a quadratic potential, here derived directly from the ladder operators.