The dimension of the kernel of $X \to AX-XA$ is the sum of the squares of the multiplicities of the eigenvalues of $A$ Let $A$ be a diagonalizable matrix and let $F$ be this application
$$F:M(n,\mathbb{R})\to M(n,\mathbb{R})$$
$$F(X)=AX-XA$$
Prove that the dimension of the kernel of F is the sum of the multiplicities of the eigenvalues of A.
First I tried to find a comfortable basis to write a good associated matrix, but I didn't find anything, then I saw that if B is a matrix that diagonalizes A ($B^{-1}AB=D$) then a generic X in the kernel satisfy
$$B^{-1}XBD=DB^{-1}XB$$
How can I proceed?

Let $E_{ij}$ be the elementary matrix whose only nonzero entry is in the $i$th row and $j$th column.

Lemma: Let $D \in Mat_n (\mathbb{R})$ be a diagonal matrix. Then $[ D, E_{ij} ] = 0 \iff D_{ii} = D_{jj}$.
Proof: $D E_{ij} = D_{ii} E_{ij}$ and $D E_{ij} = D_{jj} E_{ij}$.

Lemma: for a diagonal matrix $D \in Mat_n (\mathbb{R})$ define the $\mathbb{R}$-linear map $\Phi : Mat_n (\mathbb{R}) \rightarrow Mat_n (\mathbb{R})$ by sending $X$ to $[D, X]$. The kernel has basis $\{ E_{ij} | D_{ii} = D_{jj} \}$, the length of which is clearly $\sum_{\lambda \in \Lambda } \mu (\lambda)^2$ where $\Lambda$ is the set of eigenvalues and $\mu$ is the multiplicity of each eigenvalue.

Reduction from the case of diagonalizable matrices to the case of diagonal matrices: Take a diagonalizable matrix $M \in Mat_n (\mathbb{R} )$ with $A^{-1} M A = D$ for an invertible matrix $A$ and a diagonal matrix $D$. Then $\alpha_A: Mat_n (\mathbb{R}) \rightarrow Mat_n (\mathbb{R})$ where $X \mapsto A^{-1} X A$ is an isomorphism. As before, define an $\mathbb{R}$-linear map $\Phi : Mat_n (\mathbb{R}) \rightarrow Mat_n (\mathbb{R})$ by sending $X$ to $[M, X]$. Define an $\mathbb{R}$-linear map $\Psi : Mat_n (\mathbb{R}) \rightarrow Mat_n (\mathbb{R})$ by sending $X$ to $[D, X]$. $\Phi \circ \alpha_A = \alpha_A \circ \Psi$. We can conclude that $ker(\Phi) \cong ker(\Psi)$ as $\mathbb{R}$-vector spaces, so that their dimension is the same.
The claim therefore follows from the lemmas above. More detail upon request.
