       Final comments on CoefficientList

• To: mathgroup at smc.vnet.net
• Subject: [mg2516] Final comments on CoefficientList
• From: sherod at boussinesq.Colorado.EDU (Scott Herod)
• Date: Wed, 15 Nov 1995 02:01:53 -0500
• Organization: University of Colorado at Boulder

```I'm pretty sure that CoefficientList has a bug in it.  The simplest
example is

In:= CoefficientList[0,x]

Out= {}

But,

In:= PolynomialQ[0,x]

Out= True

This causes more problems when you try to create the list of coefficients
of a polynomial in multiple variables.

In:= CoefficientList[ x y + x y^2, {y,x}]

Out= {{}, {0, 1}, {0, 1}}

In:= CoefficientList[x y + x y^2, {x,y}]

Out= {{}, {0, 1, 1}}

Below are two functions which (I think) act correctly.  Neither makes use
of caching as discussed by David Wagner in the most recent Mathematica
Journal but such could be added easily.  I would appreciate comments on
improvements of these because I need to run them MANY times.

myCoefList[eqn_, x_Symbol] := myCoefList[eqn,{x}];
myCoefList[{eqn_}, x__] := myCoefList[eqn, x];
myCoefList[{eqn1_, eqn2__}, x__] :=
{myCoefList[eqn1, x], myCoefList[{eqn2}, x]};

myCoefList[eqn_, {x_}] :=
Table[Coefficient[eqn,x,i], {i,0, Max[Exponent[eqn, x],0]}];
myCoefList[eqn_, {x_, y__}] :=
Table[Coefficient[myCoefList[eqn,y],x,i],
{i,0,Max[Exponent[eqn,x],0]}];

myCoefList2[eqn_, var_] := Module[{coef, spam, a, b, c},
myCoefList::polynomial = "The equation is not a polynomial
in the variables";
coef[spam_, {a_, b_}] := Coefficient[spam, a, b];
coef[spam_, {a_, b_}, c__] := Coefficient[coef[spam, c], a, b];
If[PolynomialQ[eqn, var],
Array[
coef[eqn, Inner[List, var, List[##], Sequence]] &,
(Exponent[eqn,#] + 1 &) /@ var, 0]
,
Message[myCoefList::polynomial];
]
]

Scott A. Herod
Applied Mathematics
University of Colorado, Boulder

```

• Prev by Date: pRe: Writing big files with Mathematica
• Next by Date: Problems with high-dimensional lists
• Previous by thread: Final comments on CoefficientList
• Next by thread: Re: Final comments on CoefficientList