Let $A \in \mathbb{R}^{n \times p}, B \in \mathbb{R}^{p \times n}$ be two matrices. Consider the matrix-valued functions when defined:
$$z \mapsto (AB - zI_n)^{-1}, \qquad z \mapsto (BA - zI_p)^{-1} $$
These are the resolvents of matrices $AB$ and $BA$, respectively. How do I prove that for each $z$ that's neither $0$ nor an eigenvalue of $AB$, the following holds?
$$\mbox{trace} (AB - zI_p)^{-1} = \mbox{trace} (BA - zI_n)^{-1} + \frac{n - p}{z} $$
P.S. I think that for a proof, the second answer in Sylvester's determinant identity might be a way to go, using $tr(XY)=tr(YX)$, where $X,Y$ are the two block matrices that the answerer mentioned. But the differenc here is that: we're looking at $trace((AB - zI_p)^{-1})$, and $trace((BA - zI_n)^{-1})$, and not $trace(AB - zI_p), trace(BA - zI_n)$ directly.