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}]

Mathematica graphics

However, when called like this Integrate gives zero

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

Mathematica graphics

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.

  • 1
    $\begingroup$ 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 :) $\endgroup$ – anderstood Mar 2 '18 at 0:06
  • $\begingroup$ @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. $\endgroup$ – Nasser Mar 2 '18 at 0:54
  • $\begingroup$ 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.) $\endgroup$ – Daniel Lichtblau Mar 2 '18 at 19:15
  • 1
    $\begingroup$ Returning no result instead of a generically correct result would be a really bad thing to do. $\endgroup$ – Daniel Lichtblau Mar 3 '18 at 15:51
  • 1
    $\begingroup$ 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$. $\endgroup$ – J. M. will be back soon Mar 4 '18 at 15:54

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

(*  "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}  *)
  • $\begingroup$ 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. $\endgroup$ – Michael E2 Mar 2 '18 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.