5
$\begingroup$

This is a big problem if you do anything with a Fourier Series. This statement:

Assuming[Element[{m, n}, Integers], Integrate[Cos[m*x]*Cos[n*x], {x, 0, 2 Pi}]]

returns 0. But the right answer is non-zero whenever $|m|=|n|$.

This other arrangement:

Integrate[Cos[m*x]*Cos[n*x], {x, 0, 2 Pi},  Assumptions -> Element[{m, n}, Integers]]

gives an answer that goes $0/0$ when $|m|=|n|$.

I know there are generic and non-generic answers, but this is pretty dang simple. And Fourier series work is pretty common!

What I need is a solution that will work when I didn't know there was a Cos[n x] in it:

Integrate[Integrate[Cos[m*x]*f[x], {x, 0, 2 Pi},  Assumptions -> Element[{m}, Integers]]

If my f[x] happens to have a Cos[] in it, Mathematica will give me wrong answers, unless I anticipate the situation and code around it. How could I do that?

$\endgroup$
5
  • 1
    $\begingroup$ Mathematica returns generic results. You are trying to get a non-generic result. You will likely need to change your assumptions to force Mathematica to consider the non-generic case. $\endgroup$
    – KAI
    Commented Nov 17, 2014 at 22:24
  • 3
    $\begingroup$ 1 2 3 $\endgroup$ Commented Nov 17, 2014 at 22:47
  • 3
    $\begingroup$ No, it's not simple. Not at all. I suspect it would require a considerable amount of special case pattern matching to implement any subset of integrals of this type. Seen next comment for why current method cannot do these. $\endgroup$ Commented Nov 17, 2014 at 23:45
  • 2
    $\begingroup$ Currently much assumption handling is accomplished under the hood with Refine and Simplify. In a case like this, assumptions of integrality will have the predictable result. Here is a smaller variant: Refine[Sin[m*Pi]/m, Assumptions->Element[m,Integers]] Out[5]= 0. If this does not return 0, then Refine is effectively useless. And if it does, then Refine cannot do better than support a generic result, when used in Integrate. $\endgroup$ Commented Nov 17, 2014 at 23:46
  • 1
    $\begingroup$ @DanielLichtblau Okay, not that I understand why the bug exists, how do I work around it? How do I make my integrals of products of sums of trigonometric functions not come out wrong? $\endgroup$ Commented Nov 30, 2014 at 20:38

2 Answers 2

6
$\begingroup$

At least with Mathematica version 10.0.1, using option Assumptions does provide a correct answer:

Integrate[Cos[m*x]*Cos[n*x], {x, 0, 2 Pi}, 
   Assumptions -> Element[{m, n}, Integers]] 

(* (Sin[2*(m - n)*Pi]/(m - n) + Sin[2*(m + n)*Pi]/(m + n))/2

I don't know why this form of the input leads to a different result than the form using Assuming.

$\endgroup$
4
  • $\begingroup$ that form also goes 0/0 when |m|==|n|. $\endgroup$ Commented Nov 17, 2014 at 22:48
  • $\begingroup$ Yes, it's an indeterminate form. Limit is a good function for handling those. $\endgroup$ Commented Nov 17, 2014 at 22:51
  • 2
    $\begingroup$ Sure it 'goes 0/0', but so what? It is still correct. Sin[x]/x =1 at x=0. $\endgroup$ Commented Nov 18, 2014 at 7:36
  • 1
    $\begingroup$ @murray, this is why Assuming gives something different: mathematica.stackexchange.com/questions/42114/… $\endgroup$
    – Szabolcs
    Commented Nov 19, 2014 at 0:05
1
$\begingroup$

Very helpful discussion in progress about work-arounds HERE:

How to code around known MMa special-case failures?

$\endgroup$
2
  • $\begingroup$ In that case, I shall close this one as a duplicate. Thanks for letting us know. $\endgroup$
    – Verbeia
    Commented Dec 2, 2014 at 0:20
  • 1
    $\begingroup$ @Verbeia Cool. The follow-up question elicited way more helpful responses. $\endgroup$ Commented Dec 2, 2014 at 0:54

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