# Getting wrong result when Integrating under an assumption [duplicate]

The simple integral

$$\int_0^b \cos\left(\frac{2\pi m(y-\eta)}{b}\right) \cos\left(\frac{2\pi \eta}{b}\right)\mathrm{d}\eta$$

can be easily evaluated by Mathematica as,

Integrate[
Cos[(2 m π (y - η))/b] Cos[(2 π η)/b], {η, 0, b}]
(* (b m Cos[(m π (b - 2 y))/b] Sin[m π])/((-1 + m^2) π) *)


Due to the $\sin(m \pi)$ term this is zero whenever $m$ is an integer, except when $m^2=1$, when it evaluates to a something different,

Limit[(
b m Cos[(m π (b - 2 y))/b] Sin[m π])/((-1 + m^2) π),
m -> 1]
(* 1/2 b Cos[(2 π y)/b] *)


This much is clear, but when I try to use Assuming on this integral, taking m to be an integer, it does not recognize this case and instead returns simply 0.

Assuming[m ∈ Integers,
Integrate[
Cos[(2*Pi*m*(y - η))/b]*Cos[(2*Pi*η)/b], {η, 0, b}]]
(* 0 *)


the same occurs for Simplify[]

 Simplify[Integrate[Cos[(2*Pi*η)/b]*
Cos[(2*Pi*m*(y - η))/b], {η, 0, b}],
Assumptions -> Element[m, Integers]]
(* 0 *)


An even more minimal example of the problem would be

Simplify[ Sin[m π]/((-1 + m^2) π),
Assumptions -> m ∈ Integers]
(* 0 *)


Why is this? Is this a bug?

Interestingly, but somewhat unrelated to the above question, if instead of using Assuming, you provide an Assumptions to Integrate, via Integrate[ Cos[(2 m π (y - η))/b] Cos[(2 π η)/b], {η, 0, b}, Assumptions -> {m ∈ Integers}], it does not make this mistake.

• There doesn't seem to be a question in this post. Only the announcement of a problem without sufficient details for anyone to make out what you want to ask. – m_goldberg Mar 9 '16 at 13:20
• @m_goldberg - the question could be rephrased to ask why Integrate[ Cos[(2 m π (y - η))/b] Cos[(2 π η)/b], {η, 0, b}, Assumptions -> {m ∈ Integers}] gives a different result than Assuming[m ∈ Integers, Integrate[ Cos[(2 m π (y - η))/b] Cos[(2 π η)/b], {η, 0, b}]] – Jason B. Mar 9 '16 at 13:26
• @JasonB. Indeed it could, but can we be certain without more details from the OP that that is really the question? – m_goldberg Mar 9 '16 at 13:28
• "obviously… should be reported…" - so, did you actually send a bug report to them? Altho WRI employees sometimes post here, this is not an official channel for bug reports. – J. M. will be back soon Mar 9 '16 at 14:29
• These problems with trig integrals have a long history here on the site, and the difference between Assuming and Assumptions has been discussed, too. The integral is generically correct, which is all some solvers, like Solve, guarantee. However Reduce, which is usually rigorous, gets the second wrong (i0 equals the 1st integral): (1) Reduce[y == i0 && m \[Element] Integers] vs. (2) Reduce[y == i0 && m \[Element] Integers, y]. – Michael E2 Mar 9 '16 at 14:35

Here's workaround, which is what one sometimes has to look for in those tricky trig integrals:

i0 = Assuming[m ∈ Integers,
Simplify@
DSolveValue[{A'[η] ==
Cos[(2*Pi*m*(y - η))/b]*Cos[(2*Pi*η)/b], A == 0},
A[η], η] /. η -> b
];

e0 = i0 /. {m - 1 -> Sin[(-1 + m) π]/Sinc[(m - 1) Pi]/Pi,
m + 1 -> Sin[(1 + m) π]/Sinc[(m + 1) Pi]/Pi} /.
t : (h : Cos | Sin | Csc)[x_] :> TrigExpand[h[Expand[x]]] //
Expand;

goodQ = Quiet@Check[(# /. m -> 1) 0; True, False] & /@ List @@ e0;
good = Pick[e0, goodQ];

Simplify[
good +
((1/(2 Pi)) Simplify@FunctionExpand[2 Pi bad] /. {m^2 - 1 :>
Sin[(-1 + m) π]/Sinc[(m - 1) Pi]/Pi*
Sin[(1 + m) π]/Sinc[(m + 1) Pi]/Pi})
]
% /. {{m -> -1}, {m -> 1}} // Simplify

(*

-(1/8) b ((3 Cos[(m π (b - 2 y))/b] +
Cos[(m π (b + 2 y))/b]) Sinc[(1 + m) π] +
Sinc[(-1 + m) π] (3 Cos[(m π (b - 2 y))/b] +
Cos[(m π (b + 2 y))/b] -
4 m π Sin[(2 m π y)/b] Sinc[(1 + m) π]))

{1/2 b Cos[(2 π y)/b], 1/2 b Cos[(2 π y)/b]}

*)


Probably too much work: Sometimes it seems difficult to get Mathematica to do the things in trigonometry that are "obvious" to a human.