Ask Your Question

File imports for polynomial rings in sage

asked 2010-08-19 04:41:02 -0500

ae gravatar image

updated 2014-06-09 12:11:31 -0500

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 05:05:38 -0500 )edit

3 answers

Sort by ยป oldest newest most voted

answered 2010-08-19 05:21:34 -0500

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 05:50:28 -0500

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 05:53:33 -0500 )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 07:19:15 -0500 )edit

answered 2014-06-28 21:41:44 -0500

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

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 04:41:02 -0500

Seen: 212 times

Last updated: Jun 28 '14