# Closed form of $\int\limits_0^{2\pi} \prod\limits_{j=1}^n \cos(jx)dx$ and combinatorial link

I have been trying to find a closed form for this integral: $$I_n = \int\limits_0^{2\pi} \prod_{j=1}^n \cos(jx)dx$$ The first values are: $$I_1=I_2=0,I_3=\frac{\pi}{2}, I_4=\frac{\pi}{4}, I_5=I_6=0, I_7=\frac{\pi}{8}, I_8=\frac{7\pi}{64}$$

I am not able to see here a clean pattern except that for $$n=4k+1,4k+2$$ the integral should be zero. If someone could give me a hint I would appreciate it.

EDIT

As suggested by Winther in the comments, the problem can be viewed from a combinatorial standpoint. Looking at the complex exponential representation one gets $$2^n$$ integrals of the form $$\int_0^{2\pi}e^{iNx}dx$$, which is only nonzero, if $$N=0$$. The integral evaluates to $$\frac{M\pi}{2^{n-1}}$$, where $$M$$ is the number of nonzero integrals.

So one needs to find $$M$$, which is the number of binary numbers $$b$$ for which holds that $$\sum_{k=1}^n (2b_k-1)k = 0$$ where $$b_k$$ is the k-th digit of $$b$$. With this, it is easy to see if for some $$b$$ it holds, it will also hold for $$\overline{b}$$ (each digit is inverted).

• Here are the first $30$ terms, in case that helps: $$\left\{0,0,\frac{\pi }{2},\frac{\pi }{4},0,0,\frac{\pi }{8},\frac{7 \pi }{64},0,0,\frac{35 \pi }{512},\frac{31 \pi }{512},0,0,\frac{361 \pi }{8192},\frac{657 \pi }{16384},0,0,\frac{2055 \pi }{65536},\frac{1909 \pi }{65536},0,0,\frac{24955 \pi }{1048576},\frac{46923 \pi }{2097152},0,0,\frac{316301 \pi }{16777216},\frac{299973 \pi }{16777216},0,0\right\}$$ Aug 10, 2020 at 22:25
• Use the complex exponential representation of cosine. This reduces the integral to $2^n$ integrals on the form $\int_0^{2\pi}e^{iNx}dx$. This is only non-zero when $N=0$. From this we can see that the result will be $M 2\pi / 2^n$ for some integer $M$. The number $N = a_1 + a_2 + \ldots + a_n$ where $a_k = \pm k$. For example for $n=3$ we have $2$ sums: $1+2-3=0$ and $-1-2+3=0$ so the integral is $2\pi \cdot 2 / 2^3$. Aug 10, 2020 at 22:25
• Yes thats exactly right. Or if you will: how many partitions there are of $\{1,2,\ldots,n\}$ into two sets that have the same sum. Aug 10, 2020 at 22:34
• btw you can find more info about that sequence here oeis.org/A063865 (it does not have a simple closed form, but its possible to find an asymptotic expression for it). Aug 10, 2020 at 23:03

Hint. From $$\int\limits_{\gamma}f(z)dz=\int\limits_{a}^{b}f(\gamma(t))\gamma'(t)dt$$ with a transformation like $$\int\limits_0^{2\pi} \prod_{j=1}^n \cos(jx)dx= \int\limits_0^{2\pi} \prod_{j=1}^n \frac{e^{i j x}+e^{-i j x}}{2}dx=\\ \int\limits_0^{2\pi} \frac{1}{2^n} \cdot\prod_{j=1}^n \frac{1}{e^{i j x}} \cdot \prod_{j=1}^n \left(e^{2i j x}+1\right)dx=\\ \int\limits_0^{2\pi} \frac{1}{2^n} \cdot \frac{1}{e^{i \frac{n(n+1)}{2} x}} \cdot \prod_{j=1}^n \left(e^{2i j x}+1\right)dx=\\ \int\limits_0^{2\pi} \frac{1}{i2^n} \cdot \frac{1}{e^{i \frac{n(n+1)}{2} x+ix}} \cdot \left(\prod_{j=1}^n \left(e^{2i j x}+1\right)\right) \cdot ie^{i x}dx=\\ \int\limits_{|z|=1}\frac{1}{i2^n} \cdot \frac{1}{z^{\frac{n(n+1)}{2}+1}} \cdot \prod_{j=1}^n \left(z^{2 j }+1\right)dz=...$$ and noting $$f(z)=\prod\limits_{j=1}^n \left(z^{2 j }+1\right)$$, we have $$...=\frac{1}{i2^n} \int\limits_{|z|=1}\frac{f(z)}{z^{\frac{n(n+1)}{2}+1}} dz=...$$ recalling Cauchy's integral formula this is $$...=\frac{1}{i2^n}\cdot \frac{2 \pi i}{\left(\frac{n(n+1)}{2}\right)!}\cdot f^{\left(\frac{n(n+1)}{2}\right)}(0)= \frac{\pi}{2^{n-1}} \cdot \frac{1}{\left(\frac{n(n+1)}{2}\right)!} \cdot f^{\left(\frac{n(n+1)}{2}\right)}(0)$$

• I love seeing someone do the problem exactly as I would when I am too tired to do math. +1 Aug 11, 2020 at 1:36

The integral is equal to $$\frac{A_n\pi}{2^{n-1}}$$ where $$A_n$$ is the number of subsets of $$\{1,2,3,\dots,n\}$$ whose sum is $$\frac{n(n+1)}4.$$

In particular, if $$n\equiv 1,2\pmod 4,$$ the $$\frac{n(n+1)}4$$ is not an integer, so there can be no such aubsets, so the integral is zero in that case.

You get this value by representing $$\cos nx =\frac12 \left(e^{inx}+e^{-inx}\right)$$ and realize the integral is zero for all terms expanding the produc, except for the constant term, which has coefficient $$\frac{A_n}{2^n}.$$

I don’t think there is an easy way to represent this term. There is an upper bound $$\binom n{\lfloor n/2\rfloor}.$$

See this answer for details. Compute $\lim\limits_{n\to\infty} \int_{0}^{2\pi} \cos x \cos 2x\cdots \cos nx \space{dx}$

As pointed out in the comments, the result is

$$I_n = a_n \frac{2\pi}{2^{n}}$$

where $$a_n$$ is the numbers of solutions of $$\sum_{j=1}^n s_n \,j =0$$ where $$s_j \in \{1,-1\}$$ (or number of ways of marking a subset of $$\{ 1,2, \cdots n\}$$ such that the sum of the marked subset equals the sum of the unmarked subset). This is given by OEIS A063865.

Asymptotics (for $$n=0,3 \pmod 4$$): $$I_n \approx \sqrt{24 \pi} \, n^{-3/2}$$

Ref