Structural Operations on Polynomials

Structural operations on polynomials.

Here is a polynomial in one variable:

(2+4 x^2)^2 (x-1)^3

(RefLink[Expand, paclet:ref/Expand]) expands out products and powers, writing the polynomial as a simple sum of terms:

t=Expand[%]

(RefLink[Factor, paclet:ref/Factor]) performs complete factoring of the polynomial:

Factor[t]

(RefLink[FactorTerms, paclet:ref/FactorTerms]) pulls out the overall numerical factor from t:

FactorTerms[t]

There are several ways to write any polynomial. The functions (RefLink[Expand, paclet:ref/Expand]), (RefLink[FactorTerms, paclet:ref/FactorTerms]), and (RefLink[Factor, paclet:ref/Factor]) give three common ways. (RefLink[Expand, paclet:ref/Expand]) writes a polynomial as a simple sum of terms, with all products expanded out. (RefLink[FactorTerms, paclet:ref/FactorTerms]) pulls out common factors from each term. (RefLink[Factor, paclet:ref/Factor]) does complete factoring, writing the polynomial as a product of terms, each of as low degree as possible.

When you have a polynomial in more than one variable, you can put the polynomial in different forms by essentially choosing different variables to be "dominant". (RefLink[Collect, paclet:ref/Collect])[poly,x] takes a polynomial in several variables and rewrites it as a sum of terms containing different powers of the "dominant variable" x.

Here is a polynomial in two variables:

Expand[(1+2x+y)^3]

(RefLink[Collect, paclet:ref/Collect]) reorganizes the polynomial so that x is the "dominant variable":

Collect[%,x]

If you specify a list of variables, (RefLink[Collect, paclet:ref/Collect]) will effectively write the expression as a polynomial in these variables:

Collect[Expand[(1+x+2y+3z)^3],{x,y}]

Controlling polynomial expansion.

This avoids expanding parts which do not contain x:

Expand[(x+1)^2 (y+1)^2,x]

This avoids expanding parts which do not contain objects matching b[_]:

Expand[(a[1]+a[2]+1)^2 (1+b[1])^2,b[_]]

Expanding powers and logarithms.

The Wolfram System does not automatically expand out expressions of the form (((ab))^c) except when c is an integer. In general it is only correct to do this expansion if a and b are positive reals. Nevertheless, the function (RefLink[PowerExpand, paclet:ref/PowerExpand]) does the expansion, effectively assuming that a and b are indeed positive reals.

The Wolfram System does not automatically expand out this expression:

(x y)^n

(RefLink[PowerExpand, paclet:ref/PowerExpand]) does the expansion, effectively assuming that x and y are positive reals:

PowerExpand[%]

(RefLink[Log, paclet:ref/Log]) is not automatically expanded out:

Log[%]

(RefLink[PowerExpand, paclet:ref/PowerExpand]) does the expansion:

PowerExpand[%]

(RefLink[PowerExpand, paclet:ref/PowerExpand]) returns a result correct for the given assumptions:

PowerExpand[%%,Assumptions->{x>0,n<0}]

Ways of collecting terms.

Here is an expression involving various functions f:

t=3+x f[1]+x^2 f[1]+y f[2]^2+z f[2]^2

This collects terms that match f[_]:

Collect[t,f[_]]

This applies (RefLink[Factor, paclet:ref/Factor]) to each coefficient obtained:

Collect[t,f[_],Factor]

Horner form.

Horner form is a way of arranging a polynomial that allows numerical values to be computed more efficiently by minimizing the number of multiplications.

This gives the Horner form of a polynomial:

HornerForm[1+2x+3x^2+4x^3,x]