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?
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) $\endgroup$In[]
values for your inputs. If it resets toIn[1]
you know the Kernel has quit and restarted. $\endgroup$