Diagonal of product of matrices, expression with inner product I have two matrices $\mathbf{A}$ and $\mathbf{B}$. They are full and not square, though their dimensions implies that their product is :
$$
\dim (\mathbf{A}) = (n,p) \quad \text{and} \quad \dim (\mathbf{B}) = (p,n) \implies \dim (\mathbf{A}\mathbf{B})=(n,n)
$$
Now, I am interested in calculating the diagonal terms of this product, but without having to calculate all the other terms in the process (this will be in a code where $n$ and $p$ are very large). I wrote it on a simple example and ended up with :
$$
diag(\mathbf{A}\mathbf{B}) = \sum Col\left(\mathbf{A} \cdot \mathbf{B}^\mathsf{T} \right)
$$
with $\cdot$ the inner product between the two matrices, and $\sum Col$ the sum on the columns of the matrix. Sorry if my formalism is bad, I wrote it in a coding style, so please feel free to correct me. 
I tested it on my code and it matches, but :


*

*How could I demonstrate that properly?

*Is there a theorem or a property for that? I failed to find it on the internet...


Thanks for your time!
 A: The $i$th term on the diagonal is the scalar product of the $i$th row of $A$ with the transpose of the $i$th column of $B$. Is that what you need?
A: With the help of @S. Dolan, I finally got the demonstration I was searching for. So in case others need it, here it is step by step.
Let $\mathbf{A}$ and $\mathbf{B}$ two matrices such as:
$$\dim (\mathbf{A}) = (n,p) \quad \text{and} \quad \dim (\mathbf{B}) = (p,n)$$
As their dimensions match, their multiplication gives:
$$\mathbf{A} \mathbf{B}= \sum_{k=1}^p a_{ik}b_{kj} \quad \forall i\in[1,n] \text{ and } \forall j\in[1,n]$$
were $a$ and $b$ are the elements of $\mathbf{A}$ and $\mathbf{B}$. Taking only the diagonal terms of this product, hence the terms for which $i=j$, yields:
$$diag\left(\mathbf{A} \mathbf{B}\right)= \sum_{k=1}^p a_{ik}b_{ki} \quad \forall i\in[1,n]$$
Besides, their dot/inner product $\mathbf{A} \cdot \mathbf{B}^\mathsf{T}$ is the term-by-term product:
$$\mathbf{A} \cdot \mathbf{B}^\mathsf{T} = a_{ik} b_{ki} \quad  \forall i\in[1,n] \text{ and } \forall k\in [1,p] $$
So that the sum on its columns (with index $k$) is:
$$\sum Col \left(\mathbf{A} \cdot \mathbf{B}^\mathsf{T}\right) = \sum_{k=1}^p a_{ik} b_{ki} \quad  \forall i\in[1,n] $$
It can then be concluded that:
$$diag\left(\mathbf{A} \mathbf{B}\right)= \sum Col \left(\mathbf{A} \cdot \mathbf{B}^\mathsf{T}\right)$$
QED
