Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

enter image description here

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.

share|improve this question
2  
With respect to your bonus: did you already look up Regularization in the docs? – J. M. Mar 20 at 2:00
    
Indeed, thank you – nazikus Mar 20 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}]

Mathematica graphics

I've just discovered UpValues and am finding questions that suit it quite regularly.

Hope this helps.

share|improve this answer

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:

finite sum infinite sum

share|improve this answer
    
"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 at 9:56
    
@Edmund, I'd chalk it up to nonstandard evaluation within Defer[]. TracePrint[] seems to show how things proceed. – J. M. Mar 20 at 14:04

How about this?:

Clear@seriesExpanded; 
seriesExpanded[expr_, iter : {_, _, _, ___} ..] := 
 Row[If[First@# === "+", Delete[#, 1], #] &@
  Flatten@Replace[
    Flatten@Table[expr, iter], {a : (_?Negative | _?Negative _) :> {"-", -a}, 
     a_ :> {"+", 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}]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.