Ask Your Question
1

Convert expression to univariate polynomial over symbolic ring properly

asked 2015-01-19 11:57:47 +0200

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.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-01-19 12:19:40 +0200

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,)
edit flag offensive delete link more
0

answered 2015-01-19 12:31:19 +0200

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,)
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-01-19 11:57:47 +0200

Seen: 2,313 times

Last updated: Jan 19 '15