Ramanujan's 'well known' integral, $\int\limits_{-\pi/2}^{\pi/2} (\cos x)^m e^{in x}dx$.

Assume that $n >m>-1$.

Then $$ \begin{align} \int_{-\pi /2}^{\pi /2} (\cos x)^{m} e^{inx} \, dx &= \int_{- \pi/2}^{\pi /2} \left( \frac{e^{ix}+e^{-ix}}{2} \right)^{m} e^{inx} \ dx \\ &= \frac{1}{i 2^{m}} \int_{C} (z+z^{-1})^{m} z^{n-1} \, dz \\ &= \frac{1}{i2^{m}} \int_{C} \left(z^{2}+1 \right)^{m} z^{n-m-1} \, dz \\ &= \frac{1}{i2^{m}} \int_{C} f(z) \, dz \end{align}$$

where $C$ is the right half of the unit circle traversed counterclockwise with quarter-circle indentations around the branch points at $z=-i$ and $z=i$.

Have the branch cut for $f(z)$ running down the imaginary axis from $z=i$, and define $f(z)$ to be real-valued on the positive real axis.

Now close the contour with a vertical line segment just to the right of $[-i,i]$ with a half-circle indentation around the branch point at $z=0$.

Just to the right of the branch cut and above the origin,

$$f(z) = |z^{2}+1|^{m} |z|^{n-m-1} e^{i \pi /2(n-m-1)} .$$

While just to the right of the branch cut and below the origin and above $z=-i$,

$$f(z) =|z^{2}+1|^{m} |z|^{n-m-1} e^{-i \pi /2(n-m-1)} .$$

And under the assumption that $n>m>-1$, the contributions from all three indentations vanish in the limit.

For example, around $z=0$,

$$ \Big| \int_{\pi/2}^{- \pi/2} f(re^{it}) \ i r e^{it} \, dt \Big| \le \pi \ (r^{2}+1)^{m} r^{n-m}$$

which vanishes as $r \to 0$ since $n>m$.

Then going around the contour, we get

$$ \int_{C} f(z) \, dz + e^{i \pi /2 (n-m-1)}\int_{1}^{0} \left| (te^{i \pi /2})^{2} +1 \right|^{m} |te^{ i \pi /2}|^{n-m-1} e^{ i \pi /2} \, dt $$

$$+ \ e^{-i \pi /2 (n-m-1)}\int_{0}^{1} \left| (te^{-i \pi /2})^{2} +1 \right|^{m} |te^{ -i \pi /2}|^{n-m-1} e^{ -i \pi /2} \, dt = 0 $$

which implies

$$ \begin{align} \int_{C} f(z) \ dz &= e^{ i \pi /2 (n-m)} \int_{0}^{1} (1-t^{2})^m t^{n-m-1} \, dt - e^{- i \pi /2 (n-m)} \int_{0}^{1} (1-t^{2})^{m} t^{n-m-1} \, dt \\ &= 2 i \sin \left( \frac{\pi}{2} (n-m) \right) \int_{0}^{1} (1-t^{2})^{m} t^{n-m-1} \, dt \\ &= i \sin \left( \frac{\pi}{2} (n-m) \right) \int_{0}^{1} (1-u)^{m} u^{n/2-m/2-1} \, du \\ &= i \sin \left( \frac{\pi}{2} (n-m) \right) B \left( \frac{n}{2} - \frac{m}{2}, m+1 \right) \\ &= i \sin \left( \frac{\pi}{2} (n-m) \right) \frac{\Gamma(\frac{n}{2} - \frac{m}{2}) \Gamma(m+1)}{\Gamma(\frac{m}{2}+\frac{n}{2} + 1)} .\end{align}$$

Then using the reflection formula for the gamma function, we get

$$ \int_{C} f(z) \ dz= i \pi \, \frac{\Gamma(m+1)}{ \Gamma(1- \frac{n}{2} + \frac{m}{2})\Gamma(\frac{m}{2}+\frac{n}{2}+1)} .$$

Therefore,

$$ \begin{align} \int_{-\pi /2}^{\pi /2} (\cos x)^{m} e^{inx} \, dx &= \frac{1}{i2^{m}} \, i \pi \, \frac{\Gamma(m+1)}{ \Gamma(1- \frac{n}{2} + \frac{m}{2})\Gamma(\frac{m}{2}+\frac{n}{2}+1)} \\ &=\frac{\pi}{2^m} \frac{\Gamma(1+m)}{\Gamma \left(1+ \frac{m+n}{2}\right)\Gamma \left(1+ \frac{m-n}{2}\right)} . \end{align} $$


$\newcommand{\+}{^{\dagger}} \newcommand{\angles}[1]{\left\langle\, #1 \,\right\rangle} \newcommand{\braces}[1]{\left\lbrace\, #1 \,\right\rbrace} \newcommand{\bracks}[1]{\left\lbrack\, #1 \,\right\rbrack} \newcommand{\ceil}[1]{\,\left\lceil\, #1 \,\right\rceil\,} \newcommand{\dd}{{\rm d}} \newcommand{\down}{\downarrow} \newcommand{\ds}[1]{\displaystyle{#1}} \newcommand{\expo}[1]{\,{\rm e}^{#1}\,} \newcommand{\fermi}{\,{\rm f}} \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,} \newcommand{\half}{{1 \over 2}} \newcommand{\ic}{{\rm i}} \newcommand{\iff}{\Longleftrightarrow} \newcommand{\imp}{\Longrightarrow} \newcommand{\isdiv}{\,\left.\right\vert\,} \newcommand{\ket}[1]{\left\vert #1\right\rangle} \newcommand{\ol}[1]{\overline{#1}} \newcommand{\pars}[1]{\left(\, #1 \,\right)} \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\pp}{{\cal P}} \newcommand{\root}[2][]{\,\sqrt[#1]{\vphantom{\large A}\,#2\,}\,} \newcommand{\sech}{\,{\rm sech}} \newcommand{\sgn}{\,{\rm sgn}} \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}} \newcommand{\ul}[1]{\underline{#1}} \newcommand{\verts}[1]{\left\vert\, #1 \,\right\vert} \newcommand{\wt}[1]{\widetilde{#1}}$ $\ds{\int_{-\pi/2}^{\pi/2}\cos^{m}\pars{x}\expo{\ic nx}\,\dd x ={\pi \over 2^{m}}\, {\Gamma\pars{1 + m} \over \Gamma\pars{1 + \bracks{m + n}/2}\,\Gamma\pars{1 + \bracks{m - n}/2}}:\ {\large ?}}$

\begin{align} &\color{#c00000}{\int_{-\pi/2}^{\pi/2}\cos^{m}\pars{x}\expo{\ic nx}\,\dd x} =\int_{-\pi/2}^{\pi/2}\bracks{1 + \cos\pars{2x} \over 2}^{m/2}\expo{\ic nx}\,\dd x \\[3mm]&=2^{-m/2 - 1}\int_{-\pi}^{\pi}\bracks{1 + \cos\pars{x}}^{m/2} \expo{\ic nx/2}\,\dd x \\[3mm]&=2^{-m/2 - 1} \int_{\verts{z} = 1 \atop {\vphantom{\Huge A}\verts{{\rm Arg}\pars{z}}\ <\ \pi}} \pars{1 + {z^{2} + 1 \over 2z}}^{m/2}z^{n/2}\,{\dd z \over \ic z} \\[3mm]&=-2^{-m - 1}\,\ic \int_{\verts{z} = 1 \atop {\vphantom{\Huge A}\verts{{\rm Arg}\pars{z}}\ <\ \pi}} \pars{2z + z^{2} + 1}^{m/2}z^{\pars{n - m}/2 - 1}\,\dd z \\[3mm]&=-2^{-m - 1}\,\ic \int_{\verts{z} = 1 \atop {\vphantom{\Huge A}\verts{{\rm Arg}\pars{z}}\ <\ \pi}} \pars{z + 1}^{m}z^{\pars{n - m}/2 - 1}\,\dd z \\[3mm]&=2^{-m - 1}\,\ic \int_{-1}^{0}\pars{x + 1}^{m}\pars{-x}^{\pars{n - m}/2 - 1} \exp\pars{\ic\pi\bracks{{n - m \over 2} - 1}}\,\dd x \\[3mm]&\mbox{}+ 2^{-m - 1}\,\ic \int_{0}^{-1}\pars{x + 1}^{m}\pars{-x}^{\pars{n - m}/2 - 1} \exp\pars{-\ic\pi\bracks{{n - m \over 2} - 1}}\,\dd x \\[3mm]&=2^{-m - 1}\,\ic \int_{0}^{1}\pars{1 - x}^{m}x^{\pars{n - m}/2 - 1} \exp\pars{\ic\pi\bracks{{n - m \over 2} - 1}}\,\dd x \\[3mm]&\mbox{}- 2^{-m - 1}\,\ic \int_{0}^{1}\pars{1 - x}^{m}x^{\pars{n - m}/2 - 1} \exp\pars{-\ic\pi\bracks{{n - m \over 2} - 1}}\,\dd x \\[3mm]&=2^{-m - 1}\ic\braces{2\ic\sin\pars{\pi\bracks{{n - m \over 2} - 1}}} \int_{0}^{1}x^{\pars{n - m}/2 - 1}\pars{1 - x}^{m}\,\dd x \end{align}

$$ \color{#c00000}{\int_{-\pi/2}^{\pi/2}\cos^{m}\pars{x}\expo{\ic nx}\,\dd x} =2^{-m}\sin\pars{{n - m \over 2}\,\pi}{\rm B}\pars{{n - m \over 2},m + 1}\,,\qquad \Re\pars{n} > \Re\pars{m} > -1 $$ where $\ds{{\rm B}\pars{x,y} \equiv \int_{0}^{1}t^{x - 1}\pars{1 - t}^{y - 1}\,\dd t}$ is the Beta Function $\pars{~\mbox{with}\ \Re\pars{x}, \Re\pars{y} > 0~}$ which has the property $\ds{{\rm B}\pars{x,y} = {\Gamma\pars{x}\Gamma\pars{y} \over \Gamma\pars{x + y}}}$. $\ds{\Gamma\pars{z}}$ is the Gamma Function.

Then \begin{align} &\color{#c00000}{\int_{-\pi/2}^{\pi/2}\cos^{m}\pars{x}\expo{\ic nx}\,\dd x} =2^{-m}\sin\pars{{n - m \over 2}\,\pi}\, {\Gamma\pars{\bracks{n - m}/2}\Gamma\pars{m + 1} \over \Gamma\pars{\bracks{n + m}/2 + 1}}\tag{1} \end{align} By using the Gamma function Euler Reflection Formula $\ds{\Gamma\pars{z}\Gamma\pars{1 - z} = {\pi \over \sin\pars{\pi z}}}$ we find: $$ \sin\pars{{n - m \over 2}\,\pi}\Gamma\pars{n - m \over 2} ={\pi \over \Gamma\pars{1 + \bracks{m - n}/2}} $$ such that $\pars{1}$ is reduced to $$\color{#00f}{\large% \int_{-\pi/2}^{\pi/2}\cos^{m}\pars{x}\expo{\ic nx}\,\dd x ={\pi \over 2^{m}}\, {\Gamma\pars{1 + m} \over \Gamma\pars{1 + \bracks{m + n}/2}\,\Gamma\pars{1 + \bracks{m - n}/2}}} $$