Commutant

Commutant is a function that computes an orthonormal basis (in the Hilbert-Schmidt inner product) of the commutant of a matrix or set of matrices.

Syntax

 * C = Commutant(A)

Argument descriptions

 * A: Either a matrix, or a cell containing one or more matrices of the same size.

A single matrix
Everything commutes with the identity matrix, which we can verify in the 2-dimensional case as follows:

Bicommutant
If A is a cell that contains a basis of a unital, self-adjoint algebra, then its bicommutant spans the same set, by the von Neumann bicommutant theorem. The following code verifies this in the case of the subalgebra $M_2 \oplus M_1 \subseteq M_3$: Note that the basis output for the bicommutant in general may be different than the basis provided as input.