Consider the proof at page 2 found here: https://people.orie.cornell.edu/dpw/orie6334/Fall2016/lecture7.pdf
I can’t wrap my head around the second and third line:
\begin{align} &= \sum_{i \in V}x(i)^2 - \sum_{(i, j) \in E}\frac{2x(i)x(j)}{\sqrt{d(i)d(j)}}\\ &= \sum_{(i, j) \in E}\left(\frac{x(i)}{\sqrt{d(i)}} - \frac{x(j)}{\sqrt{d(j)}}\right)^2 \end{align}
They say that it can be seen by “inversely” expanding the second term. However, when I do so, to me at least it is definitely not obvious: $$\left(\frac{x(i)}{\sqrt{d(i)}} - \frac{x(j)}{\sqrt{d(j)}}\right)^2 = \frac{x(i)^2}{d(i)} - \frac{2x(i)x(j)}{\sqrt{d(i)d(j)}} + \frac{x(j)^2}{d(j)}.$$
Now from this I have no clue how this can be related to the first line.
How did they go from the first line above to the second, what are the intermediate steps?
The notation is somewhat confusing in that the edges are denoted $(i,j)\in E$ as if they were ordered pairs, but the graph is actually undirected and the sum is really meant to go over each undirected edge once. Thinking about each edge as a two-element set, the argument is just exchanging the order of summation: $$\begin{align*} \sum_{\{i,j\}\in E}\frac{x(i)^2}{d(i)}+\frac{x(j)^2}{d(j)}&= \sum_{e\in E}\sum_{i\in e}\frac{x(i)^2}{d(i)}\\ &=\sum_{i\in V}\sum_{\substack{e\in E\\i\in e}}\frac{x(i)^2}{d(i)}\\ &=\sum_{i\in V}\frac{x(i)^2}{d(i)}\sum_{\substack{e\in E\\i\in e}}1\\ &=\sum_{i\in V}\frac{x(i)^2}{d(i)}d(i)\\ &=\sum_{i\in V}x(i)^2. \end{align*}$$