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]

  • $\begingroup$ Why is integral alternatively capitalized? $\endgroup$
    – Feyre
    May 24, 2017 at 8:39
  • $\begingroup$ I get, FullSimplify[integral, n \[Element] Integers && m \[Element] Integers] /. n -> m.. Power::infy: Infinite expression 1/0 encountered. >> as expected. $\endgroup$
    – Feyre
    May 24, 2017 at 8:40
  • $\begingroup$ @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. $\endgroup$ May 24, 2017 at 8:44
  • $\begingroup$ @Feyre see edit, does that clarify? $\endgroup$ May 24, 2017 at 8:47
  • 3
    $\begingroup$ Mathematica will usually only generate generically correct answers. $\endgroup$ May 24, 2017 at 8:53


Browse other questions tagged or ask your own question.