# How to compute sum with non consecutive indices in Maple?

Suppose we need to compute the sum in Maple,

$\sum_{i = 0}^{10} 2^i$,

We can use the command,

sum(2^i, i = 0 .. 10)


Now, what if the indices are not consecutive like i = 0, 1, 2, 3, 4, [no 5], 6, 7, 8, 9, 10?

I tried sum(2^i, i = {0 .. 4, 6 .. 10}) but no luck.

• Perhaps this is a better site for this question. – Miguelgondu Jan 3 '15 at 23:39

You should use the command "add" for instance

$$\rm {add}( 2^i, i=[0,1,2,5,6,9,10] )=1639.$$

Type in maple worksheet the following command $>?list$ to read about "list".

• Thanks. If part of the sequence is consecutive, is there a way to use .. operator to generate that partial consecutive sequence then combine it with the rest of the whole sequence? – swoopin_swallow Jan 3 '15 at 23:49
• @divingswallow: Try to use the sequence command in maple to generate the partial sequences, for example $\rm{seq} ( j, j=0..4 )$. – Mhenni Benghorbal Jan 3 '15 at 23:55
• Thank you, it works; add(2^i, i = [seq(j, j = 0 .. 4), seq(k, k = 6 .. 10)]) = 2015. Happy new year!! – swoopin_swallow Jan 4 '15 at 0:00
• @divingswallow: Good job! You are very welcome. – Mhenni Benghorbal Jan 4 '15 at 0:11
• Use the dollar sign operator for a briefer command: add(2^i, i= [\$1..4, \$6..10]) – Carl Love Jan 4 '15 at 21:27

I think you can use

sum(2^i, i = 0 .. 10)-2^5