Suppose we have a real matrix $A$ with dimensions $p$-by-$n$, where $p \geq n$, and another $p$-by-$p$ positive definite matrix $B$. If the rank of matrix $A$ is denoted as $r$, what can be inferred about the rank of the matrix $A^TBA$? I would like to explore this question, considering two distinct cases: when $r=n$ and when $r<n$.
Additionally, it's worth noting that if matrix $B$ is the identity matrix, i.e., $B=I$, then $A^TA$ represents the Gram matrix, and its rank is equal to the rank of $A$.
In fact, if $B$ is positive definite, then $\mathrm{rank}(A^\top BA)=\mathrm{rank}(A)$. To see this, note that $$Ax=0\iff A^\top BAx=0$$ The $\implies$ direction is easy, the $\impliedby$ direction holds because $A^\top BAx=0$ implies $x^\top A^\top BAx=0$, which in turn implies $Ax=0$ since $B$ is positive definite. Therefore, $$\dim\ker A=\dim\ker A^\top BA\implies\dim\mathrm{range } A=\dim\mathrm{range } A^\top BA$$