Re: Enhance a function that involve list
- To: mathgroup at smc.vnet.net
- Subject: [mg36102] Re: Enhance a function that involve list
- From: hartmut.wolf at t-systems.com (Hartmut Wolf)
- Date: Wed, 21 Aug 2002 05:52:12 -0400 (EDT)
- References: <aj7o7a$2qf$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"J. Guillermo Sanchez" <guillerm at usal.es> wrote in message news:<aj7o7a$2qf$1 at smc.vnet.net>...
> Dear friends
> I wish to build a function to obtain from a list (i.e.:)
>
> list = {a1, a2, a3, a4};
>
> and output like this:
>
> {{f[a2, a1, a2]},
> {f[a3, a1, a2], f[a3, a2, a3]},
> {f[a4, a1, a2], f[a4, a2, a3], f[a4, a3, a4]}}
>
> This following function work fine
>
>
> function1[tau1_] :=
> Table[Table[
> f[Extract[tau1, j + 1], Extract[tau1, i], Extract[tau1, i + 1]],
> {i, 1,
> Length[tau1] - Length[tau1] + j}], {j, 1, Length[tau1] - 1}]
>
> function1[list] // TableForm
>
>
> but I think is not so eleghant. I will appreciate any help to build a
> more effecient and eleghant solution
>
> Guillermo Sanchez
If you like this...
In[1]:= lst = {a1, a2, a3, a4};
In[2]:=
With[{len = Length[lst]},
Table[f @@ lst[[{i, j - 1, j}]], {i, 2, len}, {j, 2, i}]]
Out[2]=
{{f[a2, a1, a2]},
{f[a3, a1, a2], f[a3, a2, a3]},
{f[a4, a1, a2], f[a4, a2, a3], f[a4, a3, a4]}}
--
Hartmut