Prove that if $TS = ST$, then there exists a polynomial $p$ for which $S = p(T)$. I have that if $V$ is $n$-dimensional and ${S,T} \in \mathcal{L}(V)$ where $S$ can be written as $p(T)$ for some polynomial $p$, then $TS = ST$. I understand that the converse of this isn't always true, but I want to show that it holds for when $T$ has $n$ distinct eigenvalues.
Essentially, I want to prove that if $S \in \mathcal{L}(V)$ is such that $TS = ST$, then there exists a polynomial $p$ for which $S = p(T)$.
I was thinking of starting by letting $v_1, ..., v_n$ be a basis of $V$ consisting of eigenvectors of $T$ and then showing that each $v_i$ is also an eigenvector of $S$, but I'm not sure how to carry this out.
I've seen a lot of similar-looking proofs discussing diagonalization with commutable operators, but I'm having trouble drawing the connection to this.
 A: Here's an idea that works when $T$ is diagonalisable with distinct eigenvalues, as specified in your opening paragraph.
I'll assume that you know how to show that $S$ and $T$ are simultaneously diagonalisable; if not, then see here or any other math.SE post on that matter.
So the fact that $S$ and $T$ are simultaneously diagonalisable means that there exists a basis in which $S$ and $T$ can be written in the form
$$ S = \begin{bmatrix} \mu_1 & 0 & 0\\ 0 & \mu_2 & 0 \\ 0 & 0 & \mu_3\end{bmatrix}, \ \ \ \ T = \begin{bmatrix} \lambda_1 & 0 & 0\\ 0 & \lambda_2 & 0 \\ 0 & 0 & \lambda_3\end{bmatrix}. $$
(I'm doing the $3\times 3$ case to keep the notation simple.)
Since we're assuming that $T$ has distinct eigenvalues, $\lambda_1, \lambda_2, \lambda_3$ are distinct by assumption.
Now we can find polynomials in $T$ that project onto the individual eigenspaces.
For example
$$ p_1(T) := \tfrac{1}{(\lambda_1 - \lambda_2)(\lambda_1 - \lambda_3)} (T - \lambda_2 I)(T - \lambda_3I) =\begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{bmatrix},$$
$$ p_2(T) := \tfrac{1}{(\lambda_2 - \lambda_3)(\lambda_2 - \lambda_1)} (T - \lambda_3 I)(T - \lambda_1I) =\begin{bmatrix} 0 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 0 \end{bmatrix},$$
$$ p_3(T) := \tfrac{1}{(\lambda_3 - \lambda_1)(\lambda_3 - \lambda_2)} (T - \lambda_1 I)(T - \lambda_2I) =\begin{bmatrix} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 1 \end{bmatrix}.$$
Then we can assemble $S$ by taking a linear combination of these projection operators:
$$ S = \mu_1 p_1(T) + \mu_2 p_2(T) + \mu_3 p_3(T).$$
