Home | Trees | Index | Help |
|
---|
Package sage :: Package rings :: Module polynomial :: Class Polynomial |
|
object
--+ |Element
--+ | Polynomial
Polynomial_generic_dense
,
Polynomial_generic_sparse
,
Polynomial_rational_dense
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:>>> x = PolynomialRing(IntegerRing()).gen() >>> f = x**5 + 2*x**2 + (-1); f x^5 + 2*x^2 - 1 >>> f**2 x^10 + 4*x^7 - 2*x^5 + 4*x^4 - 4*x^2 + 1Next we do arithmetic in a sparse polynomial ring over the integers:
>>> R = PolynomialRing(IntegerRing(), "x"); x = R.gen(); R Univariate Polynomial Ring in x over Integer Ring >>> S = PolynomialRing(R, "Z"); Z = S.gen(); S Univariate Polynomial Ring in Z over Univariate Polynomial Ring in x over Integer Ring >>> f = Z**3 + (x**2-2*x+1)*Z - 3; f Z^3 + (x^2 - 2*x + 1)*Z + -3 >>> 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 >>> f**3 == f*f*f TrueTo have the element print as 'y', give 'y' as the second argument to the PolynomialRing constructor.
>>> y = PolynomialRing(IntegerRing(), 'y').gen() >>> y**3 - 2*y y^3 - 2*y
Method Summary | |
---|---|
__init__(self,
parent,
is_gen)
| |
__add__(self,
right)
| |
Compute value of this polynomial at x. | |
__cmp__(self,
other)
| |
Division with remainder. | |
__float__(self)
| |
Quotient of division of self by other. | |
__getitem__(self,
n)
| |
__hash__(self)
| |
__int__(self)
| |
__long__(self)
| |
Remainder of division of self by other. | |
EXAMPLES: | |
__neg__(self)
| |
__pos__(self)
| |
__pow__(self,
right)
| |
__radd__(self,
left)
| |
__rdiv__(self,
left)
| |
__repr__(self)
| |
__rmul__(self,
left)
| |
__rsub__(self,
left)
| |
__setitem__(self,
n,
x)
| |
The difference self - right. | |
Return the base ring of the parent of self. | |
Returns the complex roots of this polynomial. | |
Return a copy of self. | |
Return the degree of this polynomial. | |
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. | |
derivative(self)
| |
dict(self)
| |
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. | |
Greatest common divisor of self and polynomial other. | |
is_gen(self)
| |
is_irreducible(self)
| |
Returns True if this polynomial is monic. | |
is_nonzero(self)
| |
is_zero(self)
| |
leading(self)
| |
list(self)
| |
pari(self)
| |
polynomial(self,
*args,
**kwds)
| |
resultant(self,
other,
flag)
| |
reverse(self)
| |
If f = a_r x^r + a_{r+1}x^{r+1} + higher terms ..., with a_r nonzero then the valuation of f is r. | |
variable(self)
| |
Extended gcd of self and polynomial other. | |
Inherited from object | |
x.__delattr__('name') <==> del x.name | |
x.__getattribute__('name') <==> x.name | |
helper for pickle | |
x.__setattr__('name', value) <==> x.name = value | |
x.__str__() <==> str(x) |
Method Details |
---|
__call__(self,
x)
Compute value of this polynomial at x.
|
__div__(self, other)Division with remainder. Returns a tuple (quotient, remainder). |
__floordiv__(self, right)Quotient of division of self by other. This is denoted //. |
__mod__(self, other)Remainder of division of self by other. EXAMPLES:>>> x = PolynomialRing(IntegerRing()).gen() >>> x % (x+1) -1 >>> (x**3 + x - 1) % (x**2 - 1) 2*x - 1 |
__mul__(self, right)EXAMPLES:>>> x = PolynomialRing(IntegerRing()).gen() >>> (x - 4)*(x**2 - 8*x + 16) x^3 - 12*x^2 + 48*x - 64 |
__sub__(self,
right)
|
base_ring(self)Return the base ring of the parent of self. EXAMPLES:>>> x = PolynomialRing(IntegerRing()).gen() >>> x.base_ring() Integer Ring >>> (2*x+3).base_ring() Integer Ring |
complex_roots(self, flag=0)Returns the complex roots of this polynomial. INPUT: flag -- optional, and can be 0: (default), uses Schonhage's method modified by Gourdon, 1: uses a modified Newton method. OUTPUT: list of complex roots of this polynomial, counted with multiplicities. NOTE: Calls the pari function polroots. EXAMPLE: We compute the roots of the characteristic polynomial of some Salem numbers: >>> Q = rational_field.RationalField() >>> R = PolynomialRing(Q); x = R.gen() >>> f = 1 - x**2 - x**3 - x**4 + x**6 >>> f.complex_roots()[0] 0.713639173536900883414 |
copy(self)Return a copy of self. EXAMPLES: 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.>>> x = PolynomialRing(IntegerRing()).gen() >>> f = x+3 >>> g = f >>> g[1]=3 >>> f 3*x + 3 >>> g = f.copy() >>> g[1]=5 >>> f 3*x + 3 >>> g 5*x + 3 |
degree(self)Return the degree of this polynomial. The zero polynomial has degree -1. EXAMPLES:>>> x = PolynomialRing(IntegerRing()).gen() >>> f = x**93 + 2*x + 1 >>> f.degree() 93 >>> x = PolynomialRing(RationalField(), sparse=True).gen() >>> f = x**100000 >>> f.degree() 100000 |
denominator(self)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. EXAMPLES: First we compute the denominator of a polynomial with integer coefficients, which is of course 1.>>> x = PolynomialRing(IntegerRing()).gen() >>> f = x**3 + 17*x + 1 >>> f.denominator() 1Next we compute the denominator of a polynomial with rational coefficients. >>> x = PolynomialRing(RationalField()).gen() >>> f = '1/17'*x**19 - '2/3'*x + '1/3'; f 1/17*x^19 - 2/3*x + 1/3 >>> f.denominator() 51Finally, 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. >>> x = PolynomialRing(RealField()).gen() >>> f = x + '1/3'; f 1.0*x + 0.333333333333333333333 >>> f.denominator() Traceback (most recent call last): ... AttributeError: 'RealNumber_mpf' object has no attribute 'denominator' |
factor(self)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. |
gcd(self, other)Greatest common divisor of self and polynomial other. |
is_monic(self)Returns True if this polynomial is monic. The zero polynomial is by definition not monic. |
valuation(self)If f = a_r x^r + a_{r+1}x^{r+1} + higher terms ..., with a_r nonzero then the valuation of f is r. The valuation of the zero polynomial is rings.infinity. |
xgcd(self, other)Extended gcd of self and polynomial other. |
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Mon May 9 17:57:02 2005 | http://epydoc.sf.net |