Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am currently trying to generate a list of permutations of length 2 of elements of a list of strings. For example:

Permutations[{"s1", "s2", "s3", "s4"}, {2}]
{{"s1", "s2"}, {"s1", "s3"}, {"s1", "s4"}, {"s2", "s1"}, {"s2", "s3"}, {"s2", "s4"}, {"s3", "s1"}, {"s3", "s2"}, {"s3", "s4"}, {"s4", "s1"}, {"s4", "s2"}, {"s4", "s3"}}

which is quite correct.

Now, my problem starts when attempting the same operation for a really big list of strings imported from a tsv file - we are talking of a bit more than 10000 strings. All sort of characters can be expected in strings.

This is the code that I am using:

t1 = Import["/home/bla/work/parsed_names.tsv"]
t2 = Table[t1[[i]][[1]], {i, 1, Length[t1]}]
Permutations[t2, {2}]

After evaluation of the last line, I get no output. If I evaluate it twice, all the symbols defined previously (t1, t2) become undefined, and Permutations finally give this output:

Permutations[t2, {2}]
Permutations::normal: Nonatomic expression expected at position 1 in Permutations[t2,{2}]. >>
Permutations[t2, {2}]

Which is the output for an undefined value of t2.

I tried to debug the problem: the import operations seems to go fine, each element of t2 is a proper string:

Length[t2]
10525

Tally[Table[Head[t2[[i]]], {i, 1, Length[t2]}]]
{{String, 10525}}

I tried running Trace to understand what is going on, but Mathematica still kept quiet during the first evaluation. The second evaluation again forces all the symbols to be cleared, and the output of Trace is unhelpful:

{Permutations[t2,{2}], {Message[Permutations::normal,1,Permutations[t2,{2}]],
 {MakeBoxes[Permutations::normal: Nonatomic expression expected at position 1 in Permutations[t2,{2}]. >>,StandardForm],
  RowBox[{StyleBox[RowBox[{Permutations,::,normal}],MessageName],: ,
   "Nonatomic expression expected at position \!\(1\) in \!\(Permutations[\(\(t2, \(\({2}\)\)\)\)]\). \!\(\*ButtonBox[\">>\", ButtonStyle->\"Link\", 
    ButtonFrame->None, ButtonData:>\"paclet:ref/message/General/normal\", ButtonNote -> \"Permutations::normal\"]\)"}]},Null},Permutations[t2,{2}]}

Is there something obviously wrong that I am doing? If not, how can I debug this problem further?

share|improve this question
    
Can you upload the tsv file compressed? –  M.R. Aug 29 '12 at 19:52
    
If you simply type, "t1" and hit shift + enter, what does mms show? –  David Carraher Aug 29 '12 at 19:58
    
@Mike: unfortunately I cannot –  paolo Aug 29 '12 at 20:00
    
Look at how it scales: ListLogLogPlot@Table[{i, Length[Permutations[Range[i], {2}]]}, {i,10^Range[1, 3., .2]}] gives this. It's probably related (but I don't see exactly what is happening) –  acl Aug 29 '12 at 20:01
2  
@paolo, keep an eye on the In[] values for your inputs. If it resets to In[1] you know the Kernel has quit and restarted. –  Simon Woods Aug 29 '12 at 20:13
show 9 more comments

1 Answer

up vote 6 down vote accepted

Perhaps I misunderstood, but look at how many elements there should have been in your list:

ListLogLogPlot@Table[{i, Length[Permutations[Range[i], {2}]]}, {i,10^Range[1, 3., .2]}] Mathematica graphics

It sounds like your kernel quits when you try to calculate the permutations.

share|improve this answer
1  
Unfortunately, I believe you may be correct. The fact that the symbols gets undefined at the second evaluation could point towards a kernel restart. –  paolo Aug 29 '12 at 20:12
    
@paolo If memory serves me right, then the number of permutations you are trying to produce is Binomial[10000,2] which is roughly 5*10^7, not counting ordering. It's not very suprising that Mathematica is not happy finding all of them. Just crashing the Kernel is kindof rude though... –  sebhofer Aug 30 '12 at 22:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.