Expand series unevaluated - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-22T04:47:48Z https://mathematica.stackexchange.com/feeds/question/110529 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/110529 9 Expand series unevaluated nazikus https://mathematica.stackexchange.com/users/38478 2016-03-20T01:40:20Z 2016-03-20T05:06:36Z <p>I'm newbie in Mathematica. I'd like to obtain nice and verbose output for any series calculation.</p> <p>For example, given a simple sequence <code>n*(-1)^(n-1)</code> and <strong>hypothetical</strong> function <code>NoEval</code>, I see it as follows:</p> <pre><code>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}, "="] </code></pre> <p>expected output is:</p> <p><a href="https://i.stack.imgur.com/614Gf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/614Gf.png" alt="enter image description here"></a></p> <p>Is there a simple way to do this?</p> <p>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.</p> <p>Thank you</p> <hr> <p><s>Bonus question</s> (answered) Is it possible to make Mathematica sum divergent series (<a href="https://en.wikipedia.org/wiki/Ces%C3%A0ro_summation" rel="nofollow noreferrer">Cesàro</a>, Borel, etc) like: </p> <p><code>1 - 1 + 1 - 1 ... = 1/2</code> or <code>1 - 2 + 4 - 8 ... = 1/3</code></p> <p>Update: <code>Regularization</code> parameter of <code>Sum</code> function does the job for divergent series.</p> https://mathematica.stackexchange.com/questions/110529/-/110532#110532 9 Answer by Edmund for Expand series unevaluated Edmund https://mathematica.stackexchange.com/users/19542 2016-03-20T03:07:48Z 2016-03-20T03:07:48Z <p>With <code>UpValues</code> and <code>Inactive</code>:</p> <pre><code>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] </code></pre> <p>Then</p> <pre><code>Sum[noEval[n*(-1)^(n - 1)], {n, 1, 10}] Sum[noEval[i + j], {i, 1, 5}, {j, 1, 2}] </code></pre> <p><img src="https://i.stack.imgur.com/1Amyj.png" alt="Mathematica graphics"></p> <p>I've just discovered <code>UpValues</code> and am finding questions that suit it quite regularly.</p> <p>Hope this helps.</p> https://mathematica.stackexchange.com/questions/110529/-/110536#110536 5 Answer by xzczd for Expand series unevaluated xzczd https://mathematica.stackexchange.com/users/1871 2016-03-20T03:47:11Z 2016-03-20T03:47:11Z <p>How about this?:</p> <pre><code>Clear@seriesExpanded; seriesExpanded[expr_, iter : {_, _, _, ___} ..] := Row[If[First@# === "+", Delete[#, 1], #] &amp;@ Flatten@Replace[ Flatten@Table[expr, iter], {a : (_?Negative | _?Negative _) :&gt; {"-", -a}, a_ :&gt; {"+", a}}, {1}], " "] display[a__] := HoldForm@Sum[a] == seriesExpanded[a] display[(-1)^(i + j) Subscript[a, i, j] j/i, {i, 1, 2}, {j, 2, 5}] </code></pre> <p><a href="https://i.stack.imgur.com/CmdmO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/CmdmO.png" alt="enter image description here"></a></p> https://mathematica.stackexchange.com/questions/110529/-/110538#110538 8 Answer by J. M. will be back soon for Expand series unevaluated J. M. will be back soon https://mathematica.stackexchange.com/users/50 2016-03-20T05:06:36Z 2016-03-20T05:06:36Z <p>Not as sophisticated as the other solutions, but it's good for at least single sums:</p> <pre><code>Options[displaySum] = {"Terms" -&gt; 10}; displaySum[a_, {n_, n1_, n2_}, opts : OptionsPattern[]] /; n1 &lt;= 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}]}, "="]] </code></pre> <p>Some examples:</p> <p><img src="https://i.stack.imgur.com/NC2dI.png" alt="finite sum"> <img src="https://i.stack.imgur.com/cbc8m.png" alt="infinite sum"></p>