Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: How to map a list on function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97563] Re: How to map a list on function
  • From: Raffy <raffy at mac.com>
  • Date: Sun, 15 Mar 2009 05:29:11 -0500 (EST)
  • References: <gpg18t$ceh$1@smc.vnet.net>

On Mar 14, 3:35 am, buts <mange... at yahoo.com> 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, s=
o taking parts is not a good idea.
> How to use Map or similar ?
> Thanks.

mPowers = RandomInteger[{0, 1}, {100, 4}];
vSymbols = {x, y, z, u};

Do[r1 = Plus @@
    Times @@@
     Transpose[vSymbols^Transpose[mPowers]], {10000}] // Timing

Do[r2 = Total[
    Times @@@
     Transpose[vSymbols^Transpose[mPowers]]], {10000}] // Timing

Do[r3 = Plus @@
    Times @@@ (Power[vSymbols, #] & /@ mPowers), {10000}] // Timing

Do[r4 = Plus @@
    MapThread[Times, vSymbols^Transpose[mPowers]], {10000}] // Timing

If you can prebuild a function before hand:

f = Evaluate[Times @@ (vSymbols^Array[Slot, Length[vSymbols]])] &;

Do[r5 = Plus @@ f @@ Transpose[mPowers], {10000}] // Timing

Do[r6 = Plus @@ (f @@@ mPowers), {10000}] // Timing

The winner depends on the length of mPower.
(Might wanna call ClearSystemCache[] for better time tests)

Additionally, if the mPower vector can be Transposed before hand, you
gain more speed.


  • Prev by Date: Re: Re: Two Notebooks Open at the Same Time
  • Next by Date: Re: How to map a list on function
  • Previous by thread: Re: How to map a list on function
  • Next by thread: Re: How to map a list on function