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?
Answer
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}] *)
Comments
Post a Comment