Ask Your Question
1

Polynomials with coefficients in Zp - python SyntaxError

asked 2015-12-05 14:17:37 +0100

Onox gravatar image

Hi,

I am trying to create ℤₚ[x], the set of polynomials with coefficients in ℤₚ, with the following syntax :
Zp = Integers(p)
PRZp.<x> = Zp[]

This works fine in the sage interpreter, but in a python file I get a syntax error at the "<" character. How can I solve this ? I've tried alternatives, like PRZp = PolynomialRing(Zp, 'x'), but this fails too with a "NameError: name 'x' is not defined" when I define a polynomial expression after that.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2015-12-05 21:54:41 +0100

tmonteil gravatar image

Let me first answer the secont part. When you write PRZp = PolynomialRing(Zp, 'x'), you only define PRZp to be a polynomial ring with the symbol 'x' as an indeterminate, but you did not let the PYthon variable x to point to the polynomial undeterminate 'x'. For this, you can for example do:

sage: x = PRZp.gen()

or

sage: PRZp.inject_variables()
Defining x

Now, for the first part, the notation PRZp.<x> = Zp[] is indeed not Pythonic, so it works because of Sage preparser that transforms it to something meaningful to Python:

sage: preparse('PRZp.<x> = Zp[]')
"PRZp = Zp['x']; (x,) = PRZp._first_ngens(1)"

So, you can either writh that in your python file, or, if you want to keep the same syntax, you should use a Sage file instead ot a Python file, so that Sage preparser get applied first. The way to do this is to rename yourfile.py into yourfile.sage.

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

1 follower

Stats

Asked: 2015-12-05 14:17:37 +0100

Seen: 757 times

Last updated: Dec 05 '15