$f(A)$ is invertible iff $A,B$ have no common eigenvalues A matrix $A \in M_n(F)$ is invertible iff there exists a matrix like $B \in M_n(F)$ such that $AB=I_n$.
A scalar like $\lambda \in F$ is called an eigenvalue of $A$ iff $\lambda I_n-A$ is not invertible.
The characteristic polynomial of a square matrix is a polynomial which is invariant under matrix similarity and has the eigenvalues as roots. It has the determinant and the trace of the matrix as coefficients.
Question :

Assume that $A,B \in M_n(\mathbb C) $ and $f(x)=\det(xI_n-B)$ is the characteristic polynomial of $B$.
Prove that $f(A)$ is invertible iff $A,B$ have no common eigenvalues.

Note : Here, when we talk about $f(A)$, we mean something like this :
$f(x)=a_nx^n+a_{n-1}x^{n-1}+\dots+a_1x+a_0 \implies f(A)=a_nA^n+a_{n-1}A^{n-1}+\dots+a_1A+a_0I$
The problem :
I'm confused about the meaning of $f(A)$ being invertible and the characteristic polynomial of $A$ which is $det(xI_n-A)$. I don't know where to start and what to work on.
 A: Let $\mu_i$ be eigenvalues of $A$. Since every matrix is similar to a upper triangular matrix, there is an invertible $P$ such that
$$
P^{-1}AP=\pmatrix{\mu_1 \hspace{5 mm}*\\\ddots \\& \mu_{n-1} \hspace{5 mm}* \\& \hspace{10 mm}\mu_n }=J_A
$$
where $J_A$ is an upper triangular matrix.
Thus
$$
f(A)=Pf(J_A)P^{-1}=P\pmatrix{f(\mu_1) \hspace{5 mm}*\\\ddots \\& f(\mu_{n-1} )\hspace{5 mm}* \\& \hspace{10 mm}f(\mu_n) }P^{-1}
$$
So $f(\mu_i)$ are eigenvalues of $f(A)$. If a $\mu_k$ is also  eigenvalue of $B$, then $f(\mu_k)=0$. Thus $f(A)$ has an  eigenvalue of $0$ and is not invertible.
A: Hint: write $f$ factorized on its roots, that is,
$$
f(x)=(x-\lambda_1)^{m_1}\cdots(x-\lambda_k)^{m_k},
$$
where $m_i$ is the algebraic multiplicity of the eigenvalue $\lambda_i$ (of the matrix $B$). Clearly, $\sum m_i = n$, and $k\leq n$. Then
$$
f(A) = (A-\lambda_1I)^{m_1}\cdots(A-\lambda_kI)^{m_k}
$$
From here, it should be easier to see why $f(A)$ is invertible iff $A$ and $B$ have no eigenvalue in common.
You may also need the fact that $A$ commutes with $p(A)$ for any polynomial $p$, and therefore you can write the characteristic polynomial in any order. For instance,
$$
f(A) = (A-\lambda_1I)^{m_1}\cdots(A-\lambda_kI)^{m_k} = (A-\lambda_kI)^{m_k}\cdots(A-\lambda_1I)^{m_1}
$$
