# Sigma Notation when Indexing over non-consecutive values

Posted 8 years ago
6105 Views
|
10 Replies
|
1 Total Likes
|
 Hello I want to code with Mathematica using the Sigma notation the following mathematical expression: $$\sum_{i=0\text{,i even }}^{6}{i}$$ and expect an answer of 12 (0+2+4+6). I transform this into Mathematica like that:  \!$$\*SubsuperscriptBox[\(\[Sum]$$, $$i = 1 /; \(\(Mod[i, 2]$$$$==$$$$0$$$$\$$\)\), $$6$$]i\) (* MMA returns -(1/2) (-7 + (1 /; Mod[i, 2] == 0)) (6 + (1 /; Mod[i, 2] == 0)) *) Instead of 12 I have an answer that I cannnot evaluate.Of course I could code:  Sum[i, {i, 0, 6, 2}] but this is not a format suitable for being incorporated afterwards into a Latex document. My question : how can I get a correct result by sticking to traditional notation for a sum: $\sum$ ?I have a similar problem when I want to use $\prod$
10 Replies
Sort By:
Posted 8 years ago
 Yes very unexpected but not an orthodox mathematic notation, And it implies that a reader of a document with such a formula understands Mathematica input form too.
Posted 8 years ago
 I don't think a user who wants to deal with such restricted-domain kinds of summations would need to understand InputForm at all, provided only that the sigma-notation form was shown. After discovering it from and InputForm expression, subsequently I used the Classroom Assistant palette as usual, but adjusting the lower- and upper-limits to conform to the discovered form.
Posted 8 years ago
 After looking at the output from evaluatingTraditionalForm[Hold[Sum[a[i], {i, Select[Range[0, 6], EvenQ]}]]]it appears that the following will do the sort of thing you want:In particular, if you replace a[i] by i, you'll get the expected value 12.Interesting is that the condition is placed where the upper limit would normally go. Trying, instead, to use i[Element] Select[Range[0, 6], EvenQ] as the lower limit, and no upper limit, yields a localization error.
Posted 8 years ago
 You might adapt something like this: MakeBoxes[Sum[e_, {i_, a_, b_, 2}], TraditionalForm] := RowBox[{UnderoverscriptBox["\[Sum]", RowBox[{MakeBoxes[i == a, TraditionalForm], ",\[VeryThinSpace]", MakeBoxes[i, TraditionalForm], " even"}], MakeBoxes[b, TraditionalForm]], MakeBoxes[e, TraditionalForm]}] MakeBoxes[Sum[e_, {i_, a_, b_, m_}], TraditionalForm] := RowBox[{UnderoverscriptBox["\[Sum]", RowBox[{MakeBoxes[i == a, TraditionalForm], " (mod ", MakeBoxes[m, TraditionalForm], ")"}], MakeBoxes[b, TraditionalForm]], MakeBoxes[e, TraditionalForm]}] Sum[f[i], {i, 0, n, 2}] // TeXForm (* --> \sum _{i=0\text{,$\,$}i\text{ even}}^n f(i) *) Sum[f[i], {i, 0, n, 3}] // TeXForm (* --> \sum _{i=0\text{ (mod }3)}^n f(i) *) 
Posted 8 years ago
 Thanks. I do not quite understand the use of the the Makeboxes statements unless this one: If I now type Sum[ i, {i, 0, 6,2}] //HoldForm // TraditionalForm I retrieve my original ? expression which I have to ReleaseHold to evaluate. Correct? Does your answer also mean that you cannot natively use in MMA the traditional ? notation such as my first example without Makeboxes statements describing it with the corresponding InputForm thrown in ?
Posted 8 years ago
 Perhaps I misunderstood. I took your goal to be one of output formatting, esp. for TeX. However, your comment to another response makes me think you might be interested in coding TeX-style input. MakeBoxes (as well as Format) formats output only. MakeExpression can be used to turn notebook input into expressions for evaluation. (Everything you type into a notebook is stored in cells in the form of "boxes".) The Notation package can be used to create input notation, too, if that's of interest.
Posted 8 years ago
 Thanks Jim for your answers. I think it is a lot of programming effort for a facility which should be native or will be provided in future releases of MMA (they opened already a door towards what I am looking for but not much). This is more a comment than an answer.
Posted 8 years ago
 Why not useSum[2 i, {i, 0, 3}]
Posted 8 years ago
 (* in reply to your first first reply *) Yes it gives the right answer but you modify my initial expression which is pefectly legible . I was expecting an answer which shows how the even condition in the indexing is coded, perhaps with a pattern with EvenQ. To take another example is it possible to code this expression without enumerating all the allowed successive values of i and j? $$\sum_{i=0,i\notin\mathbb{P}}^{10}\sum_{j=0,j\neq i}^{5}{x_iy_j}$$
Posted 8 years ago
 Sorry, I wasn't trying to be facetious but was more thinking that coding (2i) and (2i+1) for even and odd integers would allow for Simplify or FullSimplify potentially to find more simplified expressions that didn't require a summation notation.So it sounds like from the other responses that you want a simple way to input the restrictions on the indices AND have those display in a readable/visually-pleasing/standard-typesetting format (likely having $j \neq i$ placed right below $j=0$).The only thing I can offer is something like my original comment such that your example above becomes $$\sum _{i=0}^{10} \sum _{j=0}^5 x_i y_j-\sum _{i=0}^5 x_i y_i$$