# Expand series unevaluated

I'm newbie in Mathematica. I'd like to obtain nice and verbose output for any series calculation.

For example, given a simple sequence n*(-1)^(n-1) and hypothetical function NoEval, I see it as follows:

sequence = n*(-1)^(n-1);
range = {n, 1, 10};
seriesFormula = NoEval[Sum[sequence, range]];
seriesExpanded = Sum[NoEval[sequence], range];
seriesSum = Sum[sequence, range];
Row[{seriesFormula, seriesExpanded, seriesSum}, "="]


expected output is: Is there a simple way to do this?

I know there are Hold*, Unevaluated, Inactivate, etc, but I just couldn't get a concise solution without multiple definitions of the same series. I'd like to define target series just once, and then get different symbolic and/or numerical representations of it.

Thank you

Bonus question (answered) Is it possible to make Mathematica sum divergent series (Cesàro, Borel, etc) like:

1 - 1 + 1 - 1 ... = 1/2 or 1 - 2 + 4 - 8 ... = 1/3

Update: Regularization parameter of Sum function does the job for divergent series.

• With respect to your bonus: did you already look up Regularization in the docs? – J. M.'s discontentment Mar 20 '16 at 2:00
• Indeed, thank you – nazikus Mar 20 '16 at 2:03

With UpValues and Inactive:

noEval /:
Sum[noEval[expr_],
(indx : ({_Symbol, _Integer} | {_Symbol, _Integer, _Integer} | {_Symbol, _Integer, _Integer, _Integer}) ..)] :=
Inactive[Sum][expr, indx] ==
Inactive[Plus] @@ Flatten@Table[expr, indx] ==
Sum[expr, indx]


Then

Sum[noEval[n*(-1)^(n - 1)], {n, 1, 10}]

Sum[noEval[i + j], {i, 1, 5}, {j, 1, 2}] I've just discovered UpValues and am finding questions that suit it quite regularly.

Hope this helps.

Not as sophisticated as the other solutions, but it's good for at least single sums:

Options[displaySum] = {"Terms" -> 10};

displaySum[a_, {n_, n1_, n2_}, opts : OptionsPattern[]] /; n1 <= n2 :=
Module[{nf = Min[n1 + OptionValue["Terms"] - 1, n2]},
Row[{Defer[Sum[a, {n, n1, n2}]],
Composition[Defer, Plus] @@
Append[Table[a, {n, n1, nf}], If[n2 === ∞, "⋯", Nothing]],
Sum[a, {n, n1, n2}]}, "="]]


Some examples:  • "Terms" is very nice. I find it a bit confusing that Defer@*Plus @@ _ displays as expected but Defer[Plus @@ _ displays the deferred Apply instead of the terms. Aren't both pieces of code doing the same thing? – Edmund Mar 20 '16 at 9:56
• @Edmund, I'd chalk it up to nonstandard evaluation within Defer[]. TracePrint[] seems to show how things proceed. – J. M.'s discontentment Mar 20 '16 at 14:04

Clear@seriesExpanded; 