Let's concentrate on the inner multiple sum. First note that we know d
because it is given from the outer sum. If we want to write the expression
$$-\exp\left[k_1+k_2+\ldots+k_d\right]$$
in Mathematica we could do this very easy. First we create the list {k[1],k[2],...,k[d]}
and remember, that this is internally nothing more than List[k[1],k[2],...,k[d]]
. If we would now replace the List
head with Plus
, then it is exactly what we want. For this we can use Apply
which is written @@
in infix notation. That leaves how to create the {k[1],k[2],...,k[d]}
list. Here we can use Table
or Array
or we think of it as _mapping the function k
over the list {1,2,...,d}
. This can be written as
k /@ Range[d]
for a known d
. All together this gives
Exp[-Plus @@ k /@ Range[d]]
Now we need to build a multiple Sum
, summing over d
different k
. Again, this can be done in several ways. One way is to create a function which gets as arguments the indices for a Sum
f = Function[Sum[1, ##]]
I only use 1 in the sum for the sake of simplicity.
You may ask now, what this ##
is: it's the sequence of all arguments given to f. So lets try it:
In[63]:= {Sum[1, {3}], f[{3}]}
Out[63]= {3, 3}
In[62]:= {Sum[1, {3}, {5}], f[{3}, {5}]}
Out[62]= {15, 15}
Seems to work. The only think which is left now, is to create the ranges {k[i],1,q}
where i
is always a concrete number. Here we can use again the trick with Range
and for a known d
this gives a list of ranges:
{k[#], 1, q} & /@ Range[d]
(* For d = 3 for instance
Out[64]= {{k[1], 1, q}, {k[2], 1, q}, {k[3], 1, q}}
*)
The last thing is to think about, that our Sum
function needs a Sequence
of arguments and the above is a List
. But we already solved the problem of replacing the List
with something different by using @@
. This gives all together:
Sum[Exp[-Plus @@ k /@ Range[d]], ##] & @@ ({k[#], 1, q} & /@ Range[d])
Don't be afraid of the expression, because now you know every single piece of it and you know what every piece does. You could try it by for instance
With[{d = 4},
Sum[Exp[-Plus @@ k /@ Range[d]], ##] & @@ ({k[#], 1, q} & /@ Range[d])
]
and get $$\frac{e^{-4 q} \left(e^q-1\right)^4}{(e-1)^4}$$ or you use this to plant it directly into your outer sum
mysum[p_Integer] :=
Sum[Exp[-d]*
Sum[Exp[-Plus @@ k /@ Range[d]], ##] & @@ ({k[#], 1, q} & /@
Range[d]), {d, 1, p}]
I put it into a function mysum
, because p
needs to be a number to make all the Range
s work. Now you should check mysum[2]
$$\frac{e^{-2 q-2} \left(e^q-1\right)^2}{(e-1)^2}+\frac{e^{-q-1}
\left(e^q-1\right)}{e-1}$$