Re: Sequence@@List
- To: mathgroup at smc.vnet.net
- Subject: [mg64671] Re: [mg64644] Sequence@@List
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sun, 26 Feb 2006 05:07:53 -0500 (EST)
- Reply-to: hanlonr at cox.net
- Sender: owner-wri-mathgroup at wolfram.com
vl={x,y,z};
dims={2,3,2};
r=Length[dims];
t=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}];
Your problem arises because Table has the attribute HoldAll
Attributes[Table]
{HoldAll,Protected}
body=Product[vl[[k]]^i[k],{k,r}];
iterator=Table[{i[ind],0,dims[[ind]]-1},{ind,r}];
Table[body,Evaluate[Sequence@@ iterator]]==t
True
Bob Hanlon
>
> From: Martin Schoenecker <ms_usenet at gmx.de>
To: mathgroup at smc.vnet.net
> Subject: [mg64671] [mg64644] Sequence@@List
>
> 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
>
>