This is a follow-up question from Sum of Multinomial Coefficients
I have thought about the meaning of the formula I mentioned and, with help, I implemented the following code:
supp[vec_] := Module[{support = {}, i},
Do[If[vec[[i]] != 0, AppendTo[support, i]], {i, 1, Length[vec]}];
support
];
calctrafo[n_, func_] := Module[{vecs, trafo = 0, i},
vecs = Tuples[Range[0, (n - 1)], n];
vecs = Select[vecs, Total[#] == (n - 1) &];
Do[trafo += (Multinomial @@ vecs[[i]])*func[supp[vecs[[i]]]], {i, 1, Length[vecs]}];
trafo
];
calctrafo[7, func]
The function supp gives me the support of the lists and func is a arbitrary function. This code works well for me, but I need the code to work for large n, n >= 100. The problem lies in the function Tuples, which crashes for n > 6. Is there a way to make this work for large n?
Tuples[Range[0,20],19]I loop through all possible Tuples. But there are approx. 19^20 Tuples and mathematica can't handle such a large number. Is there any other way? – rainer Mar 05 '13 at 08:06allmyTuples=lazyTuples[Range@20,19];which will not actually calculate them all yet, then if you call for instanceallmyTuples[[21312312841789283727]]it will return only that one tuple, without having calculated all the others. If you want to iteraet over the tuples, the length can be found by callingLength[allmyTuples]. – jVincent Mar 05 '13 at 09:12Do[func[lazyTuples[Range@20,19][[i]]],{i,1,19^20}]. Mathematica tells me it can't evaluate it. – rainer Mar 05 '13 at 10:22LazyTuplenotLazyTuples, and while such an evaluation will take quite a while to finish due to the37,589,973,457,545,958,193,355,601iterations it needs to go through, it should be possible as long as you are not using up to much memory in yourfunccalls. I would suggest you start out trying to calculate how long it should approximately take before just blindly running the code and waiting though. – jVincent Mar 05 '13 at 11:13Do::iterb: "Iterator {i,1,(n-1)^(n+1)} does not have appropriate bounds". I looking for all tuples Tuples`[Range[0,n],(n-1)] where the sum is equal to (n-1), calculate with these the Multinomial Coefficient and apply a function. Since I don't have any cs background I thought I seek help from you guys. – rainer Mar 05 '13 at 20:56nmeaning that the iterator doesn't have appropriate bounds since it doesn't know what(n-1)^(n+1)is. You should make sure you have setnto a value when you do this loop. – jVincent Mar 06 '13 at 09:24n = 20; Do[tmp = lazyTuple[Range[0, n], (n - 1)][[i]]; If[Total[tmp] == (n - 1), Print[(Multinomial @@ tmp)*func[supp[tmp]]]], {i, 1, (n + 1)^(n - 1)}](*20 Do::iterb...*)where supp is the function provided by Simon Woods – rainer Mar 06 '13 at 16:20n=16so it's properly just to large for it to work with. Try running a while loop instead, and again I would advice trying to estimate total run time by running a smaller number of iterations. – jVincent Mar 06 '13 at 16:44