How to obtain a certain set of matrices in GAP?

81 Views Asked by At

I'd like to ask the following question:

Let $A$ be a finite set of complex numbers.

I would like to obtain in GAP the set $B$ of all $n\times n$ - matrices where in each row and column there is exactly one non-zero entry and this entry is from the set $A$.

Thus this set $B$ of $n\times n$-matrices should have cardinality $m^n \cdot n!$ where $m$ is the cardinality of $A$.

Is there an easy way to obtain this set $B$ in GAP?

Thank you very much.

(Example: When $A$ is equal to the set $\{1\}$, then we get for $B$ the set of $n\times n$ permutation matrices.)

1

There are 1 best solutions below

0
On BEST ANSWER

The easiest is probably to take diagonal matrices and to permute them in all possible ways:

gap> A:=[1,2,3,4];n:=3;;
[ 1, 2, 3, 4 ]
gap> diag:=List(Tuples(A,n),DiagonalMat);
[ [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ],   # and many more

Now we have the diagonal matrices, we permute the rows in each (matrices can be treated as lists of rows) with all permutations in $S_n$, and concatenate the lists:

gap> sym:=SymmetricGroup(n);
Sym( [ 1 .. 3 ] )
gap> B:=Concatenation(List(Elements(sym),p->List(diag,m->Permuted(m,p))));
[ [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ],
  [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 2 ] ], #....
gap> Length(B);  # indeed 4^3*6
384

For large values of $n$ or $|A|$ it is probably preferrable to not create $B$ as one list, but to have two for loops over diag and over sym to iterate over all elements in the huge list.