# Creating a polynomial from a string with symbolic constants

Below is some code that does the following. First, define R to be the univariate polynomial ring Q_2[x], and let f(x) be the polynomial x^2 - 2 in this ring. Then let K be the totally ramified quadratic extension defined by this polynomial, and call its generator a. Let S be the polynomial ring K[y]. Then I would like to define a polynomial y + a in S. This works find if I write f1 = S(y+a), but it fails if I try f2 = S('y + a'). However, I need to be able to define my polynomial from a string as in the f2 case. Can anyone help?

R.<x> = Qp(2,100)[]
f = R(x^2 - 2)
K.<a> = Qp(2,100).ext(f)
S.<y> = K[]

# The next line works
f1 = S(y + a)
# The next one throws an error
f2 = S('y + a')

edit retag close merge delete

Why do you need to define a polynomial from a string? Sounds like it could be an XY problem.

( 2022-07-02 08:13:15 +0200 )edit

Sort by ยป oldest newest most voted

There might be room for improvement there.

Here are two possibilities to work around this limitation.

sage: f2 = S(eval('y + a'))
sage: f2 = eval('S(y + a)')

more