Number of choices of signs: $\pm 1 \pm 2 \pm ... \pm n=0$
Here is an interesting problem I thought of.
In how many ways can we choose the $n$ $\pm$ signs in the equation below:
$\pm 1 \pm 2 \pm ... \pm n=0$
It has been made apparent to me that in fact the number of solutions is
$$ \frac{1}{2\pi} \int_0^{2\pi} \prod_{k=1}^{n} 2\cos(kx) dx $$ I find this result interesting and so:
1)How can we prove that result?
2)Does the integral have a closed form? We know that $f(n)=0$ for $n$ is $1,2$ mod $4$ by parity considerations, but for general $n$ I would be suprised if a closed form exists.
EDIT: It has been made apparent that we can prove the identity more easily than in the answer below by using generating functions. In particular consider the product of $z^k+z^{-k}$ over the appropriate values of $k$, and note the connection to complex numbers on the unit circle. Don't want to give too many more details, but you will have to substitute $z=e^{ix}$ I think. I challenge you to fill in the details (I know how to do it myself now).
Solution $1$ (using induction on $n$):
Given an integer $n$, let's consider the set $X_n=\{1,-1\}^n$; $X_n$ is the set of all choices of signs, any $a=(\epsilon_1,\cdots,\epsilon_n)\in X_n$ corresponds to the choice of signs : $ 1\epsilon_1+ 2\epsilon_2 + \cdots +n\epsilon_n$. For every $a=(\epsilon_1,\cdots,\epsilon_n)\in X_n$ define the function $f_a$ by: $$\forall x: \quad f_a(x)=1\epsilon_1x+ 2\epsilon_2x+ \cdots +n\epsilon_nx\tag 1$$
claim $1$ $$\prod_{k=1}^{n} 2\cos(kx)=\sum_{a\in X_n} \cos(f_a(x))\tag{$2_n$}$$
proof: by induction on $n$
Basis step : For $n=1$ we have $X_n={1,-1}$ and hence: $$2\cos(x)=\cos(-x)+\cos(x)\tag{$2_1$}$$ which is obviously true, and it's what we want.
Induction step:suppose $(2)_n$ is true we have the following result : $$ X_{n+1}=\left\{(a,\epsilon)\big / a\in X_n, \epsilon \in\{1,-1\}\right\}\tag 3$$
we have also: $f_{(a,\epsilon)}(x)=f_a(x)+\epsilon(n+1)x$.
Now we can start the computation : $$ \begin{align} \sum_{b\in X_{n+1}} \cos(f_b(x))&&=&\sum_{a\in X_n}\quad \sum_{\epsilon =1,-1} \cos(f_{(a,\epsilon)}(x))\tag 4\\ &&=&\sum_{a\in X_n}\quad \sum_{\epsilon =1,-1} \cos(f_{a}(x)+\epsilon(n+1)x)\tag 5\\ &&=&\sum_{a\in X_n} 2\cos(f_{a}(x))\cos((n+1)x)\tag 6\\ &&=&2\cos((n+1)x)\sum_{a\in X_n} \cos(f_{a}(x))\tag 7\\ &&=&\prod_{k=1}^{n+1} 2\cos(kx)\tag 8 \end{align} $$
finally $(2)_{n+1}$ is true. From $(5)$ to $(6)$ we used the following: $$\sum_{\epsilon =1,-1}\cos(a+\epsilon b)=\cos(a+b)+\cos(a-b)=\cos(a)\cos(b) \tag 9$$ and at the end $(7)$ to $(8)$ we used the induction hypothesis $(2)_n$
claim 2 $$\text{card}\left\{a\in X_n/ f_a=0\right\}=\frac{1}{2\pi} \int_0^{2\pi} \prod_{k=1}^{n} 2\cos(kx)dx \tag{10}$$
This claim is exactly OP's first question.
proof: The proof starts by integrating $(2)_n$ wich gives us : $$\begin{align}\frac{1}{2\pi} \int_0^{2\pi} \prod_{k=1}^{n} 2\cos(kx)&&=&\frac{1}{2\pi} \int_0^{2\pi}\sum_{a\in X_n} \cos(f_a(x))dx\tag{11}\\ &&=&\sum_{a\in X_n} \frac{1}{2\pi} \int_0^{2\pi} \cos(f_a(x))\tag{12}\\ &&=&\sum_{a\in X_n,f_a=0} 1\tag{13}\\ &&=&\#\left\{a\in X_n/ f_a=0\right\}\tag{14} \end{align} $$ From $(12)$ to $(13)$ we used the fact that $\frac{1}{2\pi}\int_0^{2\pi}\cos(f_a(x))dx=1$ if $f_a=0$ and $=0$ if $f_a(x)=mx$ where $m\neq 0$.
And here the proof which gives your formula terminates.
Comment
For the second question I don't know if there is a closed form for this integral. as pointed by Did this integral was studied by Blair D. Sullivan for other reasons in his paper: On a Conjecture of Andrica and Tomescu and as a result we can point that the number of possible ways of choosing the signs to obtain $0$ when $n \equiv 0 \text{ or } 3 \mod 4$ is equivalent to: $$\frac{2^{n+1}}{n^{\frac{3}{2}}}\sqrt{\frac{6}{\pi}} $$
Solution $2$ (direct proof):
we have: $$\begin{align} \prod_{k=1}^{n} 2\cos(kx) &&=&\prod_{k=1}^n \left(e^{ikx}+e^{-ikx}\right) \tag 1\\ \\ &&=&\sum_{a=(\epsilon_1,\epsilon_2,\cdots,\epsilon_n)\in \{+1,-1\}^n} e^{i1\epsilon 1}e^{i2\epsilon_2}\cdots e^{in\epsilon_n}\tag 2\\ \\ &&=&\sum_{a=(\epsilon_1,\epsilon_2,\cdots,\epsilon_n)\in \{+1,-1\}^n}e^{i\sum_{l=1}^n\epsilon_ll } \tag 3\\ \\ &&=&\sum_{k\in [-\frac{(n^2+n)}{2},\frac{(n^2+n)}{2}]} a_ke^{ikx}\tag 4\end{align}$$ where $$a_k=\text{card}\left\{a=(\epsilon_1,\epsilon_2,\cdots,\epsilon_n)\in \{+1,-1\}^n\big/ \sum_{i=1}^n\epsilon_ii=k\right\}\tag 5$$
From here we can obtain $a_0$ by integrating using the fact that $\int_{0}^{2\pi}a_ke^{ikx}=0$ if $k\neq 0$; which gives : $$\frac{1}{2\pi} \int_0^{2\pi}\prod_{k=1}^{n} 2\cos(kx)=a_0 \tag 6$$ And it's clear from the definition of $a_k$ that $a_0$ is exactly the the number of the choices of the signs $\pm$ in the equation $\pm 1 \pm 2 \pm ... \pm n=0$
In this proof we used mainly two identities :
Expanding products this identity is uesed in the transition $(1)\to (2)$ :
$$\prod_{k=0}^n (x_k^{+1}+x_k^{-1})=\sum_{a=(\epsilon_1,\epsilon_2,\cdots,\epsilon_n)\in \{+1,-1\}^n} x_1^{\epsilon 1}x_2^{\epsilon_2}\cdots x_n^{\epsilon_n}\tag 7$$
Grouping terms: the general for the transition $(3)\to (4)$ is :
$$\sum_{a \in E} g(u(a))=\sum_{k\in u(E)} b_k g(k) \tag 8$$ where $a_k=\text{card} \{x\in E \big/ u(x)=k\}$ and $E$ a finite set
Suppose $$ \sum_{k=1}^n\pm k=0\tag{1} $$ Since $$ \sum_{k=1}^nk=\frac{n^2+n}2\tag{2} $$ both the sum of the positive and the sum of the negative terms must be $\frac{n^2+n}4$. Thus, $(1)$ has no solution for $n\equiv1,2\pmod{4}$ since for those $n$, $\frac{n^2+n}4\not\in\mathbb{Z}$.
The number of solutions to $(1)$ is the coefficient of $x^0$, the constant coefficient, in $$ \prod_{k=1}^n\left(x^k+x^{-k}\right)\tag{3} $$ which is $$ \frac1{2\pi}\int_0^{2\pi}\prod_{k=1}^n\left(e^{ikx}+e^{-ikx}\right)\mathrm{d}x =\bbox[5px,border:2px solid #C0A000]{\frac1{2\pi}\int_0^{2\pi}\prod_{k=1}^n2\cos(kx)\,\mathrm{d}x}\tag{4} $$