Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: Rebuilding polygon from CoefficientList?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20192] Re: [mg20164] Rebuilding polygon from CoefficientList?
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Tue, 5 Oct 1999 04:04:22 -0400
  • References: <199910040107.VAA17273@smc.vnet.net.>
  • Sender: owner-wri-mathgroup at wolfram.com

Holger Strauss wrote:
> 
> Hallo,
> 
> I have a mixed polynomial poly in several variables vars.
> 
> cl = CoefficientList[poly, vars]
> 
> gives a multi-dimensional matrix of coefficients.
> 
> Can anyone help with an algorithm/expression that
> re-constructs the original poly given cl and vars?
> (In practice, I'd like to manipulate the coefficients before
> reconstructing the polynomial; otherwise this wouldn't
> make sense).
> The algorithm must be able to handle any number of vars.
> I've found a solutions for a small and fixed number of vars
> using some ugly nested For loops. However, I suppose
> that there must be a more efficient solution using some cute
> matrix operations.
> 
> Many thanks,
> Holger
> 
> Holger Strauss
> Institute of Communication Acoustics
> Ruhr-University Bochum


Here is one method.

FromCoefficientList[poly_, var_] /; Head[var]=!=List :=
	FromCoefficientList[poly, {var}]
FromCoefficientList[poly_, {var_}] := poly . var^(Range[Length[poly]]-1)
FromCoefficientList[poly_, {var1_, rest__}] := With[
	{partial = Map[FromCoefficientList[#,rest]&,poly]},
	FromCoefficientList[partial, var1]
	]

SImple example:

In[9]:= poly = CoefficientList[1+2*x + y^2, {x,y}]
Out[9]= {{1, 0, 1}, {2, 0, 0}}

In[10]:= FromCoefficientList[poly, {z,w}]
              2
Out[10]= 1 + w  + 2 z

In our development version we have a built in function that will do
this, though it is experimental and not in the System context.

As you realize, CoefficientList generates the densest possible
structure. For many purposes this may not be what you want; in
particular, it can be a memory hog if either degree or number of
variables exceeds quite modest bounds. So one might prefer to work with
sparse representations. To this end, tentative functionality present in
version 4 includes

In[5]:= poly = Internal`NestedTermsList[1+2*x + y^2, {x,y}]
Out[5]= {{1, {{0, 2}}}, {0, {{2, 1}, {0, 1}}}}

In[6]:= Internal`FromNestedTermsList[poly, {z,w}]
             2
Out[6]= 1 + w  + 2 z

One can also obtain a sparse, distributed (rather than recursive)
representation. In this case the variables are stored as part of the
data structure and hence cannot be altered. Of course they might be
changed after the fact by replacement.

In[9]:= poly2 = Internal`DistributedTermsList[1+2*x + y^2, {x,y}]
Out[9]= {{{{1, 0}, 2}, {{0, 2}, 1}, {{0, 0}, 1}}, {x, y}}

In[10]:= Internal`FromDistributedTermsList[poly2]
                    2
Out[10]= 1 + 2 x + y


Daniel Lichtblau
Wolfram Research


  • Prev by Date: Re: adjusting frame size in plot
  • Next by Date: Re: NonlinearRegress and numerical functions...
  • Previous by thread: Rebuilding polygon from CoefficientList?
  • Next by thread: Re: Rebuilding polygon from CoefficientList?