# Combining and separating sums

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?

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

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}] *)

-

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}]*)

-