# 9.63 PolynomialΒΆ

The domain constructor Polynomial (abbreviation: POLY) provides polynomials with an arbitrary number of unspecified variables.

It is used to create the default polynomial domains in FriCAS. Here the coefficients are integers.

x + 1


 x+1

Type: Polynomial Integer

Here the coefficients have type Float.

z - 2.3


 z-2.3

Type: Polynomial Float

And here we have a polynomial in two variables with coefficients which have type Fraction Integer.

y^2 - z + 3/4


 -z+y2+34

Type: Polynomial Fraction Integer

The representation of objects of domains created by Polynomial is that of recursive univariate polynomials.The term univariate means one variable. multivariate means possibly more than one variable.

This recursive structure is sometimes obvious from the display of a polynomial.

y ^2 + x*y + y


 y2+(x+1)y

Type: Polynomial Integer

In this example, you see that the polynomial is stored as a polynomial in y with coefficients that are polynomials in x with integer coefficients. In fact, you really don’t need to worry about the representation unless you are working on an advanced application where it is critical. The polynomial types created from DistributedMultivariatePolynomial and NewDistributedMultivariatePolynomial (discussed in DistributedMultivariatePolynomialXmpPage ) are stored and displayed in a non-recursive manner.

You see a flat display of the above polynomial by converting to one of those types.

% :: DMP([y,x],INT)


 y2+yx+y

Type: DistributedMultivariatePolynomial([y,x],Integer)

We will demonstrate many of the polynomial facilities by using two polynomials with integer coefficients.

By default, the interpreter expands polynomial expressions, even if they are written in a factored format.

p := (y-1)^2 * x * z


 (xy2-2xy+x)z

Type: Polynomial Integer

See FactoredXmpPage to see how to create objects in factored form directly.

q := (y-1) * x * (z+5)


 (xy-x)z+5xy-5x

Type: Polynomial Integer

The fully factored form can be recovered by using factorfactorPolynomial.

factor(q)


 x(y-1)(z+5)

Type: Factored Polynomial Integer

This is the same name used for the operation to factor integers. Such reuse of names is called overloading and makes it much easier to think of solving problems in general ways. FriCAS facilities for factoring polynomials created with Polynomial are currently restricted to the integer and rational number coefficient cases. There are more complete facilities for factoring univariate polynomials: see ugProblemFactorPage in Section ugProblemFactorNumber .

The standard arithmetic operations are available for polynomials.

p - q^2


 (-x2y2+2x2y-x2)z2+((-10x2+x)y2+(20x2-2x)y-10x2+x)z-25x2y2+50x2y-25x2

Type: Polynomial Integer

The operation gcdgcdPolynomial is used to compute the greatest common divisor of two polynomials.

gcd(p,q)


 xy-x

Type: Polynomial Integer

In the case of p and q, the gcd is obvious from their definitions. We factor the gcd to show this relationship better.

factor %


 x(y-1)

Type: Factored Polynomial Integer

The least common multiple is computed by using lcmlcmPolynomial.

lcm(p,q)


 (xy2-2xy+x)z2+(5xy2-10xy+5x)z

Type: Polynomial Integer

Use contentcontentPolynomial to compute the greatest common divisor of the coefficients of the polynomial.

content p


 1

Type: PositiveInteger

Many of the operations on polynomials require you to specify a variable. For example, resultantresultantPolynomial requires you to give the variable in which the polynomials should be expressed.

This computes the resultant of the values of p and q, considering them as polynomials in the variable z. They do not share a root when thought of as polynomials in z.

resultant(p,q,z)


 5x2y3-15x2y2+15x2y-5x2

Type: Polynomial Integer

This value is 0 because as polynomials in x the polynomials have a common root.

resultant(p,q,x)


 0

Type: Polynomial Integer

The data type used for the variables created by Polynomial is Symbol. As mentioned above, the representation used by Polynomial is recursive and so there is a main variable for nonconstant polynomials.

The operation mainVariablemainVariablePolynomial returns this variable. The return type is actually a union of Symbol and “failed”.

mainVariable p


 z

Type: Union(Symbol,...)

The latter branch of the union is be used if the polynomial has no variables, that is, is a constant.

mainVariable(1 :: POLY INT)


 “failed”

Type: Union(“failed”,...)

You can also use the predicate ground?ground?Polynomial to test whether a polynomial is in fact a member of its ground ring.

ground? p


 false

Type: Boolean

ground?(1 :: POLY INT)


 true

Type: Boolean

The complete list of variables actually used in a particular polynomial is returned by variablesvariablesPolynomial. For constant polynomials, this list is empty.

variables p


 [z,y,x]

Type: List Symbol

The degreedegreePolynomial operation returns the degree of a polynomial in a specific variable.

degree(p,x)


 1

Type: PositiveInteger

degree(p,y)


 2

Type: PositiveInteger

degree(p,z)


 1

Type: PositiveInteger

If you give a list of variables for the second argument, a list of the degrees in those variables is returned.

degree(p,[x,y,z])


 [1,2,1]

Type: List NonNegativeInteger

The minimum degree of a variable in a polynomial is computed using minimumDegreeminimumDegreePolynomial.

minimumDegree(p,z)


 1

Type: PositiveInteger

The total degree of a polynomial is returned by totalDegreetotalDegreePolynomial.

totalDegree p


 4

Type: PositiveInteger

It is often convenient to think of a polynomial as a leading monomial plus the remaining terms.

leadingMonomial p


 xy2z

Type: Polynomial Integer

The reductumreductumPolynomial operation returns a polynomial consisting of the sum of the monomials after the first.

reductum p


 (-2xy+x)z

Type: Polynomial Integer

These have the obvious relationship that the original polynomial is equal to the leading monomial plus the reductum.

p - leadingMonomial p - reductum p


 0

Type: Polynomial Integer

leadingCoefficient p


 1

Type: PositiveInteger

The operation evalevalPolynomial is used to substitute a value for a variable in a polynomial.

p


 (xy2-2xy+x)z

Type: Polynomial Integer

This value may be another variable, a constant or a polynomial.

eval(p,x,w)


 (wy2-2wy+w)z

Type: Polynomial Integer

eval(p,x,1)


 (y2-2y+1)z

Type: Polynomial Integer

Actually, all the things being substituted are just polynomials, some more trivial than others.

eval(p,x,y^2 - 1)


 (y4-2y3+2y-1)z

Type: Polynomial Integer

Derivatives are computed using the DDPolynomial operation.

D(p,x)


 (y2-2y+1)z

Type: Polynomial Integer

The first argument is the polynomial and the second is the variable.

D(p,y)


 (2xy-2x)z

Type: Polynomial Integer

Even if the polynomial has only one variable, you must specify it.

D(p,z)


 xy2-2xy+x

Type: Polynomial Integer

Integration of polynomials is similar and the integrateintegratePolynomial operation is used.

Integration requires that the coefficients support division. Consequently, FriCAS converts polynomials over the integers to polynomials over the rational numbers before integrating them.

integrate(p,y)


 (13xy3-xy2+xy)z

Type: Polynomial Fraction Integer

It is not possible, in general, to divide two polynomials. In our example using polynomials over the integers, the operation monicDividemonicDividePolynomial divides a polynomial by a monic polynomial (that is, a polynomial with leading coefficient equal to 1). The result is a record of the quotient and remainder of the division.

You must specify the variable in which to express the polynomial.

qr := monicDivide(p,x+1,x)


 [quotient=(y2-2y+1)z,remainder=(-y2+2y-1)z]

Type: Record(quotient: Polynomial Integer,remainder: Polynomial Integer)

The selectors of the components of the record are quotient and remainder. Issue this to extract the remainder.

qr.remainder


 (-y2+2y-1)z

Type: Polynomial Integer

Now that we can extract the components, we can demonstrate the relationship among them and the arguments to our original expression qr := monicDivide(p,x+1,x).

p - ((x+1) * qr.quotient + qr.remainder)


 0

Type: Polynomial Integer

If the / operator is used with polynomials, a fraction object is created. In this example, the result is an object of type Fraction Polynomial Integer.

p/q


 (y-1)zz+5

Type: Fraction Polynomial Integer

If you use rational numbers as polynomial coefficients, the resulting object is of type Polynomial Fraction Integer.

(2/3) * x^2 - y + 4/5


 -y+23x2+45

Type: Polynomial Fraction Integer

This can be converted to a fraction of polynomials and back again, if required.

% :: FRAC POLY INT


 -15y+10x2+1215

Type: Fraction Polynomial Integer

% :: POLY FRAC INT


 -y+23x2+45

Type: Polynomial Fraction Integer

To convert the coefficients to floating point, map the numeric operation on the coefficients of the polynomial.

map(numeric,%)


 -1.0y+0.66666666666666666667x2+0.8

Type: Polynomial Float

For more information on related topics, see UnivariatePolynomialXmpPage , MultivariatePolynomialXmpPage , and DistributedMultivariatePolynomialXmpPage . You can also issue the system command )show Polynomial to display the full list of operations defined by Polynomial.