Ask Your Question
1

How do I convert from unicode to a polynomial?

asked 2019-12-11 08:54:55 -0500

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 03:35:50 -0500

eric_g gravatar image

updated 2019-12-12 03:37:15 -0500

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 08:54:55 -0500

Seen: 27 times

Last updated: Dec 12 '19