Solution (source code)

= Solution

$V^*$ is the space of linear functionals and the dual <basis> satisfies $v_i^*(v_j)=\delta_{ij}$. Nondegeneracy and equal finite dimensions make $u\mapsto\langle u,\cdot\rangle$ an isomorphism; evaluation similarly identifies $V$ with $V^{**}$. Riesz representation applied to $v\mapsto\langle Tv,u\rangle$ gives the unique adjoint. If $T$ is diagonalizable, declare an eigenbasis orthonormal to make it self-adjoint. Conversely, for self-adjoint $T$ and invariant $W$, $\langle Tv,w\rangle=\langle v,Tw\rangle=0$ shows $W^\perp$ invariant.