# Simplify with integer assumptions gives wrong answer

Can somebody help me understand why Mathematica returns the following?

In[1]= f=Cos[j x]Cos[(n-2b-k)x]Cos[2(b-ell)x];
In[2]= Simplify[Integrate[f,{x,0,\[Pi]}],
Assumptions->b\[Element]Integers
&&ell\[Element]Integers
&&n\[Element]Integers
&&k\[Element]Integers
&&j\[Element]Integers]
Out[2]= 0
In[3]= g = f /. {j -> 2, b -> 3, n -> 11, ell -> 0, k -> 1};
In[4]= Integrate[g, {x, 0, \[Pi]}];
Out[4]= \[Pi]/4;


Thanks.

This example shows the need to be carefull when integrating trig-functions with integer parameters.

One way out is to use "GenerateConditions->True", like @Shinrei proposed.

If there is an error message with your special parameter values, add a small epsilon to each and build the Limit epsilon->0 and you get the right result.

 int = Integrate[f, {x, 0, Pi}, GenerateConditions -> True]

int /. {j -> 2, b -> 3, n -> 11, ell -> 0, k -> 1}

(*   During evaluation of In[4]:= Power::infy: Infinite expression 1/0 encountered. >>

During evaluation of In[4]:= Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered. >>

Out[4]=  Indeterminate    *)

Limit[int /. ({j -> 2, b -> 3, n -> 11, ell -> 0,
k -> 1} /. (u_ -> v_) -> (u -> v + Epsilon)), Epsilon -> 0]

(*   \[Pi]/4    *)

Integrate[f, x]/. {j -> 2, b -> 3, n -> 11, ell -> 0, k -> 1}


Returns:

Power::infy: Infinite expression 1/0 encountered. Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered.

so this values for j,b,n,ell,k should be treated as a separate case

• I'm struggling to see what the point of assuming something is an integer is then. – nth Apr 29 '17 at 7:17
• But expression like \$Assumptions = b \[Element] Integers && ell \[Element] Integers && n \[Element] Integers && k \[Element] Integers && j \[Element] Integers; f = Cos[j x] Cos[(n - 2 b - k) x] Cos[2 (b - ell) x]; Integrate[f, {x, 0, \[Pi]}, GenerateConditions -> True] will not give a user the chance to know that something is wrong. A user might be interested in usage of Integer assumptions in notebook for other purposes. And it looks like user have to cancel such assumptions each time when Integrate is supposed to be called. – Shinrei Apr 29 '17 at 7:24
• to @jth I think that the goal is to simplify expressions like Sin[n Pi] – Ryhor Apr 29 '17 at 7:30