Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How can I combine or separate sums in Mathematica in the way that Together or Expand work for rational expressions?

For example, how does one transform from

$$\text{Sum}\left[\frac{a}{\sqrt{n!}},\{n,0,\infty \}\right]+\text{Sum}\left[\frac{b}{\sqrt{n!}},\{n,0,\infty \}\right]$$

to

$$\text{Sum}\left[\frac{a+b}{\sqrt{n!}},\{n,0,\infty \}\right]$$

and vise versa?

share|improve this question
    
This feels like a duplicate. Does anyone recall an earlier question like this? –  Mr.Wizard Mar 3 '13 at 14:01

2 Answers 2

up vote 3 down vote accepted

If we don't mind using rules to merge the sums, here's one that can handle prefactors, different variables and limits (assuming the upper limits are always infinite):

mergesums = (ca_. Sum[a_, an_] + cb_. Sum[b_, bn_]) :> 
  With[{sum = Simplify[
       ca a + (cb b /. bn[[1]] -> an[[1]] + bn[[2]] - an[[2]])]}, 
    Sum[sum, an]] /; an[[3]] == bn[[3]] == \[Infinity]

(Sum[a/Sqrt[m!], {m, 0, \[Infinity]}] + 
   2 Sum[b/Sqrt[(n - 1)!], {n, 1, \[Infinity]}]) //. mergesums
(* Sum[(a + 2*b)/Sqrt[m!], {m, 0, Infinity}] *)
share|improve this answer

This solution works for combining any number of separate sums:

Sum[a/Sqrt[n!], {n, 0, Infinity}] + 
Sum[b/Sqrt[n!], {n, 0, Infinity}] + 
Sum[c/Sqrt[n!], {n, 0, Infinity}] //. Sum[x_, z_] + Sum[y_, z_] :> Sum[Simplify[x + y], z]

(*outputs: Sum[(a + b + c)/Sqrt[n!], {n, 0, Infinity}]*)

Here, we apply a rule to combine two sums together. The ReplaceRepeated (//.) is used to apply the combination rule as long as there are separate sums left. Note that in the present form, my solution only works if the summation variable (here n) is the same in all the sums.

And here is how to separate the sums:

Sum[(a + b + c)/Sqrt[n!], {n, 0, Infinity}] /. Sum[x_, y_] :> (Sum[#, y] & /@ Expand@x)

(*outputs: Sum[a/Sqrt[n!], {n, 0, Infinity}] + 
           Sum[b/Sqrt[n!], {n, 0, Infinity}] + 
           Sum[c/Sqrt[n!], {n, 0, Infinity}]*)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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