When can we write $X^\top MX$ as a function of $MX$?
Here $M$ is a fixed symmetric matrix and $X$ is a variable matrix, which may be non-square also.
My attempts
When $M$ is idempotent, then we are done, because then $X^\top CX = (CX)^\top(CX)$. But can we have a weaker sufficient condition? Is there a necessary and sufficient condition??
In fact, this will always hold. Let $P$ be an invertible matrix such that $$ P^TMP = \pmatrix{I_p\\ &-I_q\\&&0_r}. $$ Let $Y = P^{-1}X$. We have $$ MX = P^{-T}(P^TMP)(P^{-1}X) = P^{-T} \pmatrix{Y_1\\-Y_2\\0}. $$ On the other hand $$ X^TMX = Y^T(P^TMP)Y = \\ \pmatrix{Y_1^T & Y_2^T & Y_3^T}\pmatrix{I_p\\ &-I_q\\&&0_r}\pmatrix{Y_1\\Y_2\\Y_3} = \\ Y_1^TY_1 - Y_2^TY_2. $$ Conclude that $$ X^TMX = \begin{bmatrix}Y_1^T & -Y_2^T&0\end{bmatrix} \begin{bmatrix}I_p\\ &-I_q\\&&0_r\end{bmatrix} \begin{bmatrix}Y_1\\-Y_2\\0\end{bmatrix} \\= [(MX)^TP](P^{-T}MP^{-1})[P^T(MX)] \\ = (MX)^T(P^{-1}P^T)^TM(P^{-1}P^T)(MX). $$