Expand , Degree , Coef , Content , PrimitivePart , LeadingCoef , Monic , RandomPoly , Horner , ExpandBrackets .

# Polynomials

This chapter contains commands to manipulate polynomials.

Expand | Put polynomial in expanded form
Degree | Degree of a polynomial
Coef | Coefficient of a polynomial
Content | Content of a univariate polynomial
PrimitivePart | Primitive part of a univariate polynomial
LeadingCoef | Leading coefficient of a polynomial
Monic | Monic part of a polynomial
RandomPoly | Construct a random polynomial
Horner | Convert polynomial in Horner form
ExpandBrackets | Expand all terms

###

Expand -- Put polynomial in expanded form

Standard math library

##### Calling Sequence:

Expand(expr)
Expand(expr, var)
Expand(expr, varlist)

##### Parameters:

expr - a polynomial expression
var - a variable
varlist - a list of variables

##### Description:

This command brings a polynomial in expanded form, in which polynomials are represented in the form c0 + c1*x + c2*x^2 + ... + cn*x^n. In this form, it is easier to test whether a polynomial is zero, namely by testing whether all coefficients are zero.

If the polynomial "expr" contains only one variable, the first calling sequence can be used. Otherwise, the second form should be used which explicitly mentions that "expr" should be considered as a polynomial in the variable "var". The third calling form can be used for multivariate polynomials. Firstly, the polynomial "expr" is expanded with respect to the first variable in "varlist". Then the coefficients are all expanded with respect to the second variable, and so on.

##### Examples:

    In> PrettyPrinter("PrettyForm");

    True

    Out>
    In> Expand((1+x)^5);

     5        4         3         2
    x  + 5 * x  + 10 * x  + 10 * x  + 5 * x + 1

    Out>
    In> Expand((1+x-y)^2, x);

     2                                2
    x  + 2 * ( 1 - y ) * x + ( 1 - y )

    Out>
    In> Expand((1+x-y)^2, {x,y});

     2                         2
    x  + ( -2 * y + 2 ) * x + y  - 2 * y + 1

    Out>

##### See Also:

ExpandBrackets .

###

Degree -- Degree of a polynomial

Standard math library

##### Calling Sequence:

Degree(expr)
Degree(expr, var)

##### Parameters:

expr - a polynomial
var - a variable occurring in "expr"

##### Description:

This command returns the degree of the polynomial "expr" with respect to the variable "var". The degree is the highest power of "var" occurring in the polynomial. If only one variable occurs in "expr", the first calling sequence can be used. Otherwise the user should use the second form in which the variable is explicitly mentioned.

##### Examples:

    In> Degree(x^5+x-1);
    Out> 5;
    In> Degree(a+b*x^3, a);
    Out> 1;
    In> Degree(a+b*x^3, x);
    Out> 3;

##### See Also:

Expand , Coef .

###

Coef -- Coefficient of a polynomial

Standard math library

##### Calling Sequence:

Coef(expr, var, order)

##### Parameters:

expr - a polynomial
var - a variable occurring in "expr"
order - integer or list of integers

##### Description:

This command returns the coefficient of "var" to the power "order" in the polynomial "expr". The parameter "order" can also be a list of integers, in which case this function returns a list of coefficients.

##### Examples:

    In> e := Expand((a+x)^4,x)
    Out> x^4+4*a*x^3+(a^2+(2*a)^2+a^2)*x^2+(a^2*2*a+2*a^3)*x+a^4;
    In> Coef(e,a,2)
    Out> 6*x^2;
    In> Coef(e,a,0 .. 4)
    Out> {x^4,4*x^3,6*x^2,4*x,1};

##### See Also:

Expand , Degree , LeadingCoef .

###

Content -- Content of a univariate polynomial

Standard math library

##### Calling Sequence:

Content(expr)

##### Parameters:

expr - univariate polynomial

##### Description:

This command determines the content of a univariate polynomial. The content is the greatest common divisor of all the terms in the polynomial. Every polynomial can be written as the product of the content with the primitive part.

##### Examples:

    In> poly := 2*x^2 + 4*x;
    Out> 2*x^2+4*x;
    In> c := Content(poly);
    Out> 2*x;
    In> pp := PrimitivePart(poly);
    Out> x+2;
    In> Expand(pp*c);
    Out> 2*x^2+4*x;

##### See Also:

PrimitivePart , Gcd .

###

PrimitivePart -- Primitive part of a univariate polynomial

Standard math library

##### Calling Sequence:

PrimitivePart(expr)

##### Parameters:

expr - univariate polynomial

##### Description:

This command determines the primitive part of a univariate polynomial. The primitive part is what remains after the content (the greatest common divisor of all the terms) is divided out. So the product of the content and the primitive part equals the original polynomial.

##### Examples:

    In> poly := 2*x^2 + 4*x;
    Out> 2*x^2+4*x;
    In> c := Content(poly);
    Out> 2*x;
    In> pp := PrimitivePart(poly);
    Out> x+2;
    In> Expand(pp*c);
    Out> 2*x^2+4*x;

##### See Also:

Content .

###

LeadingCoef -- Leading coefficient of a polynomial

Standard math library

##### Calling Sequence:

LeadingCoef(poly)
LeadingCoef(poly, var)

##### Parameters:

poly - a polynomial
var - a variable

##### Description:

This function returns the leading coefficient of "poly", regarded as a polynomial in the variable "var". The leading coefficient is the coefficient of the term of highest degree. If only one variable appears in the expression "poly", it is obvious that it should be regarded as a polynomial in this variable and the first calling sequence may be used.

##### Examples:

    In> poly := 2*x^2 + 4*x;
    Out> 2*x^2+4*x;
    In> lc := LeadingCoef(poly);
    Out> 2;
    In> m := Monic(poly);
    Out> x^2+2*x;
    In> Expand(lc*m);
    Out> 2*x^2+4*x;

    In> LeadingCoef(2*a^2 + 3*a*b^2 + 5, a);
    Out> 2;
    In> LeadingCoef(2*a^2 + 3*a*b^2 + 5, b);
    Out> 3*a;

##### See Also:

Coef , Monic .

###

Monic -- Monic part of a polynomial

Standard math library

##### Calling Sequence:

Monic(poly)
Monic(poly, var)

##### Parameters:

poly - a polynomial
var - a variable

##### Description:

This function returns the monic part of "poly", regarded as a polynomial in the variable "var". The monic part of a polynomial is the quotient of this polynomial by its leading coefficient. So the leading coefficient of the monic part is always one. If only one variable appears in the expression "poly", it is obvious that it should be regarded as a polynomial in this variable and the first calling sequence may be used.

##### Examples:

    In> poly := 2*x^2 + 4*x;
    Out> 2*x^2+4*x;
    In> lc := LeadingCoef(poly);
    Out> 2;
    In> m := Monic(poly);
    Out> x^2+2*x;
    In> Expand(lc*m);
    Out> 2*x^2+4*x;

    In> Monic(2*a^2 + 3*a*b^2 + 5, a);
    Out> a^2+(a*3*b^2)/2+5/2;
    In> Monic(2*a^2 + 3*a*b^2 + 5, b);
    Out> b^2+(2*a^2+5)/(3*a);

##### See Also:

LeadingCoef .

###

RandomPoly -- Construct a random polynomial

Standard math library

##### Calling Sequence:

RandomPoly(var,deg,coefmin,coefmax)

##### Parameters:

var - free variable for resulting univariate polynomial
deg - degree of resulting univariate polynomial
coefmin - minimum value for coefficients
coefmax - maximum value for coefficients

##### Description:

RandomPoly generates a random polynomial in variable "var", of degree "deg", with integer coefficients ranging from "coefmin" to "coefmax" (inclusive). The coefficients are uniformly distributed in this interval, and are independent of each other.

##### Examples:

    In> RandomPoly(x,3,-10,10)
    Out> 3*x^3+10*x^2-4*x-6;
    In> RandomPoly(x,3,-10,10)
    Out> -2*x^3-8*x^2+8;

##### See Also:

Random , RandomIntegerVector .

###

Div and Mod for polynomials

Standard math library
Div and Mod are also defined for polynomials.

##### See Also:

Div , Mod .

###

Horner -- Convert polynomial in Horner form

Standard math library

##### Calling Sequence:

Horner(expr, var)

##### Parameters:

expr - a polynomial in "var"
var - a variable

##### Description:

This command turns the polynomial "expr", considered as a univariate polynomial in "var", into Horner form. A polynomial in normal form is an expression like

                                      n-1           n
    c(0) + c(1) * x + ... + c(n-1) * x    + c(n) * x

If one converts this polynomial in Horner form, one gets the equivalent expression

    (...( c(n) * x + c(n-1) ) * x + ...  + c(1) ) * x + c(0)

Both expression are equal, but the latter form gives a more efficient way to evaluate the polynomial as the powers have disappeared.

##### Examples:

    In> expr1:=Expand((1+x)^4)
    Out> x^4+4*x^3+6*x^2+4*x+1
    In>  Horner(expr1,x)
    Out> (((x+4)*x+6)*x+4)*x+1

##### See Also:

Expand , ExpandBrackets .

###

ExpandBrackets -- Expand all terms

Standard math library

##### Calling Sequence:

ExpandBrackets(expr)

##### Parameters:

expr - an expression

##### Description:

This command tries to expand all the brackets by repeatedly using the distributive laws "a * (b+c) = a*b + a*c" and "(a+b) * c = a*c + b*c". It goes further than `Expand`, in that it expands all terms.

##### Examples:

    In> Expand((a-x)*(b-x),x)
    Out> x^2-(b+a)*x+a*b;
    In> Expand((a-x)*(b-x),{x,a,b})
    Out> x^2-(b+a)*x+b*a;
    In> ExpandBrackets((a-x)*(b-x))
    Out> a*b-x*b+x^2-a*x;

##### See Also:

Expand .