Re: How to map a list on function

*To*: mathgroup at smc.vnet.net*Subject*: [mg97544] Re: How to map a list on function*From*: Helen Read <hpr at together.net>*Date*: Sat, 14 Mar 2009 18:17:57 -0500 (EST)*References*: <gpg18t$ceh$1@smc.vnet.net>*Reply-to*: HPR <read at math.uvm.edu>

buts wrote: > Hello, > > Could anyone explain me how to do the following: > I have a long list of integer numbers in groups of four: > > list= {{10,3,5,7},{4,6,8,9},{0,8,3,6}, ...... } > > or its Flatten version. > > How to write a fast function g[list] which does this: > > g[list] =x^10*y^3*z^5*u^7 + x^4*y^6*z^8*u^9 + y^8*z^3*u^6+ ... > > It should be done many times (say, 10^4-6) on lists with length > 1000, so taking parts is not a good idea. > How to use Map or similar ? > Thanks. Here's one straightforward way to do it. First, define a function gg[t] that acts on a 4-tuple t. gg[t_List] := x^t[[1]] y^t[[2]] z^t[[3]] u^t[[4]] Try this out on a single 4-tuple: t1={5,4,6,2} gg[t1] Now, define a function to Map gg over the list of 4-tuples and Total the results. g[list_List] := Total[Map[gg, list]] Try it on a list of 1000 4-tuples: list1 = RandomInteger[{0, 15}, {1000, 4}] g[list1] -- Helen Read University of Vermont