Summation

81 views
Skip to first unread message

Kim, In-Jae

unread,
Oct 8, 2009, 9:33:41 AM10/8/09
to sage-s...@googlegroups.com
Hello,

I was wondering how I can write the polynomial, 1+x+x^2 + ...+x^10, using summation.
I tried
sage: var('i,x')
sage: sum(x^i, (i,0,10)),

but I got the following error message:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/sage/sagenb/sage_notebook/worksheets/matrix89/26/code/6.py", line 7, in <module>
sympy.sum(x**i, (i,_sage_const_0 ,_sage_const_10 ))
File "", line 1, in <module>

NameError: name 'sympy' is not defined

Thank you.

In-Jae

kcrisman

unread,
Oct 8, 2009, 9:55:16 AM10/8/09
to sage-support
This is on the way; see http://trac.sagemath.org/sage_trac/ticket/3587.
However, for now you will get various errors. I am surprised that you
got a Sympy error; did you use Sympy along the way? Since you are
coming from the notebook, perhaps you accidentally were using it
somehow...

I get the following:

sage: var('i,x')
(i, x)
sage: sum(x^i,(i,0,10))
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)

/Users/...__sage_init_sage_0.py in <module>()

TypeError: 'sage.symbolic.expression.Expression' object is not
iterable

- kcrisman

Kim, In-Jae

unread,
Oct 8, 2009, 9:59:21 AM10/8/09
to sage-s...@googlegroups.com
Kcrisman,

You are right.
I was trying some different ways to do the job and the error message indeed from the command using sympy.
The following is the error message that I got when I used sage notebook.

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/sage/sagenb/sage_notebook/worksheets/matrix89/26/code/2.py", line 7, in <module>
sum(x**i, (i,_sage_const_0 ,_sage_const_10 ))
File "", line 1, in <module>

TypeError: 'sage.symbolic.expression.Expression' object is not iterable


Thank you.
________________________________________
From: sage-s...@googlegroups.com [sage-s...@googlegroups.com] On Behalf Of kcrisman [kcri...@gmail.com]
Sent: Thursday, October 08, 2009 8:55 AM
To: sage-support
Subject: [sage-support] Re: Summation

Jonathan Bober

unread,
Oct 8, 2009, 1:09:44 PM10/8/09
to sage-s...@googlegroups.com
The trac ticket listed in the other email is relevant for symbolic
summation, when you want to represent 1 + x^2 + ... + x^n for n a
symbolic variable. It looks like you just want to do this for a fixed
number, such as n = 10. For this, you can write

sage: sum(x^i for i in (0..10))
x^10 + x^9 + x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1

or

sage: sum(x^i for i in (0..100))
x^100 + x^99 + x^98 + x^97 + x^96 + x^95 + x^94 + x^93 + x^92 + x^91 +
x^90 + x^89 + x^88 + x^87 + x^86 + x^85 + x^84 + x^83 + x^82 + x^81 +
x^80 + x^79 + x^78 + x^77 + x^76 + x^75 + x^74 + x^73 + x^72 + x^71 +
x^70 + x^69 + x^68 + x^67 + x^66 + x^65 + x^64 + x^63 + x^62 + x^61 +
x^60 + x^59 + x^58 + x^57 + x^56 + x^55 + x^54 + x^53 + x^52 + x^51 +
x^50 + x^49 + x^48 + x^47 + x^46 + x^45 + x^44 + x^43 + x^42 + x^41 +
x^40 + x^39 + x^38 + x^37 + x^36 + x^35 + x^34 + x^33 + x^32 + x^31 +
x^30 + x^29 + x^28 + x^27 + x^26 + x^25 + x^24 + x^23 + x^22 + x^21 +
x^20 + x^19 + x^18 + x^17 + x^16 + x^15 + x^14 + x^13 + x^12 + x^11 +
x^10 + x^9 + x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1

Kim, In-Jae

unread,
Oct 8, 2009, 1:14:20 PM10/8/09
to sage-s...@googlegroups.com
Jon,

Thank you.
That was my question.

________________________________________
From: sage-s...@googlegroups.com [sage-s...@googlegroups.com] On Behalf Of Jonathan Bober [jwb...@gmail.com]
Sent: Thursday, October 08, 2009 12:09 PM
To: sage-s...@googlegroups.com
Subject: [sage-support] Re: Summation
Reply all
Reply to author
Forward
0 new messages