3
$\begingroup$

The following two codes give conflicting answers, when integrating $\sin(k\pi x)\sin(2n\pi x)$ from $0$ to $1$, where both $k$ and $n$ are positive integers.

Code 1 assumes that $k$,$n$ are independent integers:

Integrate[
  Sin[k*Pi*x]*Sin[2*n*Pi*x], {x, 0, 1}, 
  Assumptions -> {k ∈ Integers, n ∈ Integers}]

The result given by mathematica is 0.

Code 2 assumes that $k=2n$ and $n$ is integer:

Integrate[
  Sin[k*Pi*x]*Sin[2*n*Pi*x], {x, 0, 1},
  Assumptions -> {n ∈ Integers,k = 2*n}]

The result is 1/2.

The result of Code 2 should be included in that of Code 1. It seems that Code 1 doesn't manage to give a universal result. Isn't Code 1 supposed to give a universal result? if not, how to get one?

$\endgroup$
3
  • $\begingroup$ With 11.3, for Code 1, I get (2 n Cos[2 n \[Pi]] Sin[k \[Pi]] - k Cos[k \[Pi]] Sin[2 n \[Pi]])/( k^2 \[Pi] - 4 n^2 \[Pi]), which is either zero or Indeterminate for integer variables. After repairing the = that should be == in Code 2, I get 1/8 (4 - Sin[4 n \[Pi]]/(n \[Pi])),which is 1/2 for integer n. $\endgroup$
    – John Doty
    Commented May 26, 2018 at 11:12
  • $\begingroup$ With Version 8.0 , I get thes same aus @John Doty for code 1 , call it int1 , and for Limit[int1, k -> 2 n, Assumptions -> k \[Element] Integers && n \[Element] Integers] the desired result 1/2 . $\endgroup$
    – Akku14
    Commented May 26, 2018 at 11:29
  • $\begingroup$ But with ClearAll[n, k, x]; Assuming[Element[k, Integers] && Element[n, Integers], Integrate[Sin[k Pi x]*Sin[2*n Pi x], {x, 0, 1}]] I get 0 as result. Maybe in Version 8.0 Assuming worked different than Assumptions. It seems in higher versions they operate the same way. $\endgroup$
    – Akku14
    Commented May 26, 2018 at 11:37

1 Answer 1

8
$\begingroup$

Mathematica works on the general case, not the specific, when it comes to simplifications. Let try to find what is going on. Mathematica says that

\begin{align*} I & =\int_{0}^{1}\sin\left( k\pi x\right) \sin\left( 2n\pi x\right) dx\\ & =\frac{1}{2\pi}\left( \frac{\sin\left( \left( k-2n\right) \pi\right) }{k-2n}-\frac{\sin\left( \left( k+2n\right) \pi\right) }{k+2n}\right) \end{align*}

Now, when you said that $k,n$ are integers, then $k-2n$ is also an integer, as well as $k+2n$. Therefore the above becomes zero. Which agrees with what Mathematica gives. Mathematica will not consider the special case here of what happenes if $k=2n$, since this is a special case of $k$.

Now lets look at what happens when you give specific case when $k=2n$. Then the result above becomes

\begin{align*} I & =\frac{1}{2\pi}\left( \frac{\sin\left( \left( 2n-2n\right) \pi\right) }{2n-2n}-\frac{\sin\left( \left( 2n+2n\right) \pi\right) }{2n+2n}\right) \\ & =\frac{1}{2\pi}\left( \frac{\sin\left( m\pi\right) }{m}-\frac{\sin\left( 4n\pi\right) }{4n}\right) \end{align*}

Where $m=2n-2n$. (did not want to put zero, since need to take limit). Then the above becomes

$$ I=\frac{1}{2\pi}\frac{\sin\left( m\pi\right) }{m}-\frac{1}{2\pi}\frac {\sin\left( 4n\pi\right) }{4n} $$

Since $n$ is integer, then the second term above is zero. (notice also, here there is special case, what if $n=0$? Then you'll get 1/2 also for the second term and the whole thing becomes zero, like case 1, But since $n=0$ is special case, it is not considered). Now the above becomes

$$ I=\frac{1}{2\pi}\frac{\sin\left( m\pi\right) }{m} $$

But $\lim_{m\rightarrow0}\frac{\sin m\pi}{m}=\pi$, hence the above becomes \begin{align*} I & =\frac{1}{2\pi}\pi\\ & =\frac{1}{2} \end{align*}

Which is what Mathematica gives.

ClearAll[n,k,x]
Assuming[ Element[k,Integers]&&Element[n,Integers],
          Simplify[Integrate[Sin[k Pi x]*Sin[2*n Pi x],{x,0,1}]]]
(*0*)


Assuming[ Element[n, Integers] && k == 2 n, 
     Simplify[Integrate[Sin[k Pi x]*Sin[2*n Pi x], {x, 0, 1}]]]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ So, we can't totally trust Mathematica. Because in some cases, we may be not aware of the existence of specific simplifications and Mathematica ignores them as well. $\endgroup$
    – Charles6
    Commented May 27, 2018 at 2:44
  • 1
    $\begingroup$ @HC6 Yes, one needs to be careful I think when using such assumptions. I once spend hrs on a HW problem, because I was using result obtain from M that Assuming[Element[n, Integers] && n > 0, Integrate[Cos[x]* Sin[x]^2*Cos[n*x], {x, 0, 2 Pi}]] is zero. But it is not zero for all n. I posted this at sci.math.symbolic and it generated lots of discussion. Some CAS system do not even support assumptions. FriCAS for example. My advice, is to always double check CAS result using some other means. Nothing is perfect. $\endgroup$
    – Nasser
    Commented May 27, 2018 at 3:09
  • $\begingroup$ ... Still, for most cases, Mathematica's assumptions work very well. It can be very useful. I do not think I could use a CAS that does not support assumptions for example, that would be too limited. $\endgroup$
    – Nasser
    Commented May 27, 2018 at 3:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.