Counting centralizers of a matrix over a finite field with a particular minimal polynomial I am counting the centralizers of a matrix over $\mathbb{F}_5$ with minimal polynomial $x^3-1$. In rational form it is
$A=\begin{pmatrix}
 0 & 0 & 1 \\\
 1 & 0 & 0 \\\
 0 & 1 & 0
\end{pmatrix}$.
I used a cumbersome way, using the fact that the matrix that commutes with $A$ must have the form
$B=\begin{pmatrix}
 b & c & a \\\
 a & b & c \\\
 c & a & b
\end{pmatrix}$, where
the determinant is a symmetric polynomial, so I got 29 choices of $a, b$ and $c$ giving a $0$ determinant and $125-29 = 96$ possible matrices. I got the feedback
"The centralizer is the ring $\mathbb{F}_5[x]/(x^3-1)$ which is the product of a field of 25 elements with a field of 5 elements so has $24 \times 4 =96$ invertible elements" and would like to understand how this is true. Also is it possible for the statement to be extended to a general case for any matrix with a particular minimal polynomial $p(x)$?
 A: For $A\in M_n(k)$, the easy case is when the minimal polynomial $m\in k[x]$ of $A$ has degree $n$, ie. when there is some $v\in k^n$ such that $v,Av,A^2v,\ldots,A^{n-1}v$ is a basis of $k^n$.

*

*If $BA=AB$ then write $Bv=\sum_{j=0}^{n-1} c_j A^j v=f(A)v$ with $f\in k[x]$,
For all $l$ we'll have $BA^l v=A^l B v=A^l f(A)v= f(A)A^l v$.
So in fact $B=f(A)$.


*Conversely if $B=f(A)$ with $f\in k[x]$ then obviously $B$ commutes with $A$.


*The elements of $GL_n(k)$ commuting with $A$ will be those such that $f$ is coprime with $m$.
A: You say that you have established that any matrix commuting with $A$ is of the form $B=bI+aA+cA^2$; so the centraliser of $A$ is the ring $\mathbb{F}_5[A]$. The kernel of the homomorphism $\epsilon_A:\mathbb{F}_5[X]\to\mathbb{F}_5[A]$ given by $f(X)\mapsto f(A)$ is just $\langle X^3-1\rangle$ so that the centraliser of $A$ is (isomorphic to) the ring $\mathbb{F}_5[X]/\langle X^3-1\rangle$. [Personally I would not suppress the words "isomorphic to" here.]
Now over $\mathbb{F}_5$ we have that $X^3-1=(X-1)(X^2+X+1)$ as a product of distinct irreducible factors. So we have by the Chinese Remainder Theorem that
$$
\mathbb{F}_5[X]/\langle X^3-1\rangle\simeq
\mathbb{F}_5[X]/\langle X-1\rangle\oplus
\mathbb{F}_5[X]/\langle X^2+X+1\rangle.
$$
As $X-1$ and $X^2+X+1$ are irreducible we have that each of these quotients is a field, so that our centraliser is isomorphic to
$$
\mathbb{F}_5\oplus\mathbb{F}_{25}.
$$
When generalising this there are to be complications when $m_A(X)$ has repeated irreducible factors.
