# Simplify a huge expression with limited memory

I would like to perform some analytical sums such as the following

Sum[Collect[Sum[d2[r + k m, 0, r] z^(2 r + k m) I2B[(2 r + k m)/2 + 3, 2]
, {r,0, Infinity}], m, Simplify], {m, 0, Infinity}]


where (inserting Collect speeds it up)

I2B[d_,s_]:=(2 s + 1)/(4 Pi^2) (6 Exp[-1/2 t] -
Exp[-(d - 1) t] ((d - 3/2)^3 t^3 + 3 (d - 3/2)^2 t^2 +
6 (d - 3/2) t + 6))/(t^4 (1 - Exp[-t])) - (2 s +
1)^3/(16 Pi^2) (Exp[-t/2] -
Exp[-(d - 1) t] ((d - 3/2) t + 1))/(t^2 (1 - Exp[-t]))


and

d2[a_, b_, c_] := (1 + a) (1 + b) (1 + c) (1 + (a + b)/2) (1 + (b + c)/2) (1 + (a + b + c)/3)


I'm running this on Mathematica 8.0 installed on a Windows 7 Machine with 4 GB memory. The resulting expression is very long and when I want to FullSimplify the expression, I get the following message:

No more memory available.Mathematica kernel has shut down.Try quitting other applications and then retry.

I was wondering whether there are some clever ways to simplify the expression without causing memory leak.

• Do any constraints exist for your variables. For instance, are any known to be Real? Jul 19 '15 at 15:31
• Yes there are. Sorry I did not mention them. z is a real number between zero and one. k is a positive integer and t is a positive real number. Jul 20 '15 at 0:53
• It appears that positive k and Abs[z] <1 are all that is needed for convergence. Try the solution I proposed below, and let me know how it worked. Good luck. Jul 20 '15 at 0:58
• Thanks for your answer! It is indeed faster now. However I still have trouble simplifying the resulting expression. (as you mentioned in your answer as well) Do you have any suggestions on that part? Jul 20 '15 at 1:16
• Are you talking about the output of Sum[is, {m, 0, Infinity}] or of Sum[cl[[n + 1, g + 1]] f[n, g/2], {g, 0, 2}, {n, 0, 6}]? Trying to Simplify the former is hopeless, I believe. Jul 20 '15 at 1:23

The OP correctly notes that Collect with Simplify is essential for computing this double sum in a reasonable amount of time, if at all. It is straightforward to find that the LeafCount of the inner sum only without using Collect is 721809. With it, the size of the inner sum drops to 21158. However, we can do much better. Instead, define the inner sum as

is = Collect[Sum[d2[r + k m, 0, r] z^(2 r + k m) I2B[(2 r + k m)/2 + 3, 2],
{r, 0, Infinity}] /. Exp[a_] :> Exp[Expand[a]], {m, Exp[-k m t/2]}, Simplify]


In other words, Collect over both m and Exp[-k m t/2]. Doing so reduces the LeafCount to 2875. This factor of seven reduction probably is sufficient to perform the double sum.

Sum[is, {m, 0, Infinity}]


Using Mathematica 10.1, my computer never used more than 10% of its 8 GB of memory, and the total computation took only about 15 minutes. However, the LeafCount of the resulting expression is 29140583, and Simplify bogs down trying to reduce it.

An alternative approach to the outer sum is to decompose the outer sum into 21 sums of the form

Sum[m^n Exp[-g k m t] z^(k m), {m, 0, Infinity}]


By experimentation, I found that this expression is equal to

f[n_, g_] := (D[E^(k t)/(E^(k t) - z^k), {t, n}]/(-k)^n) /. t -> g t


Then, the solution can be found as follows.

cl = (CoefficientList[is, {m, Exp[-k m t/2]}] // Simplify) /. z^(k m) -> 1;
Sum[cl[[n + 1, g + 1]] f[n, g/2], {g, 0, 2}, {n, 0, 6}]


with a LeafCount of only 5767.

Performing any of the 21 outer sums with GenerateConditions -> True, for instance,
Sum[m^3 Exp[-k m t] z^(k m), {m, 0, Infinity}, GenerateConditions -> True]