<s>[INST] How was the closed form of this alternating sum of squares calculated? I am reading through this answer at socratic.org.
The question is to find the closed form of the sum
$$1^{2}-2^{2}+3^{2}-4^{2}+5^{2}-6^{2}+\ldots.$$
I understand that, if the terms were added, the sum would be
$$
\sum_{n=1}^{N} n^{2}=1^{2}+2^{2}+\ldots+N^{2}.
$$
The person goes on to say, if the series were not alternating, the sum would be
$$
S=\frac{N(N+1)}{2}
$$
But is that correct? I thought the sum of the first $N$ squares would be
$$
\frac{N(N+1)(2N+1)}{6}.
$$
Lastly, I understand moving the $-1$ constant out of the summation as such
$$
=-\sum_{n=1}^{N}(-1)^{n} n^{2}
$$
But I am completely missing how the final closed form was calculated
$$
S_{N}=-\frac{(-1)^{N} N(N+1)}{2}
$$
 [/INST] (This answer is an expansion of my comment. It shows an alternative method for computing the sum.)
If $n$ is even, then an easy way to compute $1^2-2^2+3^2-4^2+\dots+(n-1)^2+n^2$ is to consider the difference between each pair of terms:
\begin{align}
&1^2-2^2+3^2-4^2+\dots+(n-1)^2+n^2 \\[4pt]
=&(1-2)(1+2)+(3-4)(3+4)+\dots +((n-1)-n)((n-1)+n) \\[4pt]
=&-1(1+2)-1(3+4)-\dots-1((n-1)+n) \\[4pt]
=&-1(1+2+3+4+\dots+(n-1)+n) \\[4pt]
=&-\frac{n(n+1)}{2}
\end{align}
If $n$ is odd, then $n-1$ is even, and so we can use the above formula:
$$
1^2-2^2+3^2-4^2+\dots+(n-2)^2+(n-1)^2=-\frac{(n-1)n}{2} \, .
$$
Then, adding $n^2$ to both sides, we find that
$$
1^2-2^2+3^2-4^2+\dots+(n-1)^2+n^2=\frac{n(n+1)}{2} \, .
$$
Therefore, regardless of the parity of $n$,
$$
1^2-2^2+3^2-4^2+\dots+(n-1)^2+n^2=(-1)^{n+1}\cdot\frac{n(n+1)}{2} \, .
$$
</s>