1
$\begingroup$

It may look like a stupid question, but I was really confused by how double sums works in mathematica:

After simplification, the function actually has nothing to do with n2?

Also, when I manually calculate Kin[1,1], which is n1=n2=1, it should be m1=m2=0. Then Kin[1,1] should be (-1) * B(2,2) * B(2,2) * B(0,0) * (-2) =2, but mathematica gives 4. What is wrong here?

UPDATE1: For copy-and-paste-able code, see here:

Kin[n1_, n2_] = Sum[
           (-1)^(m1 + m2 + 1)*Binomial[n1 + 1, m1 + 2]*
           Binomial[n2 + 1, m2 + 2]*Binomial[m1 + m2, m1]*
          ((m1 - m2)^2 - m1 - m2 - 2), 
                {m1, 0, n1 - 1}, {m2, 0, n2 - 1}]

UPDATE2: Thanks for the answers! I got the desired answer, but I'm still confused by how MMA simplifies the expression of Kin, if I use Simplify:

  Simplify[Sum[
            (-1)^(m1 + m2 + 1)*Binomial[n1 + 1, m1 + 2]*
            Binomial[n2 + 1, m2 + 2]*Binomial[m1 + m2, m1]*
           ((m1 - m2)^2 - m1 - m2 - 2), 
                 {m1, 0, n1 - 1}, {m2, 0, n2 - 1}]]

I still get the result as in Out[15] in the screenshot. Any idea why it goes wrong?

$\endgroup$
  • $\begingroup$ Please post copy-and-paste-able code, properly formatted in code blocks, rather than screenshots of your code. Edit your post by clicking the grey edit button below your post, and click the grey question mark on the right side of the editing toolbar for formatting help. $\endgroup$ – march Apr 29 '16 at 15:48
  • 1
    $\begingroup$ @James, your code does not work when pasted back. Please see here: meta.mathematica.stackexchange.com/q/1584/27951 $\endgroup$ – MarcoB Apr 29 '16 at 16:12
  • $\begingroup$ Thanks guys! Really helpful link! $\endgroup$ – James Apr 29 '16 at 16:43
1
$\begingroup$

I am not sure whether the symbolic calculation is correct, but I would suggest that you don't pre-calculate the value of the sum; rather, let the sum be calculated when the values of $n_1$ and $n_2$ are on hand by using SetDelayed in your definition of K1:

Clear[Kin]
Kin[n1_, n2_] := 
 Sum[(-1)^(m1 + m2 + 1) * Binomial[n1 + 1, m1 + 2] * Binomial[n2 + 1, m2 + 2] *
   Binomial[m1 + m2, m1] * ((m1 - m2)^2 - m1 - m2 - 2), {m1, 0, n1 - 1}, {m2, 0, n2 - 1}]

The calculated value for Kin[1, 1] is then what you expected:

Kin[1, 1]
(* Out: 2 *)

The value of Kin also depends on the value of $n_2$, as you expected:

Kin[1, 2]
(* Out: 4 *)
$\endgroup$
0
$\begingroup$

When you are first defining Kin[n1_,n2_] you are not specifying anything about n1 or n2. For simpler cases MMA returns ConditionalExpression. However, as much I have seen, for complicated evaluation MMA goes with an approximation which is more widely applicable (in your case n1,n2>1).

To bypass this, you can always put Assumptions with your evaluation.

Sum[(-1)^(m1 + m2 + 1)*Binomial[n1 + 1, m1 + 2]*
  Binomial[n2 + 1, m2 + 2]*Binomial[m1 + m2, m1]*((m1 - m2)^2 - m1 - m2 - 2),
 {m1, 0, n1 - 1}, {m2, 0, n2 - 1}, Assumptions -> {n1 ==  1, n2 == 1}]

2

Or you can go with the preassigned values.

Block[{n1 = 1, n2 = 1}, 
Sum[(-1)^(m1 + m2 + 1)*Binomial[n1 + 1, m1 + 2]*
 Binomial[n2 + 1, m2 + 2]*Binomial[m1 + m2, m1]*((m1 - m2)^2 - m1 - m2 - 2),
{m1, 0, n1 - 1}, {m2, 0, n2 - 1}]]

2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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