I'm a noob cs masters student trying to understand how the laplacian and the Dirichlet sum are related. So there is this popular expression with graph adjacency matrix $A$ and the laplacian $L$,
$$ \sum_{ij}A_{ij}(x_i -x_j)^2 = x^tLx. $$
I'm trying to find the proof for this (for specific problem of undirected graphs). I tried to expand this out as $$ \sum_{ij}A_{ij}(x_i -x_j)^2 = \sum_{ij}A_{ij}x_i^2 + \sum_{ij}A_{ij}x_j^2 - 2\sum_{ij}A_{ij}x_ix_j \\ = \sum_{i}x_id_i + \sum_{j}x_jd_j - 2\sum_{ij}A_{ij}x_ix_j. \\ $$ Where $d$ is the degree vector. Now, I know that $L = diag(d)-A$. My question is how do I get from the result before to $x^tLx$. I apologize if this is a stupid question, I tried finding proofs online but could not find a simple solution.
edit: typo in equation
$\sum_{ij,j<i}A_{ij}(x_i -x_j)^2\\ =\frac{1}{2}\sum_{ij}A_{ij}(x_i-x_j)^2\\ =\frac{1}{2}\sum_i\sum_jA_{ij}(x_i^2+x_j^2-2x_ix_j)\\ =\frac{1}{2}(\sum_ix_i^2\sum_jA_{ij}+\sum_jx_j^2\sum_iA_{ij}-2\sum_{ij}A_{ij}x_ix_j)\\ =\frac{1}{2}(\sum_ix_i^2d_i+\sum_jx_j^2d_j-2\sum_{ij}A_{ij}x_ix_j)\\ =\frac{1}{2}(\sum_ix_i^2d_i+\sum_ix_i^2d_i-2\sum_{ij}A_{ij}x_ix_j)\\ =\frac{1}{2}(2\sum_ix_i^2d_i-2\sum_{ij}A_{ij}x_ix_j)\\ =\sum_ix_i(x_id_i-\sum_j A_{ij}x_j)\\ =\sum_ix_i(d_i\sum_j\delta_{ij}x_j-\sum_j A_{ij}x_j)\\ =\sum_i x_i\sum_j(d_i\delta_{ij}-A_{ij})x_j\\ =\sum_i\sum_j x_i(d_i\delta_{ij}-A_{ij})x_j\\ =\sum_{ij}x_iLx_j\\ =x^tLx $