$\operatorname{tr}(BA)$ where $A$ is low rank and has a subset of eigenvalues from $B^{-1}$ Most of the question is in the title.
Suppose that I have $B$ a square $N\times N$ positive definite matrix, and $A$ a low-rank square matrix with its non-zero eigenvalues being a subset of the spectrum of $B^{-1}$. Is there a simple way to compute the trace : $\mathrm{tr}(BA)$?
My intuition is that if $M$ is the rank of $A$, then $B$ and $A$ can share all $N$ eigenvectors and that one can diagonalize $A$ and $B$ and get automatically $\mathrm{tr}(BA) = \sum_{i:\lambda_i>0} \frac{\lambda_i}{\lambda_i} = M$ where $\lambda_i$ are the eigenvalues of $A$. But I am not sure how to obtain the proper ordering etc.
Thanks for your help!

Ok here is a more concrete attempt.
So if the eigenvalues of $B^{-1}$ are $\Lambda_B = \{\lambda_i\}_{i=1}^N$, I know that the eigenvalues $\Lambda_A$ of $A$ are a subset of $\Lambda_B$ and the rest are $0$.
So I can rewrite $B=W D_B^{-1}W^\top$ where $D_B=\text{diag}(\Lambda_A, \Lambda_{B}/\Lambda_{A})$ and $W$ are the corresponding eigenvectors.
Similarly I can rewrite $A$ as $A=WD_AW^\top$ where $D_A=\text{diag}(\Lambda_A, 0)$
Which means I can rewrite
\begin{align}
\text{tr}(BA) =& \text{tr}(WD_B^{-1}W^\top WD_AW^\top) = \text{tr}(W^\top W D_B^{-1}D_A)\\
=& \text{tr}(D_B^{-1}D_A) = \sum_{i=i}^M \frac{\lambda_i}{\lambda_i} = M.
\end{align}
Is there anything wrong with my reasonning?
