I have a huge list of values indexed by integer partitions. If I store them simply in a list, then, when I want to access the value corresponding to some particular integer partition, I have to find the index of the given partition in the list of all partitions before I can access the value. This is slow. Is there a way to optimize this?
In my particular example, I have values indexed by pairs of partitions of the same integers. The first 4 levels look like this:
chars = {
{{1}},
{{1, 1}, {-1, 1}}, {{1, 1, 1}, {-1, 0, 2}, {1, -1, 1}},
{{1, 1, 1, 1, 1}, {-1, 0, -1, 1, 3}, {0, -1, 2, 0, 2}, {1, 0, -1, -1, 3},
{-1, 1, 1, -1, 1}}
}
Then to access a particular value, I use this function:
maxn = 4;
YDs = Array[IntegerPartitions[#] &, maxn];
findChar[y1_, y2_] := Module[{l1, l2, n1, n2, i1, j1},
l1 = Length[y1];
l2 = Length[y2];
n1 = Sum[y1[[i]], {i, l1}];
n2 = Sum[y2[[i]], {i, l2}];
If[n1 != n2, Return["ERROR"];];
i1 = Position[YDs[[n1]], y1, Heads -> False][[1, 1]];
j1 = Position[YDs[[n2]], y2, Heads -> False][[1, 1]];
Return[chars[[n1, i1, j1]]];
];
This seems to be a pretty inefficient way, but I don't know how to do it more effectively in Mathematica.
maxn
in your code? Can you edit your question and fix this? $\endgroup$