Ask Your Question
1

Convert expression to univariate polynomial over symbolic ring properly

asked 10 years ago

petRUShka gravatar image

If I create polynomial like this

R.<x> = SR[]
var('a')
f = a*x^3+1

I get such list of variables

sage: f.variables()
(x,)

But how to convert existing expression to univariate polynomial over symbolic ring?

When I do like this

var('a')
f = a*x^3+1
P.<x> = SR[]

I get following output

sage: P(f).variables()
()
sage: SR['x'](f).variables()
()

How to convert f to polynomial in a right way with x as variable.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
0

answered 10 years ago

slelievre gravatar image

You could do this:

sage: a, x = var('a x')
sage: f = a * x^3 + 1
sage: P.<x> = SR[]
sage: ff = sum(c*x^j for (c,j) in f.coefficients(x))
sage: ff.parent()
Univariate Polynomial Ring in x over Symbolic Ring
sage: ff.variables()
(x,)
Preview: (hide)
link
0

answered 10 years ago

tmonteil gravatar image

Here is a possibility:

sage: var('a x')
(a, x)
sage: f = a*x^3+1
sage: f.parent()
Symbolic Ring
sage: q = f.polynomial(SR)
sage: q
a*x^3 + 1
sage: q.parent()
Multivariate Polynomial Ring in a, x over Symbolic Ring
sage: q.variables()
(a, x)

So, at this point you got a polynomial with coefficients in SR but with both a and x as polynomial variables. Hence, it is not possible to send it into the ring R:

sage: R.<x> = SR[]
sage: R(q)
TypeError: not a constant polynomial

So, you have to substitute the polynomial variable a of q into the symbolic variable a:

sage: s = q.subs(a=SR.var('a'))
sage: s.parent()
Multivariate Polynomial Ring in a, x over Symbolic Ring
sage: P = R(s)
sage: P
a*x^3 + 1
sage: P.parent()
Univariate Polynomial Ring in x over Symbolic Ring
sage: P.variables()
(x,)
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

1 follower

Stats

Asked: 10 years ago

Seen: 2,647 times

Last updated: Jan 19 '15