[GAP Forum] how to iterate over all matrices over a finite field?

Benoit Jacob benoitjacob at google.com
Mon Dec 14 14:43:45 GMT 2015


On Mon, Dec 14, 2015 at 9:33 AM, Alexander Konovalov <alexk at mcs.st-and.ac.uk
> wrote:

>
> > On 14 Dec 2015, at 14:00, Sven Reichard <sven.reichard at tu-dresden.de>
> wrote:
> >
> > Hello Benoit,
> >
> > matrices are tuples of tuples, so we can use the combinatorial
> > functions. As we do not want to store the complete list of matrices we
> > use an iterator.
> >
> > gap> n := 3;; F := GF(3);;
> > gap> rows := Tuples(F, n);
> > gap> matrices := IteratorOfTuples(rows, n);
> > gap> for matrix in matrices do
> >>     process(matrix);
> >>   od;
> >
> > Hope this helps.
> >
> > If the set of rows is too large to be stored, the set of matrices is
> > likely too large to be processed. However maybe there is also a way of
> > avoiding storage of the rows.
>
> Yes, one way to avoid storage of rows is to iterate over the full matrix
> algebra:
>
> n := 3;; F := GF(3);;
> M:=FullMatrixAlgebra(F,n);
> for matrix in M do
>   process(matrix);
> od;
>

Many thanks for this.

Here's why I didn't find this myself when I searched for it, in case it
might help future documentation work:
 - I searched "matrix set" and "matrix ring", not "matrix algebra".
 - I read the pages on matrices
<http://www.gap-system.org/Manuals/doc/ref/chap24.html> and on matrix rings
<http://www.math.uiuc.edu/Software/GAP-Manual/Matrix_Rings.html>, not on
algebras <http://www.gap-system.org/Manuals/doc/ref/chap62.html>.
 - It is no clear to me which GAP objects can be readily iterated over by a
"for x in object" construct. In other words, even reading the page on
algebras <http://www.gap-system.org/Manuals/doc/ref/chap62.html>, it would
have been not be obvious to me that I could write
M:=FullMatrixAlgebra(F,n); for matrix in M do... . I did read about the
concept of a "collection" but it wasn't obvious to me whether the return
value of FullMatrixAlgebra is a collection, and if collections can over be
iterated over like this, or if one needs to explicitly construct an
iterator first.

Thanks again!
Benoit



>
> Hope this helps
> Alexander
>
>
>


More information about the Forum mailing list