Message Boards Message Boards

Speed up a calculation done by Mathematica involving a 5X5 matrix

Posted 4 years ago

Problem: find a 5X5 matrix of distinct integers to the fourth power with identical row and column sums.

I have the following code:

ClearAll[findMat2]
findMat2 = 
Module[{csums = ConstantArray[#, 5], 
mats = Select[DuplicateFreeQ[Join @@ #] &]@
Subsets[Select[DuplicateFreeQ]@
IntegerPartitions[#, {5}, 
Range[Ceiling[#^(1/4)]]^(4)], {5}]}, 
Join @@ ((Select[Total[#] == csums &]@
Tuples[{{#[[1]]}, Permutations[#[[2]]], 
Permutations[#[[3]]], 
Permutations[#[[4]]], 
Permutations[#[[5]]]}]) & /@ mats)] &;
solsB = ParallelTable[
findMat2[n] /. {} -> Nothing, {n, 0, 100000000}];
{Total[#[[1, 1]]]} & /@ solsB

And this code solves (I think) the problem I described at the beginning of my question. But it does so very very slowly, is there a way to compute this in a different way and speed up the calculation?

POSTED BY: Jan Eerland

Both here and on StackExchange you are posing interrelated questions that really are unrelated to Mathematica. What you are seeking is better algorithms. Sure, maybe your implementations could be made to work faster. But that will give perhaps an order of magnitude improvement at best.

All in all it might be best to first pose these questions on a math forum, to get some idea as to whether better approaches are known for these computational number theory problems.

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract