1 | initial version |
Unless you declare x
as the indeterminate in R
,
it is still a "symbolic variable" in the "symbolic ring".
sage: x.parent()
Symbolic Ring
sage: p = (x - 1) * (x - 2)
sage: p.parent()
Symbolic Ring
Declare x
as the indeterminate in R
.
sage: R = PolynomialRing(ZZ, 'x')
sage: x = R.gen()
Then:
sage: x.parent()
Univariate Polynomial Ring in x over Integer Ring
sage: p = (x - 1) * (x - 2)
sage: p.parent()
Univariate Polynomial Ring in x over Integer Ring
To get the degree, use the degree
method:
sage: p.degree()
2
2 | No.2 Revision |
Unless you declare Polynomials (and symbolic expressions) have a degree
method.
Beware that even after defining R
as in the question,
x
as the indeterminate in is still a "symbolic variable" in the "symbolic ring".R
,
it
In a fresh Sage session:
sage: R = PolynomialRing(ZZ, 'x') # defines R but not x
sage: x.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: R = PolynomialRing(ZZ, 'x')
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: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()