# 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. will be back soon 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. will be back soon Mar 20 '16 at 14:04

Clear@seriesExpanded;
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.744276225566864, "perplexity": 8807.120615243912}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-51/segments/1575541310866.82/warc/CC-MAIN-20191215201305-20191215225305-00394.warc.gz"}