# Polynomials with coefficients in Zp - python SyntaxError

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 close merge delete

Sort by » oldest newest most voted

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.

more