Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

How would I translate this code into a mathematical formula?

myset={4,2,5,26,8,1,2}, d0=[], d1=[], dnp1=[]
for i in range(myset):
    if   i==0: d0=myset[i]
    elif i==1: d1=myset[i]
    else:      dnp1+=myset[i]

(a $\LaTeX$ example would be great)

share|improve this question
    
I have received this solution over IRC, it is useful but being able to more explicitly do an if elif type thing would be better: $$ d1 = myset_1, d0 = myset_0, dnp1 = \sum_{i >= 2} myset_i $$ –  A T Jul 6 '12 at 16:50
    
If $i \in \{4, 2, 5, 26, 8, 1, 2\}$ then how come you test for $i = 0$?! $i$ will never be zero. –  user2468 Jul 6 '12 at 17:35

1 Answer 1

Here's one solution (I devised myself):

$$ \sum_{i}^{\text{myset}} d_0=\{ \unicode{x27E6}i==0\unicode{x27E7}\ i \},\ d_1=\{ \unicode{x27E6}i==1\unicode{x27E7}\ i \},\ d_{np1}=\{ \unicode{x27E6}i>1\unicode{x27E7}\ i \} $$

share|improve this answer
    
Please delete this answer, edit your question and this info inside your question. –  user2468 Jul 6 '12 at 17:36
    
@J.D. you know it's kosher to answer your own question, right? –  J. M. Jul 6 '12 at 17:39
    
@J.M. Sure. But this question is two folded (1) how do I formulate it? (2) is my following attempt correct? Answering (2) is much easier if all OP's attempts are in 1 place: the question body. –  user2468 Jul 6 '12 at 17:41

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.