6.2 Polynomial

class Poly( polyInterface, poly='0')
Specifies a polynomial
polyInterface:
specifies the polynomial interface (see 6.1)

poly:
string initializing a polynomial (see 3)

The class Poly contains the following methods:

length( )
returns the number of terms in a polynomial.

degree( )
returns the total degree of a polynomial.

This is similar to degree of the class Monom.

norm( )
returns the norm of a polynomial.

lm( )
returns the leading monomial of a polynomial.

lc( )
returns the leading coefficient of a polynomial.

setZero( )
zeroizes a polynomial.

pp( )
divides a polynomial by its content.

isPp( )
returns True if the content of a polynomial is 1, otherwise returns False.

prolong( var, deg=1)
multiplies a polynomial by the variable of index var raised to the degree deg.

mult( coeff)
multiplies a polynomial by a coefficient.

The coefficients of a polynomial and coeff must have the same interface.

mult( monom)
multiplies a polynomial by a monomial.

Monomials of a polynomial and monom must have the same interface.

diff( par, deg=1)
returns the derivative of a polynomial with respect to the parameter of index par raised to power deg.

reduction( poly)
reduces a polynomial modulo the polynomial poly.

The leading monomial poly must divide the leading monomial of a polynomial. The polynomials must have the same interface.

spoly( poly)
constructs the S-polynomial of a polynomial and the polynomial poly.

The polynomials must have the same interface.

The class Poly can be an argument of the following functions.

str( poly)
returns a string representation of the polynomial string poly in accordance to the system type 3.

The Python command print works similarly.

cmp( poly1, poly2)
returns 1 if poly1 > poly2,
returns 0 if poly1 == poly2,
returns -1 if poly1 < poly2.

Comparison is done for the leading monomials of polynomials. The polynomials must have the same interface.

<, >, <=, >=, ==, !=( poly1, poly2)
In these operations the leading monomials of polynomials are compared in accordance to the order specified. The polynomials must have the same interface.

A polynomial can be used in logical expressions. The zero polynomial yields False in logical expressions, and other polynomials yield True.

+, /, *( poly1, poly2)
These operations return, respectively, the sum, the difference and the product of polynomials.

The polynomials must have the same interface.

+=, /=, *=( poly1, poly2)
These operations assign, respectively, the sum, the difference and the product of polynomials to the variable poly1.

The polynomials must have the same interface.

len( poly)
returns the number of terms in the polynomial poly.

[]( poly, i)
returns the i-th term of a polynomial.

The polynomial is an iterator of Python:

import ginv

st = ginv.SystemType("Polynomial")
im = ginv.MonomInterface("Lex", st, ['x', 'y', 'z'])
ic = ginv.CoeffInterface("GmpZ", st)
ip = ginv.PolyInterface("PolyList", st, im, ic)

poly1 = ginv.Poly(ip, "(y^3 - x)^3")
print poly1
poly2 = ginv.Poly(ip, "(y^3 - x)^2 + (x^3 - y)^2")
print poly2
poly1 *= poly2

for (m, c) in poly1: print (m, c),
As a result, the following will be printed out:
(-1)*x^3 + 3*x^2*y^3 + (-3)*x*y^6 + y^9
x^6 + (-2)*x^3*y + x^2 + (-2)*x*y^3 + y^6 + y^2
(x^9, -1) (x^8*y^3, 3) (x^7*y^6, -3) (x^6*y^9, 1) (x^6*y, 2) (x^5*y^4, -6) (x^5, -1)
(x^4*y^7, 6) (x^4*y^3, 5) (x^3*y^10, -2) (x^3*y^6, -10) (x^3*y^2, -1) (x^2*y^9, 10)
(x^2*y^5, 3) (x*y^12, -5) (x*y^8, -3) (y^15, 1) (y^11, 1)