Ask Your Question
0

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 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 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 ( 2010-08-19 05:05:38 -0500 )edit

3 answers

Sort by ยป oldest newest most voted
2

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 publish link more
1

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 my.py with all the needed extra python code will be produced and loaded automatically.

edit flag offensive delete publish link more
1

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 publish 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 ( 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 ( 2010-08-19 07:19:15 -0500 )edit

Your Answer

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

Add Answer

[hide preview]

Stats

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

Seen: 132 times

Last updated: Jun 28