Ask Your Question
0

How to find the degree of a polynomial

asked 2021-03-30 23:05:53 +0200

anonymous user

Anonymous

Is there a function that takes in a polynomial and returns its degree? For example: suppose we have the ring R = PolynomialRing(ZZ, 'x'), and the polynomial p = (x-1)*(x-2). The degree function I'm looking for should return 2 when applied to p. Does such a function exist??

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-03-31 09:14:19 +0200

slelievre gravatar image

updated 2021-03-31 10:15:10 +0200

Polynomials (and symbolic expressions) have a degree method.

Beware that even after defining R as in the question, x is still a "symbolic variable" in the "symbolic ring".

In a fresh Sage session:

sage: R = PolynomialRing(ZZ, 'x')  # defines R but not x

sage: x.parent()
Symbolic Ring

sage: q = (x - 1) * (x - 2)
sage: q
(x - 1)*(x - 2)

sage: q.parent()
Symbolic Ring

Symbolic expressions have a degree method that gives the degree with respect to any chosen variable.

sage: q.degree(x)
2

Declare x as the indeterminate in R.

sage: x = R.gen()

Then:

sage: x.parent()
Univariate Polynomial Ring in x over Integer Ring

sage: p = (x - 1) * (x - 2)
sage: p
x^2 - 3*x + 2

sage: p.parent()
Univariate Polynomial Ring in x over Integer Ring

Or:

sage: p = R(q)
sage: p
x^2 - 3*x + 2

sage: p.parent()
Univariate Polynomial Ring in x over Integer Ring

To get the degree, use the degree method (no need to specify that it is with respect to x now, since p is a univariate polynomial):

sage: p.degree()
2

Sage slightly extends Python's syntax to enable defining R and x at once. For example:

sage: R.<x> = PolynomialRing(ZZ)

is equivalent to:

sage: R = PolynomialRing(ZZ, 'x')
sage: x = R.gen()
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: 2021-03-30 23:05:53 +0200

Seen: 3,044 times

Last updated: Mar 31 '21