Let $G$ be a simple graph (that is, without parallel edges and loops). I want to know how can one go about formally proving the following (if true):
$$ \sum_{\{v,w\}\in E(G)}d(v)+d(w) = \sum_{v \in V(G)}d(v)^2 $$
Intuitively, I've convinced myself since the RHS can be thought of a sum where each term $d(v)$ is summed exactly $d(v)$ times, and the LHS verifies this as well: each $d(v)$ 'appears' on one of the summands if and only if there exists an edge $e \in G$ which contains $v$. Since this happens exactly $|\{e \in G : v \in e\}|= d(v)$ times, each sum has the same terms ocurring the same amount of times. How can I say this with a bit more rigor?
You have the right idea. Define the set $\, F := \{(v,e) \in V(G)\times E(G) : v \in e\} \,$ of ordered pairs of all vertices and all edges that contains that vertex. Consider the sum $\, \sum_{(v,e)\in F} d(v). \,$ It partitions naturally in two ways. One way is by vertices and the other by edges. In the first case, each vertex $\, v \,$ appears $\, d(v) \,$ times and thus the sum is of $\, d(v)^2. \,$ In the second case, each edge $\, \{v,w\} \,$ has two vertices and appears two times, once for $\, v \,$ and again for $\, w, \,$ and thus the sum is of $\, d(v)+d(w). \,$