MathGroup Archive 2005

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

Search the Archive

Re: permutations

Francisco Gutierrez wrote:
> Dear Group:
>   If I do for example:
>   Permutations[{x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12}],
>   my computer runs out of memory.
>   This is not such a poor computer.  Actually, I would need to do permutations of lists of Length 20, perhaps 25.  I am aware these calculations are big (Length[x]!), but I wonder if there is some way around the problem. Compilating Permutations? But then how? Can somebody help me?
>   Francisco Gutiérrez


Your best bet is to work with smaller lists and manually create subsets of the 
final list containing all permutations.  Have you calculated how much memory you 
would actually need?  You're looking at 33GBs and that's considering list 
overhead + each element being just an unassigned variable.  If the list 
contained, say, integers (16 bytes), you're looking @ 120GBs.

In[56]:= lst = {x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12}; ByteCount@lst

Out[57]= 72

In[58]:= lst2 = {1,2,3,4,5,6,7,8,9,10,11,12}; ByteCount@lst2

Out[59]= 264

In[60]:= ByteCount@lst * Length@lst!/1024.0^2

Out[60]= 32890.4

In[61]:= ByteCount@lst2 * Length@lst2!/1024.0^2

Out[61]= 120598.

I'm sure there are multiple ways to create subsets of the full list of 
permutations, but here's one that's easy to write (I'm working with a smaller 
set so I don't run out of memory):

In[98]:= result = Flatten[
    Table[Insert[#, x6, i]&/@Permutations[{x1,x2,x3,x4,x5}], {i,1,6}], 1];

In[99]:= Length@result

Out[99]= 720

which is the same as:

In[100]:= Length@Permutations[{x1,x2,x3,x4,x5,x6}]

Out[100]= 720


Igor C. Antonio
Wolfram Research, Inc.

To email me personally, remove the dash.

  • Prev by Date: Re: Timing of looping operators
  • Next by Date: Re: Time needed for calculation
  • Previous by thread: Re: permutations
  • Next by thread: Re: permutations