# Should integrate have given zero for this integral?

Here is an integrand

 integrand = Cos[x] Sin[x]^2 Cos[n x];


One can see it is not zere for all integer positive n as follows

 Table[Integrate[integrand, {x, 0, 2 Pi}], {n, 1, 5}]


However, when called like this Integrate gives zero

 Assuming[Element[n, Integers] && n > 0,Integrate[integrand, {x, 0, 2 Pi}]]


This seems to be related to Mathematica giving a general result, rather than specific result? But I think it is a little misleading. Since the result is not valid for all n>0.

Should Mathmatica have given zero above? Is there a way to tell Mathematica not to do this? Does your version of Mathematica give zero as well?

Mathematica 11.2 on windows.

• related I'm pretty sure I've seen a dupe here but did not find it yet. edit Oh, that was the one I was thinking about: 165991. I'm pretty sure you've seen it before :) – anderstood Mar 2 '18 at 0:06
• @anderstood that is why I seem to remember I've had this problem before. But I forgot. But notice that none of the answers given are really satisfactory in general. This is because they require the user to always suspect the result from Integrate is not valid and to do special post processing. But this is not the way to do CAS. Is one supposed to see the result is not valid in general each time and handle it in special way? The best solution is that Integrate itself to always give the correct answer. I do not think 0 is correct answer here. – Nasser Mar 2 '18 at 0:54
• I get the impression that essentially the same question is being asked in multiple guises. Is there some expectation that the answer might change? (I suppose at some point the answer might indeed change but that would be mentioned in release notes.) – Daniel Lichtblau Mar 2 '18 at 19:15
• Returning no result instead of a generically correct result would be a really bad thing to do. – Daniel Lichtblau Mar 3 '18 at 15:51
• I'll note that a similar problem happens with FourierCosCoefficient[]: FourierCosCoefficient[Cos[x] Sin[x]^2, x, n, FourierParameters -> {-1, 1}] returns 0 without any indication that something's amiss, even if one obtains different results for $n=1$ and $n=3$. – J. M. will be back soon Mar 4 '18 at 15:54

## 1 Answer

As has been stated on this site before, the use of Assuming is less safe than the use of Assumptions:

\$Version
(*  "11.2.0 for Mac OS X x86 (64-bit) (September 11, 2017)"  *)

Integrate[Cos[x] Sin[x]^2 Cos[n x], {x, 0, 2 Pi}, Assumptions -> n ∈ Integers]
(*  -((2 n Sin[2 n π])/(9 - 10 n^2 + n^4))  *)

Table[Limit[%, n -> n0], {n0, 1, 5}]
(*  {π/4, 0, -(π/4), 0, 0}  *)

• Funny, I forgot I also answered 165991 along similar lines. The only difference here is the reference to Daniel Lichtblau's discussion of Assuming vs. Assumptions. – Michael E2 Mar 2 '18 at 2:36