Message Boards Message Boards

0
|
6717 Views
|
10 Replies
|
1 Total Likes
View groups...
Share
Share this post:
GROUPS:

Sigma Notation when Indexing over non-consecutive values

Posted 9 years ago

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$

POSTED BY: wojtek potocki
10 Replies
Posted 9 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 BY: wojtek potocki

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 BY: Murray Eisenberg

After looking at the output from evaluating

TraditionalForm[Hold[Sum[a[i], {i, Select[Range[0, 6], EvenQ]}]]]

it appears that the following will do the sort of thing you want:

enter image description here

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 BY: Murray Eisenberg

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 BY: Michael Rogers
Posted 9 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 BY: wojtek potocki

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 BY: Michael Rogers
Posted 9 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 BY: wojtek potocki
Posted 9 years ago

Why not use

Sum[2 i, {i, 0, 3}]

POSTED BY: Jim Baldwin
Posted 9 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 BY: wojtek potocki
Posted 9 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$$

POSTED BY: Jim Baldwin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract