First time here? Check out the FAQ!

Ask Your Question
1

File imports for polynomial rings in sage

asked 14 years ago

ae gravatar image

updated 10 years ago

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.

Preview: (hide)

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 ( 14 years ago )

4 Answers

Sort by » oldest newest most voted
2

answered 14 years ago

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.

Preview: (hide)
link
1

answered 14 years ago

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.

Preview: (hide)
link

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 ( 14 years ago )

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

William Stein gravatar imageWilliam Stein ( 14 years ago )
1

answered 10 years ago

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.

Preview: (hide)
link
0

answered 7 years ago

slelievre gravatar image
Preview: (hide)
link

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: 14 years ago

Seen: 1,663 times

Last updated: Dec 09 '17