(* :Title: Coefficients Functions *)
(* :Context: Coefficients` *)
(* :Author: Roberto Colistete Junior
Email : roberto@cce.ufes.br
*)
(* :Summary:
The Coefficients.m package provides some additional functions in order to
deal with coefficients of multivariable polynomials, without any dominant
variable.
*)
(* :Package Version: 1.1 *)
(* :Mathematica Version: 2.0 *)
(* :History:
V1.0, October 1995.
V1.1, November 1995, with optimized CoefficientListToPolynomial adapted
from Allan Hayes (MathGroup [mg2531]).
*)
(* :Keywords:
polynomial, coefficients, collect, expand, factor, simplify.
*)
(* :Limitations:
The user should be wary about high order polynomials, since CoefficientList
may return large arrays in such cases - for example, the simple polynomial
1 + x^1000 + y^1000 yields an array with about 3000 elements !
Thus, as all the functions defined here work with CoefficientList (or
CoefficientListToPolynomial), the main shortcoming of the package is its
limitation to low and medium order polynomials.
*)
BeginPackage["Coefficients`"]
CoefficientListToPolynomial::usage = "CoefficientListToPolynomial [coef, x]
inverts the operation of CoefficientList and returns a polynomial, so that
coef is the list returned by CoefficientList. The polynomial is returned with
terms of the same powers of x collected together.
\nCoefficientListToPolynomial [coef, {x1, x2, ...}] does the same thing to
xi, but without any 'dominant variable' xi, and it is necessary that the
number of variables xi be compatible with coef."
MapCoefficients::usage = "MapCoefficients[f, poly, x] applies the function f
to each coefficient of the polynomial poly in x.
\nMapCoefficients[f, poly, {x1, x2, ...}] does the same thing to xi, but
without any 'dominant variable' xi.
\nMapCoefficients[f, {poly1, poly2, ...}, x] and
\nMapCoefficients[f, {poly1, poly2, ...}, {x1, x2, ...}] are for lists of
polynomials."
CollectCoefficients::usage = "CollectCoefficients [poly, x] collects together
terms involving the same powers of x, in the polynomial poly.
\nCollectCoefficients [poly, {x1, x2, ...}] does the same thing to xi, but
without any 'dominant variable' xi.
\nCollectCoefficients [{poly1, poly2, ...}, x] and
\nCollectCoefficients [{poly1, poly2, ...}, {x1, x2, ...}] are for lists of
polynomials."
ExpandCoefficients::usage = "ExpandCoefficients [poly, x, (opts)] applies the
Expand function to the coefficients of the polynomial poly in x, collecting
together terms involving the same powers of x.
\nExpandCoefficients [poly, {x1, x2, ...}] does the same thing to xi, but
without any 'dominant variable' xi.
\nExpandCoefficients [{poly1, poly2, ...}, x] and
\nExpandCoefficients [{poly1, poly2, ...}, {x1, x2, ...}] are for lists of
polynomials."
FactorCoefficients::usage = "FactorCoefficients [poly, x, (opts)] applies the
Factor function to the coefficients of the polynomial poly in x, collecting
together terms involving the same powers of x.
\nFactorCoefficients [poly, {x1, x2, ...}] does the same thing to xi, but
without any 'dominant variable' xi.
\nFactorCoefficients [{poly1, poly2, ...}, x] and
\nFactorCoefficients [{poly1, poly2, ...}, {x1, x2, ...}] are for lists of
polynomials."
SimplifyCoefficients::usage = "SimplifyCoefficients [poly, x, (opts)] applies
the Simplify function to the coefficients of the polynomial poly in x,
collecting together terms involving the same powers of x.
\nSimplifyCoefficients [poly, {x1, x2, ...}] does the same thing to xi, but
without any 'dominant variable' xi.
\nSimplifyCoefficients [{poly1, poly2, ...}, x] and
\nSimplifyCoefficients [{poly1, poly2, ...}, {x1, x2, ...}] are for lists of
polynomials."
Begin["`Private`"]
CoefficientListToPolynomial [coef_List, x_] :=
Plus@@Flatten[MapIndexed[#1*Times@@(x^(#2 - 1))&, coef,
{If[Head[x] === List, Length[x], 1]}]]
MapCoefficients [f_, poly_, x_] :=
CoefficientListToPolynomial[Map[If[Head[#] === List, #, f[#]]&,
CoefficientList[poly, x], If[Head[x] === List, Length[x], 1]], x]
MapCoefficients [f_, poly_List, x_] := Map[MapCoefficients[f, #, x]&, poly]
CollectCoefficients [poly_, x_] := MapCoefficients[#&, poly, x]
ExpandCoefficients [poly_, x_, args___] :=
MapCoefficients[Expand[#, args]&, poly, x]
FactorCoefficients [poly_, x_, args___?OptionQ] :=
MapCoefficients[Factor[#, args]&, poly, x]
SimplifyCoefficients [poly_, x_, args___?OptionQ] :=
MapCoefficients[Simplify[#, args]&, poly, x]
End[]
Protect[CoefficientListToPolynomial, MapCoefficients, CollectCoefficients,
ExpandCoefficients, FactorCoefficients, SimplifyCoefficients]
EndPackage[]