Commuting matrices and centralizer of a maximal toral Lie subalgebra In this old question it is discussed how to generate random commuting Hermitian matrices. The proposed method is the following: generate a random unitary matrix $U\in \operatorname{U}(n)$. Then take diagonal matrices $D_m$ with $d_{kk}=\delta_{mk}$.
The requested commuting Hermitian matrices are:
$$
H_m=U^\dagger \cdot D_m \cdot U.
$$
This is absolutely clear to me. But then, there is this explanation:

This is the maximal [abelian subalgebra]
(http://en.wikipedia.org/wiki/Toral_Lie_algebra)
of the Lie algebra $\mathfrak{ u}(n)$. The centralizer of a maximal toral Lie
subalgebra is called the [Cartan subalgebra]
(http://en.wikipedia.org/wiki/Cartan_subalgebra):


A Cartan subalgebra of the Lie algebra of $n\times n$ matrices over a field is the algebra of
all diagonal matrices.

Is anybody able to understand the meaning of these very concise lines? I can guess that
the set of $H_m$ is a "maximal abelian subalgebra". But then, why does the centralizer comes into play? If the diagonal matrices form the centralizer, I would expect that they commute with all the $H_m$, but this is false.
Although I was not able to understand this text, it seems that the aim is to provide a generalization and a formalization of the method, so I would like to understand it.
 A: The complex Lie algebra of the Lie group of unitary matrices $U(n)=\{U\in \mathbb{M}_n(\mathbb{C)}\,|\,U\cdot U^\dagger =1\}$ are the skew-hermtian matrices $\mathfrak{u}(n)=\{X\in\mathbb{M}_n(\mathbb{C}\,|\,X+X^\dagger=0\}.$ If we add the condition of a trivial trace, then we get the simple Lie algebra $\mathfrak{su}(n)=\{X\in\mathbb{M}_n(\mathbb{C}\,|\,X+X^\dagger=0\wedge \operatorname{trace}(X)=0\}.$ This does not change the structure substantially. The only difference is the center
$$
\mathfrak{Z}(\mathfrak{u}(n))= i \cdot \mathbb{R}\cdot I_n
$$
that does not affect diagonalizability. The maximal toral (= simultaneously diagonalizable) subalgebra and Cartan-subalgebra are equivalent for simple, complex Lie algebras as $\mathfrak{su}(n)$. They are also abelian, self-normalizing, and self-centralizing. We get the maximal toral, abelian, self-centralizing Cartan subalgebra for $\mathfrak{u}(n)$ from the corresponding central extension of the Cartan subalgebra of $\mathfrak{su}(n).$
The situation is more complex over non-algebraically closed fields where we do not automatically have all necessary eigenvalues to perform a simultaneous diagonalization.
A: Several things are not worded in a fortunate way there.
First of all, the answer writes "maximal abelian subalgebras" and links "abelian subalgebra" to an article on "toral subalgebras". Now in general, a maximal abelian subalgebra is not the same as a maximal toral subalgebra. These things are identical only in case our Lie algebra is a compact semisimple or reductive real LA (like $\mathfrak{u}(n)$), so it is sloppy to just mix that terminology there. Cross out "abelian", write "toral".
Next, maximal toral subalgebras are identical to Cartan subalgebras in any semisimple (or even reductive) Lie algebra over any characteristic $0$ field. See https://math.stackexchange.com/a/2497093/96384. So the sentence "The centralizer of a maximal toral subalgebra is called the Cartan subalgebra" is misleading, as there is no need to take a centralizer here. (I mean, technically one can, because in hindsight, these things are also self-centralizing, i.e. they are identical to their own centralizers, but still that is a bad way to express that.)
Speaking of bad expressions, one should also say "a Cartan subalgebra" and not "the Cartan subalgebra". Any nontrivial semisimple Lie algebra has infinitely many such CSA's a.k.a. maximal toral subalgebras.
Next, the quoted fact that the subalgebra of all diagonal matrices forms a (not "the") CSA a.k.a. maximal toral subalgebra in the full matrix algebra $\mathfrak{gl}_n$ is very good to know, but falls short of relevance here.
Some underlying idea here might be: A CSA a.k.a. maximal toral subalgebra of $\mathfrak{u}(n)$ is given by the diagonal matrices inside $\mathfrak{u}(n)$. This subalgebra is abelian, hence everything in there commutes, and it has dimension $n$, so we can even choose $n$ linearly independent such matrices. Finally, if we conjugate a CSA, we get another CSA, so we could also use any such conjugation and get a different set of matrices in our Lie algebra, which are still linearly independent and commute with each other.
Well so far so good. Problem being that where I come from, the Lie algebra $\mathfrak{u}(n)$ consists not of hermitian, but of skew-hermitian matrices; correspondingly, those diagonal matrices in that answer with $1$'s on the diagonal are not even contained in $\mathfrak{u}(n)$. While conversely, the hermitian matrices do not form a Lie algebra.
Probably there is some way to fix those problems, but I would concur that that answer you link to would be better if one just ignores everything after the first line and equation.

Added in hindsight: Maybe the answer there should have just said that those $D_m$ ($m=1, ..., n$), belong to a (maximal) torus in the group $U(n)$. In particular, they all commute with each other. And so if you conjugate all of them with the same element of that group, you get a new set of hermitian matrices which all commute with each other. That's it. Going to the Lie algebra adds little insight, in particular when it's done with all those imprecisions.
A: @DorianoBrogioli "Is it true in general, for any Lie group and related algebra?" - No. You cannot say this in such a generality.
Let us consider the Lie group of unitary matrices U with determinant one and the Lie algebra of skew-hermitian matrices X with trace zero. Then $U^{-1}XU$ defines an operation of $SU(m)$ on $\mathfrak{su}(m).$ The CSA is the maximal subalgebra of diagonalizable matrices: $\mathfrak{h}=\operatorname{span}_\mathbb{R}\{ i (e_{ii}-e_{jj}) \}.$ The center of $\mathfrak{u}(n)$ is $i\cdot \mathbb{R}\cdot I_m.$ It does not have a determinant one anymore. However, it commutes with all other matrices, so we can extend our set of diagonalizable matrices by them and allow
$$
D_m \in \mathcal{D}:=\operatorname{span}_\mathbb{R}\{i (e_{ii}-e_{jj}), i\cdot I_m\}.
$$
As a side note, $\mathcal{D}=\mathfrak{h}\oplus \mathfrak{Z}(\mathfrak{u}(m))$ is the CSA of $\mathfrak{u}(m).$ Let $D\in \mathcal{D}.$ Then
$$
D=i\cdot \left(a_0I_m+ \sum_{i,j}a_{ij}(e_{ii}-e_{jj})\right)
$$
and thus
$$
U^\dagger DU=U^\dagger \left(i\cdot \left(a_0I_m+ \sum_{i,j}a_{ij}(e_{ii}-e_{jj})\right)\right)U=i\cdot \left(a_0I_m+ \sum_{i,j}U^\dagger a_{ij}(e_{ii}-e_{jj})U\right)
$$
The matrices $U^\dagger DU$ are skew-hermitian again:
$$
\left(U^\dagger D U\right)^\dagger = U^\dagger D^\dagger U=-U^\dagger DU
$$
Now, as suggested, we chose a random unitary matrix $U$, a random set $\{a_0,a_{ij}\}$ and compute $H:=U^\dagger DU.$ This will be a random skew-hermitian matrix $H.$ All matrices $H$ are diagonalizable by construction since $U^\dagger =U^{-1}$ and they commute with each other as long as we only change the randomly chosen coefficients $\{a_0,a_{ij}\},$ i.e. only the skew-hermitian diagonal matrix, while we keep the unitary matrix:
$$
[H,H']=[U^\dagger DU, U^\dagger D'U]=U^\dagger[D,D']U=0
$$
Finally, in order to generate a random hermitian matrix, we only have to multiply $H$ by $ i $:
$$
(iH)^\dagger =-i H^\dagger =-i (-H)=i H
$$
My silent switch from special unitary matrices (determinant one) to arbitrary unitary matrices does not play a role because I did it at the time when we left Lie theory and focused only on matrix properties.
