2

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.

Jason B.
  • 68,381
  • 3
  • 139
  • 286
sebqas
  • 605
  • 4
  • 15
  • 1
    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 09 '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 09 '16 at 13:26
  • 1
    @JasonB. Indeed it could, but can we be certain without more details from the OP that that is really the question? – m_goldberg Mar 09 '16 at 13:28
  • @m_goldberg - no, we can't. OP's question seems pretty clear (to me) to be "Why do I get the wrong answer from this integral when I use Assuming?" But that's pretty localized, and is related to the question of why you get the right answer using the Integrate[...., Assumptions->...] form. – Jason B. Mar 09 '16 at 13:31
  • @JasonB. If you feel confident you understand the question well enough to answer, then please do so. – m_goldberg Mar 09 '16 at 13:34
  • @m_goldberg I never said I could answer, I just helped to clarify the question. – Jason B. Mar 09 '16 at 13:56
  • obviously it is a serious bag and should be reported to Wolfram, this kind of integral was involved in many places in my complicated calculation which appeared to be wrong now – sebqas Mar 09 '16 at 14:25
  • 3
    "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.'s missing motivation Mar 09 '16 at 14:29
  • 1
    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 09 '16 at 14:35

1 Answers1

2

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] == 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];
bad = Pick[e0, goodQ, False];

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.

Michael E2
  • 235,386
  • 17
  • 334
  • 747