# Fast arithmetic on matrix elements

I have a square matrix $U$ of dimension $L\times L$, I am interested in the following quantity

$U_{1,j}U_{2,k}U_{3,l}U_{4,m}\cdots U_{L,q}$

summed over all permutations of the letter indices, e.g., $\{j,k,l,m,\cdots q\}$ is an element of Permutations[Range[L]]. What is a fast and efficient way of doing this? I am using the following function:

f[mat_, l_] := Total[Product[Part[mat, j, #[[j]]], {j, l}] & /@ Permutations[Range[l]]]


which is very inefficient. In fact it even runs out of memory for $L>11$

• Permanent[] is a built-in function, but it is not very fast. You might want to look at the solutions here. – J. M.'s technical difficulties Dec 18 '15 at 17:28
• @J.M. Thanks for your suggestion. I was wondering if there is a matrix operation corresponding to what I want to do. It is indeed the permanent. Thanks for pointing this out. – user64620 Dec 18 '15 at 17:37

To settle this:

The function being sought by the OP is actually now built-in into Mathematica as Permanent[]. Unfortunately, it is not terribly quick. You can, for instance, use a function like the one in this answer instead.

permanent[mat_?SquareMatrixQ] := Module[{l = Length[mat] - 1, b}, b = 2^l;
((2 IntegerDigits[2 b - ExperimentalGrayCode[l] - 1, 2] - 1).mat))/b]
`