summation over tuple of symbols

124 views
Skip to first unread message

Nova Munch

unread,
Aug 4, 2014, 1:30:38 AM8/4/14
to sy...@googlegroups.com
hello.

i have a tuple of symbols, a where a is (a_0, a_1, a_2, a_3, a_4)

i want to call:
>> summation(a[i], (i, 0, 4))

but python returns a TypeError that the indices must be integers, not Symbol. 

this is more of a python constraint instead of Sympy. but is there some workaround to it?

thanks folks!

Sudhanshu Mishra

unread,
Aug 4, 2014, 2:40:44 AM8/4/14
to sy...@googlegroups.com
Hi Nova

Since `a` is a python tuple, you can not access its elements by passing a symbol as index.

`summation` can be used like this:

>>> summation(2*i - 1, (i, 1, n))

Hope this helps.

​Regards​
​Sudhanshu Mishra​


--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/70299343-3cca-4274-80c7-24505ce47816%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sergey Kirpichev

unread,
Aug 4, 2014, 10:23:09 AM8/4/14
to sy...@googlegroups.com
Hmm.  I have no idea of what you want, but...

In [32]: A = IndexedBase('A')

In [33]: n=Symbol('n', integer=True)

In [34]: Sum(A[n],(n,0,2))
Out[34]:
  2      
 ___     
 ╲       
  ╲   A[n]
  ╱      
 ╱       
 ‾‾‾     
n = 0    

In [35]: _.doit()
Out[35]: A[0] + A[1] + A[2]

Nova Munch

unread,
Aug 4, 2014, 8:04:03 PM8/4/14
to sy...@googlegroups.com
hello! 

yes. i think thats very close to what i am looking for. 

thank you!
Reply all
Reply to author
Forward
0 new messages