<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- %% -->
<!-- %A  ratfun.xml                  GAP documentation            Alexander Hulpke -->
<!-- %A                                                           Frank Celler -->
<!-- %% -->
<!-- %% -->
<!-- %Y  (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland -->
<!-- %Y  Copyright (C) 2002 The GAP Group -->
<!-- %% -->
<Chapter Label="Polynomials and Rational Functions">
<Heading>Polynomials and Rational Functions</Heading>

Let <M>R</M> be a commutative ring-with-one. We call a free associative
algebra <M>A</M> over <M>R</M> a <E>polynomial ring</E> over <M>R</M>. The free generators of
<M>A</M> are called <E>indeterminates</E>
(to avoid naming conflicts with the word <E>variables</E> which will be used
to denote &GAP; variables only)
, they are usually denoted by
<M>x_1, x_2, \ldots</M>.
The number of indeterminates is called the <E>rank</E> of <M>A</M>.
The elements of <M>A</M> are called <E>polynomials</E>. Products of
indeterminates are called <E>monomials</E>, every
polynomial can be expressed as a finite sum of products of monomials with
ring elements in a form like
<M>r_{{1,0}} x_1 + r_{{1,1}} x_1 x_2 + r_{{0,1}} x_2 + \cdots</M>
with <M>r_{{i,j}} \in R</M>.
<P/>
A polynomial ring of rank 1 is called an <E>univariate</E> polynomial ring, its
elements are <E>univariate polynomials</E>.
<P/>
Polynomial rings of smaller rank naturally embed in rings of higher rank; if
<M>S</M> is a subring of <M>R</M> then a polynomial ring over <M>S</M> naturally embeds in
a polynomial ring over <M>R</M> of the same rank. Note however that &GAP; does
not consider <M>R</M> as a subset of a polynomial ring over <M>R</M>; for example the
zero of <M>R</M> (<M>0</M>) and the zero of the polynomial ring (<M>0x^0</M>) are different
objects.
<P/>
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
<Ref Sect="Indeterminates"/> for details.
<P/>
If <M>R</M> is an integral domain, the polynomial ring <M>A</M> over <M>R</M> is an integral domain as well and one can
therefore form its quotient field <M>Q</M>. This field is called a <E>field of
rational functions</E>. Again <M>A</M> embeds naturally into <M>Q</M> and &GAP; will
perform this embedding implicitly. (In fact it implements the ring of rational
functions over <M>R</M>.) To avoid problems with leading
coefficients, however, <M>R</M> must be a unique factorization domain.


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Indeterminates">
<Heading>Indeterminates</Heading>

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

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Operations for Rational Functions">
<Heading>Operations for Rational Functions</Heading>

The rational functions form a field,
therefore all arithmetic operations are applicable to rational functions.
<P/>
<Index Subkey="rational functions">addition</Index>
<Index Subkey="rational functions">subtraction</Index>
<Index Subkey="rational functions">product</Index>
<Index Subkey="rational functions">quotient</Index>
<C><A>f</A> + <A>g</A></C>
<P/>
<C><A>f</A> - <A>g</A></C>
<P/>
<C><A>f</A> * <A>g</A></C>
<P/>
<C><A>f</A> / <A>g</A></C>
<P/>
<Example><![CDATA[
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)
]]></Example>
<P/>
Note that the quotient <C><A>f</A>/<A>g</A></C> of two polynomials might be represented as
a rational function again. If <A>g</A> is known to divide <A>f</A> the call
<C>Quotient(<A>f</A>,<A>g</A>)</C> (see&nbsp;<Ref Oper="Quotient"/>) should be used instead.
<P/>
<Index Subkey="Laurent polynomials">mod</Index>
<C><A>f</A> mod <A>g</A></C>
<!-- %\><C><A>f</A> mod <A>int</A></C>{mod!integer polynomial} -->
<P/>
For two Laurent polynomials <A>f</A> and <A>g</A>, <C><A>f</A> mod <A>g</A></C> is the Euclidean
remainder (see&nbsp;<Ref Oper="EuclideanRemainder"/>) of <A>f</A> modulo <A>g</A>.
<!-- % For a polynomial <A>f</A> over the integers and an integer <A>int</A>, <C><A>f</A> mod <A>int</A></C> -->
<!-- % is the polynomial over the integers obtained by reducing the coefficients -->
<!-- % of <A>f</A> modulo <A>int</A>. -->
<!-- % Just a remark: -->
<!-- % These two methods would not be compatible if integers would be regarded -->
<!-- % as constant polynomials. -->
<!-- % Therefore, I leave the second method undocumented. -->
<P/>
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
<Ref Func="Gcd" Label="for (a ring and) several elements"/> on the
<Ref Attr="NumeratorOfRationalFunction"/> and
<Ref Attr="DenominatorOfRationalFunction"/> values
of a given rational function.
<P/>
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.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Comparison of Rational Functions">
<Heading>Comparison of Rational Functions</Heading>

<Index Subkey="rational functions">comparison</Index>
<C><A>f</A> = <A>g</A></C>
<P/>
Two rational functions <A>f</A> and <A>g</A> are equal if the product
<C>Numerator(<A>f</A>) * Denominator(<A>g</A>)</C> equals
<C>Numerator(<A>g</A>) * Denominator(<A>f</A>)</C>.
<P/>
<Example><![CDATA[
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
]]></Example>
<P/>
<Index Subkey="rational functions">smaller</Index>
<C><A>f</A> &lt; <A>g</A></C>
<P/>
The ordering of rational functions is defined in several steps. Monomials
(products of indeterminates) are sorted first by degree, then
lexicographically (with <M>x_1>x_2</M>)
(see&nbsp;<Ref Func="MonomialGrlexOrdering"/>). Products of monomials
with ring elements (<Q>terms</Q>) are compared first by their monomials and
then by their coefficients.
<P/>
<Example><![CDATA[
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
]]></Example>
Polynomials are compared by comparing the largest terms in turn until they
differ.
<Example><![CDATA[
gap> x+y<y;
false
gap> x<x+1;
true
]]></Example>
Rational functions are compared by comparing the polynomial
<C>Numerator(<A>f</A>) * Denominator(<A>g</A>)</C> with the polynomial
<C>Numerator(<A>g</A>) * Denominator(<A>f</A>)</C>. (As the ordering of monomials used by
&GAP; is invariant under multiplication this is independent of common
factors in numerator and denominator.)
<Example><![CDATA[
gap> f/g<g/f;
false
gap> f/g<(g*g)/(f*g);
false
]]></Example>
<P/>
For univariate polynomials this reduces to an ordering first by total degree
and then lexicographically on the coefficients.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Properties and Attributes of Rational Functions">
<Heading>Properties and Attributes of Rational Functions</Heading>

All these tests are applicable to <E>every</E> 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.
<P/>
For reasons of performance within algorithms it can be useful to use other
attributes, which give a slightly more technical representation.
See section&nbsp;<Ref Sect="The Representations of Rational Functions"/>
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">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Univariate Polynomials">
<Heading>Univariate Polynomials</Heading>

Some of the operations are actually defined on the larger domain of Laurent
polynomials (see <Ref Sect="Laurent Polynomials"/>). For this section you can simply
ignore the word <Q>Laurent</Q> if it occurs in a description.
<P/>

<#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
<Ref Oper="Value" Label="for rat. function, a list of indeterminates, a value (and a one)"/>,
<Ref Oper="Discriminant"/>, <Ref Attr="Derivative"/>,
<Ref Oper="LeadingCoefficient"/> and <Ref Oper="LeadingMonomial"/>:
<Example><![CDATA[
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
]]></Example>

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Polynomials as Univariate Polynomials in one Indeterminate">
<Heading>Polynomials as Univariate Polynomials in one Indeterminate</Heading>

<#Include Label="DegreeIndeterminate">
<#Include Label="PolynomialCoefficientsOfPolynomial">
<#Include Label="LeadingCoefficient">
<#Include Label="LeadingMonomial">
<#Include Label="Derivative">
<#Include Label="Discriminant">
<#Include Label="Resultant">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Multivariate Polynomials">
<Heading>Multivariate Polynomials</Heading>

<#Include Label="Value">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Minimal Polynomials">
<Heading>Minimal Polynomials</Heading>

<Index Key="MinimalPolynomial" Subkey="over a ring"><C>MinimalPolynomial</C></Index>
<#Include Label="MinimalPolynomial">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Cyclotomic Polynomials">
<Heading>Cyclotomic Polynomials</Heading>

<#Include Label="CyclotomicPolynomial">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Polynomial Factorization">
<Heading>Polynomial Factorization</Heading>

At the moment &GAP; provides only methods to factorize 
polynomials over finite fields (see Chapter&nbsp;<Ref Chap="Finite Fields"/>),
over subfields of cyclotomic fields (see Chapter&nbsp;<Ref Chap="Abelian Number Fields"/>),
and over algebraic extensions of these
(see Chapter&nbsp;<Ref Chap="Algebraic extensions of fields"/>).
<P/>

<ManSection>
<Meth Name="Factors" Arg='[R, ]poly[, opt]' Label="of polynomial"/>

<Description>
returns a list of the irreducible factors of the polynomial
<A>poly</A> in the polynomial ring <A>R</A>. (That is factors over the
<Ref Attr="CoefficientsRing"/> value of <A>R</A>.)
<P/>
For univariate factorizations, it is possible to pass a record <A>opt</A>
as a third argument. This record can contain the following components:
<List>
<Mark><C>onlydegs</C></Mark>
<Item>
is a set of positive integers. The factorization assumes
that all irreducible factors have a degree in this set.
</Item>
<Mark><C>stopdegs</C></Mark>
<Item>
is a set of positive integers. The factorization will stop once a
factor of degree in <C>stopdegs</C> has been found and will return the
factorization found so far.
</Item>
</List>
<P/>
<Example><![CDATA[
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) ]
]]></Example>
</Description>
</ManSection>


<#Include Label="FactorsSquarefree">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Polynomials over the Rationals">
<Heading>Polynomials over the Rationals</Heading>

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

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

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Factorization of Polynomials over the Rationals">
<Heading>Factorization of Polynomials over the Rationals</Heading>

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">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Laurent Polynomials">
<Heading>Laurent Polynomials</Heading>

A univariate polynomial can be written in the form
<M>r_0 + r_1 x + \cdots + r_n x^n</M>, with <M>r_i \in R</M>.
Formally, there is no reason to start with 0, if <M>m</M> is an
integer, we can consider objects of the form
<M>r_m x^m + r_{{m+1}} x^{{m+1}} + \cdots + r_n x^n</M>.
We call these <E>Laurent polynomials</E>.
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">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Univariate Rational Functions">
<Heading>Univariate Rational Functions</Heading>

<#Include Label="UnivariateRationalFunctionByCoefficients">

<#Include Label="TaylorSeriesRationalFunction">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Polynomial Rings and Function Fields">
<Heading>Polynomial Rings and Function Fields</Heading>

While polynomials depend only on the family of the coefficients, polynomial
rings <M>A</M> are defined over a base ring <M>R</M>.
A polynomial is an element of <M>A</M> if and only if all its coefficients
are contained in <M>R</M>.
Besides providing domains and an easy way to create polynomials,
polynomial rings can affect the behavior of operations like
factorization into irreducibles.
<P/>
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&nbsp;<Ref Sect="Indeterminates"/> for details about the internal numbering):
Either, first create the ring and then get the indeterminates with
<Ref Attr="IndeterminatesOfPolynomialRing"/>. 
<P/>
<Example><![CDATA[
gap> r := PolynomialRing(Rationals,["a","b"]);;
gap> indets := IndeterminatesOfPolynomialRing(r);;
gap> a := indets[1]; a := indets[2];
a
b
]]></Example>
<P/>
Alternatively, first create the
indeterminates and then create the ring including these indeterminates.
<P/>
<Example><![CDATA[
gap> a:=Indeterminate(Rationals,"a":old);;
gap> b:=Indeterminate(Rationals,"b":old);;
gap> PolynomialRing(Rationals,[a,b]);;
]]></Example>
<P/>
As a convenient shortcut, intended mainly for interactive working, the
<M>i</M>-th indeterminate of a polynomial ring <M>R</M> can be accessed as
<M>R.i</M>,
which corresponds exactly to
<C>IndeterminatesOfPolynomialRing</C><M>( R )[i]</M>
or, if it has the name <C>nam</C>, as <M>R</M><C>.nam</C>.
<E>Note</E> that the number <M>i</M> is in general
<E>not</E> the indeterminate number,
but simply an index into the indeterminates list of <M>R</M>.
<P/>
<Example><![CDATA[
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
]]></Example>
<P/>
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.)
<P/>
<#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">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Univariate Polynomial Rings">
<Heading>Univariate Polynomial Rings</Heading>

<#Include Label="UnivariatePolynomialRing">
<#Include Label="IsUnivariatePolynomialRing">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Monomial Orderings">
<Heading>Monomial Orderings</Heading>

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
<E>monomial ordering</E> if it is total, invariant under multiplication with
other monomials and admits no infinite descending chains. For details on
monomial orderings see <Cite Key="coxlittleoshea"/>.
<P/>
In &GAP;, monomial orderings are represented by objects that provide a way
to compare monomials (as polynomials as well as &ndash;for efficiency purposes
within algorithms&ndash; in the internal representation as lists). 
<P/>
Normally the ordering chosen should be <E>admissible</E>, i.e. it
must be compatible with products:
If <M>a &lt; b</M> then <M>ca &lt; cb</M> for all monomials
<M>a, b</M> and <M>c</M>.
<P/>
Each monomial ordering provides the two functions
<Ref Attr="MonomialComparisonFunction"/> and
<Ref Attr="MonomialExtrepComparisonFun"/> to compare monomials.
These functions work as <Q>is less than</Q>,
i.e. they return <K>true</K> if and only if the left argument is smaller.
<P/>
<#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">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Groebner Bases">
<Heading>Groebner Bases</Heading>

A <E>Groebner Basis</E> of an ideal <M>I</M>i, in a polynomial ring <M>R</M>, with
respect to a monomial ordering, is a set of ideal generators <A>G</A> such that
the ideal generated by the leading monomials of all polynomials in <A>G</A> is
equal to the ideal generated by the leading monomials of all polynomials
in <A>I</A>.
<P/>
For more details on Groebner bases see <Cite Key="coxlittleoshea"/>.

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

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Rational Function Families">
<Heading>Rational Function Families</Heading>

All rational functions defined over a ring lie in the same family, the
rational functions family over this ring.
<P/>
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 <Q>compatible</Q>.

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

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="The Representations of Rational Functions">
<Heading>The Representations of Rational Functions</Heading>

&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).
<P/>
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&nbsp;<Ref Sect="Properties and Attributes of Rational Functions"/> will find
this out.
<P/>
Each representation is associated one or several <Q>defining attributes</Q>
that give an <Q>external</Q> representation
(see&nbsp;<Ref Sect="The Defining Attributes of Rational Functions"/>)
of the representation in the form of lists and are the defining information
that tells a rational function what it is.
<P/>
&GAP; also implements methods to compute these attributes for rational
functions in <E>other</E> representations, provided it would be possible to
express an <E>mathematically equal</E> 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.)
<P/>
Therefore these attributes can be thought of as <Q>conceptual</Q>
representations that allow us &ndash;as far as possible&ndash;
to consider an object as a rational function, a polynomial or a Laurent
polynomial, regardless of the way it is represented in the computer.
<P/>
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.
<P/>
Consequentially, methods for rational functions are installed for properties
and not for representations.
<P/>
When <E>creating</E> 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 <Q>conceptual</Q> representation in which the calculation was done
is the defining attribute.
<P/>
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.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="The Defining Attributes of Rational Functions">
<Heading>The Defining Attributes of Rational Functions</Heading>

In general, rational functions are given in terms of monomials.
They are represented by lists, using numbers
(see&nbsp;<Ref Sect="Indeterminates"/>) for the indeterminates.
<P/>
<#Include Label="[4]{ratfun}">
<#Include Label="[1]{ratfun}">
<P/>
The attributes that give a representation of a rational function as a Laurent polynomial are
<Ref Attr="CoefficientsOfLaurentPolynomial"/>
and <Ref Attr="IndeterminateNumberOfUnivariateRationalFunction"/>.
<P/>
<#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">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Creation of Rational Functions">
<Heading>Creation of Rational Functions</Heading>

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

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Arithmetic for External Representations of Polynomials">
<Heading>Arithmetic for External Representations of Polynomials</Heading>

The following operations are used internally to perform the arithmetic for
polynomials in their <Q>external</Q> representation
(see&nbsp;<Ref Sect="The Defining Attributes of Rational Functions"/>)
as lists.
<P/>
Functions to perform arithmetic with the coefficient lists of Laurent
polynomials are described in
Section&nbsp;<Ref Sect="Coefficient List Arithmetic"/>.

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

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Cancellation Tests for Rational Functions">
<Heading>Cancellation Tests for Rational Functions</Heading>

The operation <Ref Func="Gcd" Label="for (a ring and) several elements"/>
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="HeuristicCancelPolynomialsExtRep">

</Section>
</Chapter>


