Polynomials and Rational Functions

Let R be a commutative ring-with-one. We call a free associative algebra A over R a polynomial ring over R. The free generators of A are called indeterminates (to avoid naming conflicts with the word variables which will be used to denote &GAP; variables only) , they are usually denoted by x_1, x_2, \ldots. The number of indeterminates is called the rank of A. The elements of A are called polynomials. Products of indeterminates are called monomials, every polynomial can be expressed as a finite sum of products of monomials with ring elements in a form like r_{{1,0}} x_1 + r_{{1,1}} x_1 x_2 + r_{{0,1}} x_2 + \cdots with r_{{i,j}} \in R.

A polynomial ring of rank 1 is called an univariate polynomial ring, its elements are univariate polynomials.

Polynomial rings of smaller rank naturally embed in rings of higher rank; if S is a subring of R then a polynomial ring over S naturally embeds in a polynomial ring over R of the same rank. Note however that &GAP; does not consider R as a subset of a polynomial ring over R; for example the zero of R (0) and the zero of the polynomial ring (0x^0) are different objects.

Internally, indeterminates are represented by positive integers, but it is possible to give names to them to have them printed in a nicer way. Beware, however that there is not necessarily any relation between the way an indeterminate is called and the way it is printed. See section for details.

If R is an integral domain, the polynomial ring A over R is an integral domain as well and one can therefore form its quotient field Q. This field is called a field of rational functions. Again A embeds naturally into Q and &GAP; will perform this embedding implicitly. (In fact it implements the ring of rational functions over R.) To avoid problems with leading coefficients, however, R must be a unique factorization domain.

Indeterminates
<#Include Label="[1]{ringpoly}">

<#Include Label="[2]{ringpoly}"> <#Include Label="Indeterminate"> <#Include Label="IndeterminateNumberOfUnivariateRationalFunction"> <#Include Label="IndeterminateOfUnivariateRationalFunction"> <#Include Label="IndeterminateName"> <#Include Label="CIUnivPols">

Operations for Rational Functions

The rational functions form a field, therefore all arithmetic operations are applicable to rational functions.

addition
subtraction
product
quotient
f + g

f - g

f * g

f / g

gap> x:=Indeterminate(Rationals,1);;y:=Indeterminate(Rationals,2);; gap> f:=3+x*y+x^5;;g:=5+x^2*y+x*y^2;; gap> a:=g/f; (x_1^2*x_2+x_1*x_2^2+5)/(x_1^5+x_1*x_2+3)

Note that the quotient f/g of two polynomials might be represented as a rational function again. If g is known to divide f the call Quotient(f,g) (see ) should be used instead.

mod
f mod g

For two Laurent polynomials f and g, f mod g is the Euclidean remainder (see ) of f modulo g.

As calculating a multivariate Gcd can be expensive, it is not guaranteed that rational functions will always be represented as a quotient of coprime polynomials. In certain unfortunate situations this might lead to a degree explosion. To ensure cancellation you can use on the and values of a given rational function.

All polynomials as well as all the univariate polynomials in the same indeterminate form subrings of this field. If two rational functions are known to be in the same subring, the result will be expressed as element in this subring.

Comparison of Rational Functions
comparison
f = g

Two rational functions f and g are equal if the product Numerator(f) * Denominator(g) equals Numerator(g) * Denominator(f).

gap> x:=Indeterminate(Rationals,"x");;y:=Indeterminate(Rationals,"y");; gap> f:=3+x*y+x^5;;g:=5+x^2*y+x*y^2;; gap> a:=g/f; (x^2*y+x*y^2+5)/(x^5+x*y+3) gap> b:=(g*f)/(f^2); (x^7*y+x^6*y^2+5*x^5+x^3*y^2+x^2*y^3+3*x^2*y+3*x*y^2+5*x*y+15)/(x^10+2\ *x^6*y+6*x^5+x^2*y^2+6*x*y+9) gap> a=b; true

smaller
f < g

The ordering of rational functions is defined in several steps. Monomials (products of indeterminates) are sorted first by degree, then lexicographically (with x_1>x_2) (see ). Products of monomials with ring elements (terms) are compared first by their monomials and then by their coefficients.

gap> x>y; true gap> x^2*y<x*y^2; false gap> x*y<x^2*y; true gap> x^2*y < 5* y*x^2; true
Polynomials are compared by comparing the largest terms in turn until they differ. gap> x+y<y; false gap> x<x+1; true Rational functions are compared by comparing the polynomial Numerator(f) * Denominator(g) with the polynomial Numerator(g) * Denominator(f). (As the ordering of monomials used by &GAP; is invariant under multiplication this is independent of common factors in numerator and denominator.) gap> f/g<g/f; false gap> f/g<(g*g)/(f*g); false

For univariate polynomials this reduces to an ordering first by total degree and then lexicographically on the coefficients.

Properties and Attributes of Rational Functions

All these tests are applicable to every rational function. Depending on the internal representation of the rational function, however some of these tests (in particular, univariateness) might be expensive in some cases.

For reasons of performance within algorithms it can be useful to use other attributes, which give a slightly more technical representation. See section for details.

<#Include Label="IsPolynomialFunction"> <#Include Label="NumeratorOfRationalFunction"> <#Include Label="DenominatorOfRationalFunction"> <#Include Label="IsPolynomial"> <#Include Label="AsPolynomial"> <#Include Label="IsUnivariateRationalFunction"> <#Include Label="CoefficientsOfUnivariateRationalFunction"> <#Include Label="IsUnivariatePolynomial"> <#Include Label="CoefficientsOfUnivariatePolynomial"> <#Include Label="IsLaurentPolynomial"> <#Include Label="IsConstantRationalFunction"> <#Include Label="IsPrimitivePolynomial"> <#Include Label="SplittingField">

Univariate Polynomials

Some of the operations are actually defined on the larger domain of Laurent polynomials (see ). For this section you can simply ignore the word Laurent if it occurs in a description.

<#Include Label="UnivariatePolynomial"> <#Include Label="UnivariatePolynomialByCoefficients"> <#Include Label="DegreeOfLaurentPolynomial"> <#Include Label="RootsOfPolynomial"> <#Include Label="RootsOfUPol"> <#Include Label="QuotRemLaurpols"> <#Include Label="UnivariatenessTestRationalFunction"> <#Include Label="InfoPoly">

We remark that some functions for multivariate polynomials (which will be defined in the following sections) permit a different syntax for univariate polynomials which drops the requirement to specify the indeterminate. Examples are , , , and : gap> p:=UnivariatePolynomial(Rationals,[1,2,3,4],1); 4*x^3+3*x^2+2*x+1 gap> Value(p,Z(5)); Z(5)^2 gap> LeadingCoefficient(p); 4 gap> Derivative(p); 12*x^2+6*x+2

Polynomials as Univariate Polynomials in one Indeterminate
<#Include Label="DegreeIndeterminate"> <#Include Label="PolynomialCoefficientsOfPolynomial"> <#Include Label="LeadingCoefficient"> <#Include Label="LeadingMonomial"> <#Include Label="Derivative"> <#Include Label="Discriminant"> <#Include Label="Resultant">

Multivariate Polynomials
<#Include Label="Value">

Minimal Polynomials
MinimalPolynomial
<#Include Label="MinimalPolynomial">

Cyclotomic Polynomials
<#Include Label="CyclotomicPolynomial">

Polynomial Factorization

At the moment &GAP; provides only methods to factorize polynomials over finite fields (see Chapter ), over subfields of cyclotomic fields (see Chapter ), and over algebraic extensions of these (see Chapter ).

returns a list of the irreducible factors of the polynomial poly in the polynomial ring R. (That is factors over the value of R.)

For univariate factorizations, it is possible to pass a record opt as a third argument. This record can contain the following components: onlydegs is a set of positive integers. The factorization assumes that all irreducible factors have a degree in this set. stopdegs is a set of positive integers. The factorization will stop once a factor of degree in stopdegs has been found and will return the factorization found so far.

gap> f:= CyclotomicPolynomial( GF(2), 7 ); x_1^6+x_1^5+x_1^4+x_1^3+x_1^2+x_1+Z(2)^0 gap> Factors( f ); [ x_1^3+x_1+Z(2)^0, x_1^3+x_1^2+Z(2)^0 ] gap> Factors( PolynomialRing( GF(8) ), f ); [ x_1+Z(2^3), x_1+Z(2^3)^2, x_1+Z(2^3)^3, x_1+Z(2^3)^4, x_1+Z(2^3)^5, x_1+Z(2^3)^6 ] gap> f:= MinimalPolynomial( Rationals, E(4) ); x^2+1 gap> Factors( f ); [ x^2+1 ] gap> Factors( PolynomialRing( Rationals ), f ); [ x^2+1 ] gap> Factors( PolynomialRing( CF(4) ), f ); [ x+(-E(4)), x+E(4) ]
<#Include Label="FactorsSquarefree">

Polynomials over the Rationals

The following functions are only available to polynomials with rational coefficients:

<#Include Label="PrimitivePolynomial"> <#Include Label="PolynomialModP"> <#Include Label="GaloisType"> <#Include Label="ProbabilityShapes">

Factorization of Polynomials over the Rationals

The following operations are used by &GAP; inside the factorization algorithm but might be of interest also in other contexts. <#Include Label="BombieriNorm"> <#Include Label="MinimizedBombieriNorm"> <#Include Label="HenselBound"> <#Include Label="OneFactorBound">

Laurent Polynomials

A univariate polynomial can be written in the form r_0 + r_1 x + \cdots + r_n x^n, with r_i \in R. Formally, there is no reason to start with 0, if m is an integer, we can consider objects of the form r_m x^m + r_{{m+1}} x^{{m+1}} + \cdots + r_n x^n. We call these Laurent polynomials. Laurent polynomials also can be considered as quotients of a univariate polynomial by a power of the indeterminate. The addition and multiplication of univariate polynomials extends to Laurent polynomials (though it might be impossible to interpret a Laurent polynomial as a function) and many functions for univariate polynomials extend to Laurent polynomials (or extended versions for Laurent polynomials exist).

<#Include Label="LaurentPolynomialByCoefficients"> <#Include Label="CoefficientsOfLaurentPolynomial"> <#Include Label="IndeterminateNumberOfLaurentPolynomial">

Univariate Rational Functions
<#Include Label="UnivariateRationalFunctionByCoefficients">

Polynomial Rings and Function Fields

While polynomials depend only on the family of the coefficients, polynomial rings A are defined over a base ring R. A polynomial is an element of A if and only if all its coefficients are contained in R. Besides providing domains and an easy way to create polynomials, polynomial rings can affect the behavior of operations like factorization into irreducibles.

If you need to work with a polynomial ring and its indeterminates the following two approaches will produce a ring that contains given variables (see section for details about the internal numbering): Either, first create the ring and then get the indeterminates with .

gap> r := PolynomialRing(Rationals,["a","b"]);; gap> indets := IndeterminatesOfPolynomialRing(r);; gap> a := indets[1]; a := indets[2]; a b

Alternatively, first create the indeterminates and then create the ring including these indeterminates.

gap> a:=Indeterminate(Rationals,"a":old);; gap> b:=Indeterminate(Rationals,"b":old);; gap> PolynomialRing(Rationals,[a,b]);;

As a convenient shortcut, intended mainly for interactive working, the i-th indeterminate of a polynomial ring R can be accessed as R.i, which corresponds exactly to IndeterminatesOfPolynomialRing( R )[i] or, if it has the name nam, as R.nam. Note that the number i is in general not the indeterminate number, but simply an index into the indeterminates list of R.

gap> r := PolynomialRing(Rationals, ["a", "b"]:old );; gap> r.1; r.2; r.a; r.b; a b a b gap> IndeterminateNumberOfLaurentPolynomial(r.1); 3

Polynomials as &GAP; objects can exist without a polynomial ring being defined and polynomials cannot be associated to a particular polynomial ring. (For example dividing a polynomial which is in a polynomial ring over the integers by another integer will result in a polynomial over the rationals, not in a rational function over the integers.)

<#Include Label="PolynomialRing"> <#Include Label="IndeterminatesOfPolynomialRing"> <#Include Label="CoefficientsRing"> <#Include Label="IsPolynomialRing"> <#Include Label="IsFiniteFieldPolynomialRing"> <#Include Label="IsAbelianNumberFieldPolynomialRing"> <#Include Label="IsRationalsPolynomialRing"> <#Include Label="FunctionField"> <#Include Label="IsFunctionField">

Univariate Polynomial Rings
<#Include Label="UnivariatePolynomialRing"> <#Include Label="IsUnivariatePolynomialRing">

Monomial Orderings

It is often desirable to consider the monomials within a polynomial to be arranged with respect to a certain ordering. Such an ordering is called a monomial ordering if it is total, invariant under multiplication with other monomials and admits no infinite descending chains. For details on monomial orderings see .

In &GAP;, monomial orderings are represented by objects that provide a way to compare monomials (as polynomials as well as –for efficiency purposes within algorithms– in the internal representation as lists).

Normally the ordering chosen should be admissible, i.e. it must be compatible with products: If a < b then ca < cb for all monomials a, b and c.

Each monomial ordering provides the two functions and to compare monomials. These functions work as is less than, i.e. they return true if and only if the left argument is smaller.

<#Include Label="IsMonomialOrdering"> <#Include Label="LeadingMonomialOfPolynomial"> <#Include Label="LeadingTermOfPolynomial"> <#Include Label="LeadingCoefficientOfPolynomial"> <#Include Label="MonomialComparisonFunction"> <#Include Label="MonomialExtrepComparisonFun"> <#Include Label="MonomialLexOrdering"> <#Include Label="MonomialGrlexOrdering"> <#Include Label="MonomialGrevlexOrdering"> <#Include Label="EliminationOrdering"> <#Include Label="PolynomialReduction"> <#Include Label="PolynomialReducedRemainder"> <#Include Label="PolynomialDivisionAlgorithm"> <#Include Label="MonomialExtGrlexLess">

Groebner Bases

A Groebner Basis of an ideal Ii, in a polynomial ring R, with respect to a monomial ordering, is a set of ideal generators G such that the ideal generated by the leading monomials of all polynomials in G is equal to the ideal generated by the leading monomials of all polynomials in I.

For more details on Groebner bases see .

<#Include Label="GroebnerBasis"> <#Include Label="ReducedGroebnerBasis"> <#Include Label="StoredGroebnerBasis"> <#Include Label="InfoGroebner">

Rational Function Families

All rational functions defined over a ring lie in the same family, the rational functions family over this ring.

In &GAP; therefore the family of a polynomial depends only on the family of the coefficients, all polynomials whose coefficients lie in the same family are compatible.

<#Include Label="RationalFunctionsFamily"> <#Include Label="IsPolynomialFunctionsFamily"> <#Include Label="CoefficientsFamily">

The Representations of Rational Functions

&GAP; uses four representations of rational functions: Rational functions given by numerator and denominator, polynomials, univariate rational functions (given by coefficient lists for numerator and denominator and valuation) and Laurent polynomials (given by coefficient list and valuation).

These representations do not necessarily reflect mathematical properties: While an object in the Laurent polynomials representation must be a Laurent polynomial it might turn out that a rational function given by numerator and denominator is actually a Laurent polynomial and the property tests in section will find this out.

Each representation is associated one or several defining attributes that give an external representation (see ) of the representation in the form of lists and are the defining information that tells a rational function what it is.

&GAP; also implements methods to compute these attributes for rational functions in other representations, provided it would be possible to express an mathematically equal rational function in the representation associated with the attribute. (That is one can always get a numerator/denominator representation of a polynomial while an arbitrary function of course can compute a polynomial representation only if it is a polynomial.)

Therefore these attributes can be thought of as conceptual representations that allow us –as far as possible– to consider an object as a rational function, a polynomial or a Laurent polynomial, regardless of the way it is represented in the computer.

Functions thus usually do not need to care about the representation of a rational function. Depending on its (known in the context or determined) properties, they can access the attribute representing the rational function in the desired way.

Consequentially, methods for rational functions are installed for properties and not for representations.

When creating new rational functions however they must be created in one of the three representations. In most cases this will be the representation for which the conceptual representation in which the calculation was done is the defining attribute.

Iterated operations (like forming the product over a list) therefore will tend to stay in the most suitable representation and the calculation of another conceptual representation (which may be comparatively expensive in certain circumstances) is not necessary.

The Defining Attributes of Rational Functions

In general, rational functions are given in terms of monomials. They are represented by lists, using numbers (see ) for the indeterminates.

<#Include Label="[4]{ratfun}"> <#Include Label="[1]{ratfun}">

The attributes that give a representation of a a rational function as a Laurent polynomial are and .

<#Include Label="[2]{ratfun}"> <#Include Label="IsRationalFunctionDefaultRep"> <#Include Label="ExtRepNumeratorRatFun"> <#Include Label="ExtRepDenominatorRatFun"> <#Include Label="ZeroCoefficientRatFun"> <#Include Label="IsPolynomialDefaultRep"> <#Include Label="ExtRepPolynomialRatFun"> <#Include Label="IsLaurentPolynomialDefaultRep">

Creation of Rational Functions
<#Include Label="[3]{ratfun}"> <#Include Label="RationalFunctionByExtRep"> <#Include Label="PolynomialByExtRep"> <#Include Label="LaurentPolynomialByExtRep">

Arithmetic for External Representations of Polynomials

The following operations are used internally to perform the arithmetic for polynomials in their external representation (see ) as lists.

Functions to perform arithmetic with the coefficient lists of Laurent polynomials are described in Section .

<#Include Label="ZippedSum"> <#Include Label="ZippedProduct"> <#Include Label="QuotientPolynomialsExtRep">

Cancellation Tests for Rational Functions

The operation can be used to test for common factors of two polynomials. This however would be too expensive to be done in the arithmetic, thus uses the following operations internally to try to keep the denominators as small as possible

<#Include Label="RationalFunctionByExtRepWithCancellation"> <#Include Label="TryGcdCancelExtRepPolynomials"> <#Include Label="HeuristicCancelPolynomials">