I have an equation $$E=\frac{1}{2}k(\varphi_1-\varphi_2)^2+\frac{1}{2}k(\varphi_2+\varphi_3)^2+\frac{1}{2}k(\varphi_4-\varphi_3)^2$$ that looks quite compact already but the problem is that the equation above is written for $n=4$. Notice that for each $n$ the equation has $n-1$ terms where the middle one is also a sum of variables. Also note that later in my calculations i am calculating derivatives of $E$, meaning that it is NOT the same if I write $(x-y)^2$ or $(y-x)^2$.
How would I write $E$ in a more compact way? Probably with some combination of sums. For example: If $n=10$ than $$E=\frac{1}{2}k(\varphi_1-\varphi_2)^2+\frac{1}{2}k(\varphi_3-\varphi_3)^2+\frac{1}{2}k(\varphi_3-\varphi_4)^2+\frac{1}{2}k(\varphi_4-\varphi_5)^2+\frac{1}{2}k(\varphi_5+\varphi_6)^2+\frac{1}{2}k(\varphi_7-\varphi_6)^2+\frac{1}{2}k(\varphi_8-\varphi_7)^2+\frac{1}{2}k(\varphi_9-\varphi_8)^2+\frac{1}{2}k(\varphi_{10}-\varphi_9)^2$$
which becomes very ... yeah.