       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)
• Sender: owner-wri-mathgroup at wolfram.com

```vl={x,y,z};
dims={2,3,2};
r=Length[dims];

t=Table[vl[]^a*vl[]^b*vl[]^c,
{a,0,dims[]-1},
{b,0,dims[]-1},
{c,0,dims[]-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:=
> vl = {x, y, z}
> dims = {2, 3, 2}
> r = Dimensions[dims]
>
> Out=
> {x,y,z}
>
> Out=
> {2,3,2}
>
> Out=
> {3}
>
> In:=
> Table[vl[]^a*vl[]^b*
>     vl[]^c, {a, 0,
>     dims[] - 1},
>    {b, 0, dims[] - 1},
>    {c, 0, dims[] - 1}]
>
> Out=
> \!\({{{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:=
> body = Product[vl[[k]]^i[k],
>     {k, 1, Dimensions[vl][]}]
> iterator = Table[{i[ind], 0,
>      dims[[ind]] - 1},
>     {ind, 1, r[]}]
> Table[body, Sequence @@ iterator]
>
> Out=
> x^i*y^i*z^i
>
> Out=
> {{i, 0, 1}, {i, 0, 2},
>    {i, 0, 1}}
>
>  From In:=
> Table::"itform":"Argument \!\(Sequence @@ iterator\) at position \!\(2\)
> does \
> not have the correct form for an iterator. \!\(\*ButtonBox[\"Mehrâ?¦\", \
> 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:=
> f[Sequence @@ iterator]
>
> Out=
> f[{i, 0, 1}, {i, 0, 2},
>    {i, 0, 1}]
> ---------------------------------------------------------------
>
> does work.
>
> Any help regarding using Sequence in a function accepting more than just
> one argument is appreciated!
>
> Thank you,
> Martin
>
>

```

• Prev by Date: Re: Re: Code to translate to negative base...
• Next by Date: Re: Forcing surds into the numerator
• Previous by thread: Re: Sequence@@List
• Next by thread: Q: How do I format text within a cell of GridBox[]?