# Trigonometric integral with assumptions fails

Consider the following integral

Assuming[Element[{n, m}, Integers] && n >= 0, Integrate[Cos[ϕ]^n Exp[I ϕ m], {ϕ, 0, 2 π}]]


0

The above output is clearly wrong since, with explicit integers plugged in, we get:

Table[Integrate[ Cos[ϕ]^n Exp[I ϕ m], {ϕ, 0, 2 π}], {n, 0, 5}, {m, -10, 10}] // MatrixForm From which one can deduce that the true result of the integral should be

(1 + (-1)^(m + n)) π Binomial[n, (m + n)/2]/2^n


Is there a way to make Mathematica return this correct result instead of zero? How should I be doing this?

EDIT

Analytically there is no problem to arrive at the correct result:

$$\int\limits_0^{2\pi}\cos^n\phi\ e^{im\phi}\ d\phi=2^{-n}\sum_{k=0}^n\left({{n}\atop{k}}\right)\int\limits_0^{2\pi} e^{i(n+m-2k)\phi} d\phi$$

here the integral is clearly only non-zero if we have $k=\frac{m+n}{2}$, but this can only hold for integer $k$ if $m+n$ is even. Therefore, the result is proportional to $(1+(-1)^{m+n})/2$. Then plugging $k=\frac{m+n}{2}$ in, we get

$$\frac{(1+(-1)^{m+n})}{2}\cdot2^{-n}\left({{n}\atop{\frac{m+n}{2}}}\right)2\pi=(1+(-1)^{m+n})\pi\left({{n}\atop{\frac{m+n}{2}}}\right)2^{-n}$$

which is exactly the answer deduced above.

Sure, one could follow these steps in Mathematica instead of LaTeX and arrive at the correct output. But isn't the whole point of using Mathematica to speed up such calculations? Still hoping that a one line Mathematica command exists that gives the result without requiering input of prior knowledge for how to arrive at the result in a pedestrian way.

• This is suspect indeed; compare it with the very different non-zero result one gets when assumptions are specified within Integrate: Integrate[Cos[ϕ]^n Exp[I ϕ m], {ϕ, 0, 2 π}, Assumptions -> {Element[{n, m}, Integers], n >= 0}] which, at least at a cursory glance, does not appear to be equivalent to your result. – MarcoB Jul 3 '18 at 18:41
• @MarcoB The result I get for this input is actually identical to zero as well. Even though Mathematica prints some terms, it is proportional to (-1 + E^(2 I m \[Pi])) which is zero for any integer m. – Kagaratsch Jul 3 '18 at 18:45
• If I define the result in @MarcoB 's comment as h[m_, n_] = %, then it seems I get the correct results by doing the limits like this: Limit[h[3, n], n -> 3] $\Rightarrow\frac{\pi}{4}$, etc. But the limit can't be done purely symbolically. – Jens Jul 4 '18 at 4:36
• @Jens I see, very interesting observation! – Kagaratsch Jul 4 '18 at 12:10