# Why does Mathematica neglect this special case for a double integral? [duplicate]

I was running the following script in Mathematica

f = Sin[n*Pi*q]*Sin[m*Pi*p]*Exp[I*b*(q - p)] + Sin[n*Pi*q]*Sin[m*Pi*p]*Exp[-I*b*(q - p)] integral = Integrate[Integrate[f, {p, 0, q}], {q, 0, 1}] SimpleIntegral = Simplify[integral, n ∈ Integers && m ∈ Integers] SimpleIntegral /. n -> m

and noticed that the resulting double integral was incorrect for the special case n=m. In fact the result is singular at m=n.

My question is why does Mathematica not account for this special case? Is there any way to force it to distinguish the cases? Right now I have to compute the m=n case separately and then synthesize my own formula from the two results.

For clarity what I really want to compute is the integral $$\int_0^1 \int_0^q \left[\sin(n\pi q)\sin(m\pi p)e^{ib(q - p)} + \sin(n\pi q)\sin(m\pi p)e^{-ib(q - p)}\right]$$

under the condition that $n$ and $m$ are integers. $n$ and $m$ may or may not be equal.

To see why this integral is indeed wrong for the special case n=m try the following code, where the assumption is put at the start and that gives a finite result

f = Sin[n*Pi*q]*Sin[n*Pi*p]*Exp[I*b*(q - p)] + Sin[n*Pi*q]*Sin[n*Pi*p]*Exp[-I*b*(q - p)] integral = Integrate[Integrate[f, {p, 0, q}], {q, 0, 1}] SimpleIntegral = Simplify[integral, n ∈ Integers]

• Why is integral alternatively capitalized? Commented May 24, 2017 at 8:39
• I get, FullSimplify[integral, n \[Element] Integers && m \[Element] Integers] /. n -> m.. Power::infy: Infinite expression 1/0 encountered. >> as expected. Commented May 24, 2017 at 8:40
• @Feyre oops, the capitalized 'integral' was a typo. I corrected it, the script should run now. About the other comment: yep, I get that too. That is really not expected though, how is the integral with n=m infinite? Also I tried setting n=m at the start and then compute the integral, that gave a different and finite result. Commented May 24, 2017 at 8:44
• @Feyre see edit, does that clarify? Commented May 24, 2017 at 8:47
• Mathematica will usually only generate generically correct answers. Commented May 24, 2017 at 8:53