(directly go to documentation on : Expand, Degree, Coef, Content, PrimitivePart, LeadingCoef, Monic, SquareFree, SquareFreeFactorize, Horner, ExpandBrackets, EvaluateHornerScheme.
)
19. Operations on polynomials
This chapter contains commands to manipulate
polynomials. This includes functions for constructing and evaluating
orthogonal polynomials.
Expand -- transform a polynomial to an expanded form
Standard library
Calling format:
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
$c_{0} + c_{1} x + c_{2} x ^{2} + \mathrm{ ... } + c _{n} 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'Set("PrettyForm");
True
|
In> Expand((1+x)^5);
5 4 3 2
x + 5 * x + 10 * x + 10 * x + 5 * x + 1
|
In> Expand((1+x-y)^2, x);
2 2
x + 2 * ( 1 - y ) * x + ( 1 - y )
|
In> Expand((1+x-y)^2, {x,y});
2 2
x + ( -2 * y + 2 ) * x + y - 2 * y + 1
|
See also:
ExpandBrackets
.
Degree -- degree of a polynomial
Standard library
Calling format:
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 library
Calling format:
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 library
Calling format:
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 library
Calling format:
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 library
Calling format:
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 library
Calling format:
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
.
SquareFree -- return the square-free part of polynomial
Standard library
Calling format:
Parameters:
p - a polynomial in x
Description:
Given a polynomial
$$p = p _{1} ^{n _{1}} \mathrm{ ... } p _{m} ^{n _{m}}$$
with irreducible polynomials $p _{i}$,
return the square-free version part (with all the factors having
multiplicity 1):
$$p _{1} \mathrm{ ... } p _{m}$$
Examples:
In> Expand((x+1)^5)
Out> x^5+5*x^4+10*x^3+10*x^2+5*x+1;
In> SquareFree(%)
Out> (x+1)/5;
In> Monic(%)
Out> x+1;
|
See also:
FindRealRoots
,
NumRealRoots
,
MinimumBound
,
MaximumBound
,
Factor
.
SquareFreeFactorize -- return square-free decomposition of polynomial
Standard library
Calling format:
Parameters:
p - a polynomial in x
Description:
Given a polynomial $p$ having square-free decomposition
$$p = p _{1} ^{n _{1}} \mathrm{ ... } p _{m} ^{n _{m}}$$
where $p _{i}$ are square-free and $n _{i + 1} > n _{i}$,
return the list of pairs ($p _{i}$, $n _{i}$)
Examples:
In> Expand((x+1)^5)
Out> x^5+5*x^4+10*x^3+10*x^2+5*x+1
In> SquareFreeFactorize(%,x)
Out> {{x+1,5}}
|
See also:
Factor
.
Div and Mod for polynomials
Standard library
Div and Mod are also defined for polynomials.
See also:
Div
,
Mod
.
Horner -- convert a polynomial into the Horner form
Standard library
Calling format:
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 such as
$$c _{0} + c _{1} x + \mathrm{ ... } + c _{n} x ^{n}.$$
If one converts this polynomial into Horner form, one gets the
equivalent expression
$$\left( \mathrm{ ... }\left( c _{n} x + c _{n - 1}\right) x + \mathrm{ ... } + c _{1}\right) 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
,
EvaluateHornerScheme
.
ExpandBrackets -- expand all brackets
Standard library
Calling format:
Parameters:
expr -- an expression
Description:
This command tries to expand all the brackets by repeatedly using the
distributive laws $a \left( b + c\right) = a b + a c$ and $\left( a + b\right) c = a c + b c$.
It goes further than Expand, in that it expands all brackets.
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
.
EvaluateHornerScheme -- fast evaluation of polynomials
Standard library
Calling format:
EvaluateHornerScheme(coeffs,x)
|
Parameters:
coeffs -- a list of coefficients
x -- expression
Description:
This function evaluates a polynomial given as a list of its coefficients, using
the Horner scheme. The list of coefficients starts with the $0$-th power.
Example:
In> EvaluateHornerScheme({a,b,c,d},x)
Out> a+x*(b+x*(c+x*d));
|
See also:
Horner
.