GAP (Utils) - Chapter 7: Iterators

Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 13 Bib Ind
[Top of Book] [Contents] [Previous Chapter] [Next Chapter]

[MathJax off]

7 Iterators
7.1 Some iterators for groups and their isomorphisms
7.1-1 AllIsomorphismsIterator
7.1-2 AllSubgroupsIterator
7.2 Operations on iterators
7.2-1 CartesianIterator
7.2-2 UnorderedPairsIterator

### 7 Iterators

#### 7.1 Some iterators for groups and their isomorphisms

The motivation for adding these operations is partly to give a simple example of an iterator for a list that does not yet exist, and need not be created.

##### 7.1-1 AllIsomorphismsIterator

`‣ AllIsomorphismsIterator`( G, H ) | ( operation )

`‣ AllIsomorphismsNumber`( G, H ) | ( operation )

`‣ AllIsomorphisms`( G, H ) | ( operation )

The main GAP library contains functions producing complete lists of group homomorphisms such as `AllHomomorphisms`; `AllEndomorphisms` and `AllAutomorphisms`. Here we add the missing `AllIsomorphisms(G,H)` for a list of isomorphisms from \(G\) to \(H\). The method is simple -- find one isomorphism \(G \to H\) and compose this with all the automorphisms of \(G\). In all these cases it may not be desirable to construct a list of homomorphisms, but just implement an iterator, and that is what is done here. The operation `AllIsomorphismsNumber` returns the number of isomorphisms iterated over (this is, of course, just the order of the automorphisms group). The operation `AllIsomorphisms` produces the list or isomorphisms.

    gap> G := DihedralGroup(6);;
    gap> iter := AllIsomorphismsIterator( G, s3 );;
    gap> NextIterator( iter );
    [ f1, f2 ] -> [ (6,7), (5,6,7) ]
    gap> n := AllIsomorphismsNumber( G, s3 );
    6
    gap> AllIsomorphisms( G, s3 );
    [ [ f1, f2 ] -> [ (6,7), (5,6,7) ], [ f1, f2 ] -> [ (5,7), (5,6,7) ],
      [ f1, f2 ] -> [ (5,6), (5,7,6) ], [ f1, f2 ] -> [ (6,7), (5,7,6) ],
      [ f1, f2 ] -> [ (5,7), (5,7,6) ], [ f1, f2 ] -> [ (5,6), (5,6,7) ] ]
    gap> iter := AllIsomorphismsIterator( G, s3 );;
    gap> for h in iter do Print( ImageElm( h, G.1 ) = (6,7), ", " ); od;
    true, false, false, true, false, false,

##### 7.1-2 AllSubgroupsIterator

`‣ AllSubgroupsIterator`( G ) | ( operation )

The manual entry for the operation `AllSubgroups` states that it is only intended to be used on small examples in a classroom situation. Access to all subgroups was required by the XMod package, so this iterator was introduced here. It used the operations `LatticeSubgroups(G)` and `ConjugacyClassesSubgroups(lat)`, and then iterates over the entries in these classes.

    gap> c3c3 := Group( (1,2,3), (4,5,6) );;
    gap> iter := AllSubgroupsIterator( c3c3 );
    <iterator>
    gap> while not IsDoneIterator(iter) do Print(NextIterator(iter),"\n"); od;
    Group( () )
    Group( [ (4,5,6) ] )
    Group( [ (1,2,3) ] )
    Group( [ (1,2,3)(4,5,6) ] )
    Group( [ (1,3,2)(4,5,6) ] )
    Group( [ (4,5,6), (1,2,3) ] )

#### 7.2 Operations on iterators

This section considers ways of producing an iterator from one or more iterators. It may be that operations equivalent to these are available elsewhere in the library -- if so, the ones here can be removed in due course.

##### 7.2-1 CartesianIterator

`‣ CartesianIterator`( iter1, iter2 ) | ( operation )

This iterator returns all pairs \([x,y]\) where \(x\) is the output of a first iterator and \(y\) is the output of a second iterator.

    gap> it1 := Iterator( [ 1, 2, 3 ] );;
    gap> it2 := Iterator( [ 4, 5, 6 ] );;
    gap> iter := CartesianIterator( it1, it2 );;
    gap> while not IsDoneIterator(iter) do Print(NextIterator(iter),"\n"); od;
    [ 1, 4 ]
    [ 1, 5 ]
    [ 1, 6 ]
    [ 2, 4 ]
    [ 2, 5 ]
    [ 2, 6 ]
    [ 3, 4 ]
    [ 3, 5 ]
    [ 3, 6 ]

##### 7.2-2 UnorderedPairsIterator

`‣ UnorderedPairsIterator`( iter ) | ( operation )

This operation returns pairs \([x,y]\) where \(x,y\) are output from a given iterator `iter`. Unlike the output from `CartesianIterator(iter,iter)`, unordered pairs are returned. In the case \(L = [1,2,3,\ldots]\) the pairs are ordered as \([1,1],[1,2],[2,2],[1,3],[2,3],[3,3],\ldots\).

    gap> L := [6,7,8,9];;
    gap> iterL := IteratorList( L );;
    gap> pairsL := UnorderedPairsIterator( iterL );;
    gap> while not IsDoneIterator(pairsL) do Print(NextIterator(pairsL),"\n"); od;
    [ 6, 6 ]
    [ 6, 7 ]
    [ 7, 7 ]
    [ 6, 8 ]
    [ 7, 8 ]
    [ 8, 8 ]
    [ 6, 9 ]
    [ 7, 9 ]
    [ 8, 9 ]
    [ 9, 9 ]
    gap> iter4 := IteratorList( [ 4 ] );
    <iterator>
    gap> pairs4 := UnorderedPairsIterator(iter4);
    <iterator>
    gap> NextIterator( pairs4 );
    [ 4, 4 ]
    gap> IsDoneIterator( pairs4 );
    true

[Top of Book] [Contents] [Previous Chapter] [Next Chapter]
Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 13 Bib Ind

generated by GAPDoc2HTML