Calculating Gramian matrix from Euclidean distance matrix For $v_1, \dots, v_n \in \mathbb{R}^n$ we have Euclidean distance matrix $D = (\|v_i - v_j\|^2)_{ij}$ and Gramian matrix $G = (v_i \cdot v_j)_{ij} = V^TV$, where $V = (v_1, \dots, v_n)$. If the $v_i$ are mean-centered ($\sum_i v_i = 0$) then the Gramian matrix can be calculated from the Euclidean distance matrix by $G = -\frac{1}{2}CDC,$ where $C = I - \frac{1}{n}\bf{1}^T \bf{1}$ is the n-by-n centering matrix. What is an elegant way to show this identity?

Note: I can prove this, but only by entering "indices hell":
Write the components of $D$ and $G$ as $d_{ij}$ and $g_{ij}$ respectively. Then:
$$d_{ij}=g_{ii}+g_{jj}-2g_{ij}$$
$$\sum_{j} g_{ij} = v_i \cdot (\sum_j v_j) = 0$$
$$\sum_{j}d_{ij} = \sum_{j}d_{ji} = \sum_j (g_{ii} + g_{jj} - 2g_{ij})=ng_{ii}+Tr(G)$$
Let $CD = (h_{ij})_{ij}$ and $CDC = (h'_{ij})_{ij}$. Then
$$h_{ij} = d_{ij} - \frac{1}{n}\sum_k d_{kj} = (g_{ii} + g_{jj}-2g_{ij}) - \frac{1}{n}(ng_{jj}+Tr(G))$$
$$= g_{ii}-2g_{ij}-\frac{1}{n}Tr(G)$$
$$\sum_k h_{ik} = n g_{ii}-Tr(G)$$
$$h'_{ij} = h_{ij}-\frac{1}{n}\sum_k h_{ik} = 2g_{ij}$$
and hence $G = \frac{1}{2}CDC$.
I've thought about whether one might be able to make use of the Cholesky decomposition of $D$ (since then $G = V^TV$ and $D = L^TL$, so the identity would be $V^TV=\frac{1}{2}H^TL^TLH$ and then perhaps once could relate $V$ to $LH$ somehow), but I'm not sure when $D$ is positive-definite. Also, I am aware of this related question.
 A: Set $\gamma_i=(v_i,v_i)$ and $e_i=1$. In terms of these (column) vectors we have the following expression relating $D$ and $G$:
$$  D = e \gamma^T + \gamma e^T - 2 G .$$
Defining the projection $P=I - \frac{1}{n} e e^T$ we have
 $P e= e^T P = 0$ and, under the assumptions of vanishing mean-value, $e^TG=0$ and $G e=0$ so $PG=G=GP$. Finally, $$PDP = -2G$$
A: Note that the all-ones matrix $(J)$ is annihilated when multiplied by the Centering matrix (from either side)
$$\eqalign{
\def\LR#1{\left(#1\right)}
C &= \LR{I-\tfrac{1}{n}J} \;=\; C^T \\
0 &= JC = CJ \;=\; C^TJ^T \\
}$$
However, the $V$ matrix is unaffected by the Centering matrix
(since it is already centered) and its Gramian matrix inherits this immunity
$$\eqalign{
\def\qiq{\quad\implies\quad}
&VC = V &\qiq CV^T = V^T \\
&G = V^TV &\qiq G = CGC \\
}$$
The distance matrix can be written in terms of $(G,J,V)\,$ and Hadamard products $(\odot)$
$$\eqalign{
D &= \LR{V\odot V}^TJ + J^T\LR{V\odot V} - 2G \\
}$$
Straightforward multiplication yields the desired conclusion
$$\eqalign{
CDC &= \LR{0 + 0 - 2CGC} \;=\; -2G \\
}$$
