Suppose $T$ is a compact self-adjoint operator on $H$, then $T=\sum_{i=1}^{\infty}\lambda_i P_i$, where each $\lambda_i$ is an eigenvalue of $T$, $P_i$ is a projection from $H$ onto $ker(T-\lambda_i)$.
I want to calculate the commutant of $T$. Does the following relation hold? $T'=\sum_{i=1}^{\infty}(\lambda_i P_i)'$
Besides the non-zero eigenvalues of $T$, let us make sure to include $\lambda_0=0$, and let $P_0$ be the orthonormal projection onto the null space of $T$. Then clearly $$ T = \sum_{i=1}^{\infty}\lambda_i P_i = \sum_{i=0}^{\infty}\lambda_i P_i, $$ and also $$ H = \bigoplus_{i=0}^{\infty}P_i(H). $$
Notice that an operator $S$ commutes with $T$ iff $S$ commutes with every $P_i$: the "if" part is obvious because $T=\sum_{i=1}^{\infty}\lambda_i P_i$, and the "only if" follows from the fact that each $P_i$ may be writen as a limit of polynomials applied to $T$ by the functional calculus (provided the $\lambda _i$'s are distinct).
Thus the commutant of $T$ coincides with the set of all operators leaving each $P_i(H)$ invariant. Viewing these as block-diagonal operators we then have $$ \{T\} ' = \bigoplus_i P_iB(H)P_i. $$