Ask Your Question
1

How do I convert from unicode to a polynomial?

asked 2019-12-11 15:54:55 +0100

bori gravatar image

Hi,

I have a raw_input like

y = raw_input()

And if I write for example x+2 in the input I get u'x+2' as y.

How can I convert it to a simple x+2 polynomial?

sage: y = raw_input() x+2

sage: a u'x+2'

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-12-12 10:35:50 +0100

eric_g gravatar image

updated 2019-12-12 10:37:15 +0100

Simply pass the string to the polynomial ring you want to consider:

sage: R.<x> = PolynomialRing(QQ)
sage: R
Univariate Polynomial Ring in x over Rational Field
sage: p = R(u'x + 2')
sage: p
x + 2
sage: p.degree()
1
sage: p in R
True

Note that p = R(u'x + 2') is nothing but a special case of SageMath general scheme to construct an element E from its parent P:

sage: E = P(D)

where D is some data to initialize the element.

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: 2019-12-11 15:54:55 +0100

Seen: 108 times

Last updated: Dec 12 '19