I am caught with a little trouble to figure out an easier way to set up and solve a summation of a function of several variables. I just realized that Mathematica doesnt allow me to add a constraint in the summation operation. My problem is that, the summation should be performed over the ordered partition set of a number.

An example, will illustrate the problem definition a lot better. Suppose I want to compute the sum of a function of variables over all variables such that, the sum of the index variables always equal to a constant .

Clearly, the indices here runs over all the ordered partitions of the number . Since is not that big a number, we can simply write these partitions by hand and somehow get the job done. Let us say denote the ordered partitions and unordered partitions of the number by and respectively.

. The ordered partition will have the permutations of each of these on the three positions! So and are different sets of whereas, they are considered as one in . The summation needs to be carried over the ordered partition list . Since both and grow pretty big with even modest , the job of manual summation is not that appealing. I really hoped mathematica to aid me here. Unfortunately, I don’t see a way out here, other than the painful individual partition sum. Anyway, for the curious reader, the sum I attempt are of the following types:

typical values for is and is around . If any enthused reader finds a way/trick, I will be happy to sponsor a coffee 🙂 (Sorry at this recession time, nothing more 😦 sadly…).

In fact, the first one is easy (Interestingly, I just found a way, while typesetting the blog). I can do a differential with respect to and then scale it to get the requisite sum. It can be written as follows:

Second one is the trouble maker 😦

Oh man! power of a coffee. As I am typing this on a moody Lausanne swiss weather, here comes the trick. I just made a coffee and that seemed to have worked. I guess I can apply a similar trick to the second one too. Basically, we can split them into two expressions and then write each as differential versions of a multinomial sum. Here it is:

Amazingly, we can simplify both to get a simple looking expression. I am glad! Here is what I finally got:

### Like this:

Like Loading...

*Related*

## 1 comment

Comments feed for this article

March 12, 2009 at 7:38 pm

yehuda ben-shimolHi,

The easiest way is to use an If statement, that means that sum would iterate over all possible values and will sum only the relevant values

Sum[If[x+y+z==10,1,0]f[x,y,z],{x,0,10},{y,0,10},{z,0,10}]

For a non determined f it returns

f[0, 0, 10] + f[0, 1, 9] + f[0, 2, 8] + f[0, 3, 7] + f[0, 4, 6] +

f[0, 5, 5] + f[0, 6, 4] + f[0, 7, 3] + f[0, 8, 2] + f[0, 9, 1] +

f[0, 10, 0] + f[1, 0, 9] + f[1, 1, 8] + f[1, 2, 7] + f[1, 3, 6] +

f[1, 4, 5] + f[1, 5, 4] + f[1, 6, 3] + f[1, 7, 2] + f[1, 8, 1] +

f[1, 9, 0] + f[2, 0, 8] + f[2, 1, 7] + f[2, 2, 6] + f[2, 3, 5] +

f[2, 4, 4] + f[2, 5, 3] + f[2, 6, 2] + f[2, 7, 1] + f[2, 8, 0] +

f[3, 0, 7] + f[3, 1, 6] + f[3, 2, 5] + f[3, 3, 4] + f[3, 4, 3] +

f[3, 5, 2] + f[3, 6, 1] + f[3, 7, 0] + f[4, 0, 6] + f[4, 1, 5] +

f[4, 2, 4] + f[4, 3, 3] + f[4, 4, 2] + f[4, 5, 1] + f[4, 6, 0] +

f[5, 0, 5] + f[5, 1, 4] + f[5, 2, 3] + f[5, 3, 2] + f[5, 4, 1] +

f[5, 5, 0] + f[6, 0, 4] + f[6, 1, 3] + f[6, 2, 2] + f[6, 3, 1] +

f[6, 4, 0] + f[7, 0, 3] + f[7, 1, 2] + f[7, 2, 1] + f[7, 3, 0] +

f[8, 0, 2] + f[8, 1, 1] + f[8, 2, 0] + f[9, 0, 1] + f[9, 1, 0] +

f[10, 0, 0]

which is what you need

yehuda

reposted from http://forums.wolfram.com/student-support/topics/20170