Ask Your Question

File imports for polynomial rings in sage

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

ae gravatar image

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

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 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


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 +0200 )edit

4 Answers

Sort by ยป oldest newest most voted

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

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

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

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


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 +0200 )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 +0200 )edit

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

mmarco gravatar image

Rename your file to my.sage

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

edit flag offensive delete link more

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

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


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

Seen: 1,505 times

Last updated: Dec 09 '17