MathGroup Archive 2006

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

Search the Archive

Re: Sequence@@List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64721] Re: Sequence@@List
  • From: Peter Pein <petsie at dordos.net>
  • Date: Wed, 1 Mar 2006 04:11:40 -0500 (EST)
  • References: <dtp535$ef6$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Martin Schoenecker schrieb:
> Hello,
> 
> I want to construct the corresponding variable list to a
> CoefficientList[poly, {var1, var2, var3,...}].
> 
> The following code does the work:
> 
> ---------------------------------------------------------
> In[472]:=
> vl = {x, y, z}
> dims = {2, 3, 2}
> r = Dimensions[dims]
> 
> Out[472]=
> {x,y,z}
> 
> Out[473]=
> {2,3,2}
> 
> Out[474]=
> {3}
> 
> In[475]:=
> Table[vl[[1]]^a*vl[[2]]^b*
>     vl[[3]]^c, {a, 0,
>     dims[[1]] - 1},
>    {b, 0, dims[[2]] - 1},
>    {c, 0, dims[[3]] - 1}]
> 
> Out[475]=
> \!\({{{1, z}, {y, y\ z}, {y\^2, y\^2\ z}}, {{x, x\
>          z}, {x\ y, x\ y\ z}, {x\ y\^2, x\ y\^2\ z}}}\)
> -----------------------------------------------------------
> 
> To do the job automated (so that a different variable list vl can be 
> used easily, as well as the output of Dimensions[CoefficientList[...]] 
> can be used as dims, for veriable polynomials and variables) I tried
> 
> ------------------------------------------------------------
> In[477]:=
> body = Product[vl[[k]]^i[k],
>     {k, 1, Dimensions[vl][[1]]}]
> iterator = Table[{i[ind], 0,
>      dims[[ind]] - 1},
>     {ind, 1, r[[1]]}]
> Table[body, Sequence @@ iterator]
> 
> Out[477]=
> x^i[1]*y^i[2]*z^i[3]
> 
> Out[478]=
> {{i[1], 0, 1}, {i[2], 0, 2},
>    {i[3], 0, 1}}
> 
>  From In[481]:=
> Table::"itform":"Argument \!\(Sequence @@ iterator\) at position \!\(2\) 
> does \
> not have the correct form for an iterator. \!\(\*ButtonBox[\"Mehrâ?¦\", \
> ButtonStyle->\"RefGuideLinkText\", ButtonFrame->None, \
> ButtonData:>\"General::itform\"]\)"
> ---------------------------------------------------------------
> 
> which does not work because in this case, because Sequence does not 
> strip the outer List brackets, while using it as the only argument to 
> some function, e.g.
> 
> ---------------------------------------------------------------
> In[480]:=
> f[Sequence @@ iterator]
> 
> Out[480]=
> f[{i[1], 0, 1}, {i[2], 0, 2},
>    {i[3], 0, 1}]
> ---------------------------------------------------------------
> 
> does work.
> 
> Any help regarding using Sequence in a function accepting more than just 
> one argument is appreciated!
> 
> Thank you,
> Martin
> 

Hi Martin,

may I suggest

Outer[Times, Sequence @@ (vl^(Range /@ dims - 1))]
-->
{{{1, z}, {y, y*z}, {y^2, y^2*z}}, {{x, x*z}, {x*y, x*y*z}, {x*y^2, x*y^2*z}}}

?

Peter


  • Prev by Date: Re: Re: Re: Mathematica:recursion with 2 arguments?
  • Next by Date: Re: Re: General--Making the DisplayFormula style in ArticleModern look like Traditional
  • Previous by thread: Re: Re: Re: Mathematica:recursion with 2 arguments?
  • Next by thread: Re: Sequence@@List