parent, [is_gen=False]) |
The following examples illustrate creation of elements of polynomial rings, and some basic arithmetic.
First we make a polynomial over the integers and do some arithmetic:
sage: x = PolynomialRing(IntegerRing()).gen() sage: f = x**5 + 2*x**2 + (-1); f x^5 + 2*x^2 - 1 sage: f**2 x^10 + 4*x^7 - 2*x^5 + 4*x^4 - 4*x^2 + 1
Next we do arithmetic in a sparse polynomial ring over the integers:
sage: R = PolynomialRing(IntegerRing(), "x"); x = R.gen(); R Univariate Polynomial Ring in x over Integer Ring sage: S = PolynomialRing(R, "Z"); Z = S.gen(); S Univariate Polynomial Ring in Z over Univariate Polynomial Ring in x over Integer Ring sage: f = Z**3 + (x**2-2*x+1)*Z - 3; f Z^3 + (x^2 - 2*x + 1)*Z + -3 sage: f*f Z^6 + (2*x^2 - 4*x + 2)*Z^4 + (-6)*Z^3 + (x^4 - 4*x^3 + 6*x^2 - 4*x + 1)*Z^2 + (-6*x^2 + 12*x - 6)*Z + 9 sage: f**3 == f*f*f True
To have the element print as 'y', give 'y' as the second argument to the PolynomialRing constructor.
sage: y = PolynomialRing(IntegerRing(), 'y').gen() sage: y**3 - 2*y y^3 - 2*y
base_ring,
copy,
degree,
denominator,
derivative,
dict,
factor,
gcd,
integral,
is_gen,
is_irreducible,
is_monic,
is_nonzero,
is_zero,
latex,
lcm,
leading,
list,
pari,
polynomial,
quo_rem,
resultant,
reverse,
truncate,
valuation,
variable,
xgcd
Further documentation:
) |
Return the base ring of the parent of self.
sage: x = PolynomialRing(ZZ).gen() sage: x.base_ring() Integer Ring sage: (2*x+3).base_ring() Integer Ring
) |
Return a copy of self.
We create the polynomial f=x+3, then set g=f, and change the coefficient of x in g, which also changes the coefficient of x in f. If we instead copy f, then changing the coefficient of x of g does not change f.
sage: x = PolynomialRing(IntegerRing()).gen() sage: f = x+3 sage: g = f sage: g[1]=3 sage: f 3*x + 3 sage: g = f.copy() sage: g[1]=5 sage: f 3*x + 3 sage: g 5*x + 3
) |
Return the degree of this polynomial. The zero polynomial has degree -1.
sage: x = PolynomialRing(ZZ).gen() sage: f = x**93 + 2*x + 1 sage: f.degree() 93 sage: x = PolynomialRing(QQ, sparse=True).gen() sage: f = x**100000 sage: f.degree() 100000
) |
Return the least common multiple of the denominators of the entries of self, when this makes sense, i.e., when the coefficients have a denominator function.
WARNING: This is not the denominator of the rational function defined by self, which would always be 1 since self is a polynomial.
First we compute the denominator of a polynomial with integer coefficients, which is of course 1.
sage: x = PolynomialRing(IntegerRing()).gen() sage: f = x**3 + 17*x + 1 sage: f.denominator() 1
Next we compute the denominator of a polynomial with rational coefficients.
sage: x = PolynomialRing(RationalField()).gen() sage: f = '1/17'*x**19 - '2/3'*x + '1/3'; f 1/17*x^19 - 2/3*x + 1/3 sage: f.denominator() 51
Finally, we try to compute the denominator of a polynomial with coefficients in the real numbers, which is a ring whose elements do not have a denominator method.
sage: x = PolynomialRing(RealField()).gen() sage: f = x + '1/3'; f 1.0*x + 0.333333333333333333333 sage: f.denominator() Traceback (most recent call last): ... AttributeError: 'RealNumber_mpf' object has no attribute 'denominator'
) |
Return polynomials f1, ..., fn and exponents e1, ..., en such that the gcd fo the coefficients of the fi is 1, and prod fi**ei is equal to a scalar multiple of self.
other) |
Greatest common divisor of self and polynomial other.
) |
Returns True if this polynomial is monic. The zero polynomial is by definition not monic.
other) |
Let f and g be two polynomials. Then this function returns the monic least common multiple of f and g.
other) |
Returns a tuple (quotient, remainder) where self = quotient*other + remainder.
n) |
Replace this polynomial by
where the sum is
over
. The resulting polynomial is equivalent to self
modulo
.
) |
If
, with
nonzero,
then the valuation of
is
. The valuation of the zero
polynomial is
.
other) |
Extended gcd of self and polynomial other.
Instances of class Polynomial also have the following special functions:
__add__,
__call__,
__cmp__,
__div__,
__float__,
__floordiv__,
__getitem__,
__int__,
__long__,
__mod__,
__mul__,
__neg__,
__pos__,
__pow__,
__radd__,
__rdiv__,
__rmul__,
__rsub__,
__setitem__,
__sub__
Further documentation:
a) |
Evaluate polynomial at x=a using Horner's rule
INPUT: a -- ring element a; need not be in the coefficient ring of the polynomial. OUTPUT: ring element, in the parent of a, if a is a ring element.
sage: x = PolynomialRing(QQ, 'x').gen() sage: f = x - 5 sage: f(3) -2 sage: f = (x-1)**5 sage: f(2) 1
AUTHOR: David Joyner, 2005-04-10.
right) |
Quotient of division of self by other. This is denoted //.
other) |
Remainder of division of self by other.
sage: x = PolynomialRing(IntegerRing()).gen() sage: x % (x+1) -1 sage: (x**3 + x - 1) % (x**2 - 1) 2*x - 1
right) |
sage: x = PolynomialRing(IntegerRing()).gen() sage: (x - 4)*(x**2 - 8*x + 16) x^3 - 12*x^2 + 48*x - 64
right) |
The difference self - right.
sage: x = PolynomialRing(QQ).gen() sage: x - (x+1) -1
See About this document... for information on suggesting changes.