Ask Your Question
1

File imports for polynomial rings in sage

asked 2010-08-19 11:41:02 +0100

ae gravatar image

updated 2014-06-09 19:11:31 +0100

slelievre gravatar image

If i type in the following

R.<z1,z2> = PolynomialRing(GF(5),2,"z")

direclty to Sage it accepts it as a polynomial ring. But if i place this in a .py file and load it from this Sage eg sage my.py it gives me a syntax error. I guess i need a module loaded for it to be detected, but which module and hence which command do i need to make Sage accept this ring.

edit retag flag offensive close merge delete

Comments

Could you please edit your question? There are html escaping errors in it. Notice the ampersand gt semicolon? I see the command, but I don't see a question mark or a question in what you originally typed. Thanks.

ccanonc gravatar imageccanonc ( 2010-08-19 12:05:38 +0100 )edit

4 Answers

Sort by ยป oldest newest most voted
2

answered 2010-08-19 12:21:34 +0100

niles gravatar image

I agree, this is hard to read (probably a candidate for "What is broken on this site"). Having said that, I think the question is:

What module do I need to import in my .py file so that the above syntax works as expected?

I guess I don't know this answer, but maybe a workaround: The .< > notation is a shortcut for

R = PolynomialRing(ZZ,2,'z1,z2')

(z1,z2) = R.gens()

and the latter works when loaded from a .py file.

edit flag offensive delete link more
1

answered 2010-08-19 12:50:28 +0100

William Stein gravatar image

The answer; it is impossible to make the notation:

R.<z1,z2> = ZZ[]

work in a .py file, since .py files must be valid Python, and the above isn't. The workaround by niles above is the way to go.

edit flag offensive delete link more

Comments

I tried to edit and get a big traceback -- there my thus be a bug in askbot that prevents editing some posts.

William Stein gravatar imageWilliam Stein ( 2010-08-19 12:53:33 +0100 )edit

Oh, to use the PolynomialRing command in a .py file, do from sage.rings.all import PolynomialRing

William Stein gravatar imageWilliam Stein ( 2010-08-19 14:19:15 +0100 )edit
1

answered 2014-06-29 04:41:44 +0100

mmarco gravatar image

Rename your file to my.sage

Then, when you run sage my.sage it will be automatically preparsed. A my.py with all the needed extra python code will be produced and loaded automatically.

edit flag offensive delete link more
0

answered 2017-12-09 19:23:07 +0100

slelievre gravatar image
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2010-08-19 11:41:02 +0100

Seen: 1,597 times

Last updated: Dec 09 '17