MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Final comments on CoefficientList

  • Subject: [mg2541] Re: [mg2516] Final comments on CoefficientList
  • From: hay%haystack at (Allan Hayes)
  • Date: Fri, 17 Nov 1995 05:20:22 GMT
  • Approved:
  • Distribution: local
  • Newsgroups: wri.mathgroup
  • Organization: Wolfram Research, Inc.
  • Sender: daemon at ( )

Scott Herod <sherod at boussinesq.Colorado.EDU>
in [mg2516] Final comments on CoefficientList

defines two new coefficient list functions (attached) that always  
give cuboidal arrays of the coefficients, unlike the built-in  
function, CoefficientList.

Here is another such function that is quicker and simpler.

   CoefficientList3[poly_, vars_]:=
         {Expand[(Times@@vars) poly]},
The function for getting back to the polynomial now simpler:
   CoeffsToPoly[c_,v_] :=

First construct a test polynomial (this one,pp, is of degree 4 in  
each of the variables x,y,z,u,v)

   ri := Random[Integer,{1,9}];
   vars = {x,y,z,u};
   pp =

   (cl3 = CoefficientList3[pp, vars]);//Timing
      {0.9 Second, Null}

Scott's two functions
   (cl1= myCoefList[pp, vars]);//Timing
      {31.0167 Second, Null}

   (cl2= myCoefList2[pp, vars]);//Timing
      {29.7167 Second, Null}

The built-in function
   (cl= CoefficientList[pp, vars]);//Timing
      {2.2 Second, Null}

   cl1 == cl2 ==cl3

   (pp - CoeffsToPoly[cl3,vars])//Expand

Allan Hayes
hay at


Scott's Code
( Scott sent me a correction to the last definition in the code for  

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__}] :=

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],
      coef[eqn, Inner[List, var, List[##], Sequence]] &,
      (Exponent[eqn,#] + 1 &) /@ var, 0]

  • Prev by Date: Re: (fix) bizarre mathematica replacement rule error
  • Next by Date: Re: turn off symbols in MultipleListPlot?
  • Previous by thread: Final comments on CoefficientList
  • Next by thread: Re: Final comments on CoefficientList