This set of problems is supposed to give you ideas of things worth playing with. Feel free to modify them and make up your own problems. They roughly correspond to the contents of the tutorial. But sometimes, you may find the GAP reference manual and the GAP tutorial useful.
The problems are labeled basic, medium or advanced. This refers to the amount of work that has to be put into a complete solution. This work may be mathematical, programming effort or it may consist of studying the reference manual.
If GAP is unable to process an instruction, it may return
Problem (basic): Find out what GAP does in the following cases (what
is safe and what isn't):
gap> true and fail; gap> 7<2 and 1/0=42; gap> 1/0=42 and 7<2; |
Most objects in GAP can be compared to other objects.
Problem (basic/medium): Find out what the following does and why it does it:
gap> Sqrt(4)<3; gap> Sqrt(5)<3; |
If you use too much memory, GAP enters a break loop. Generate a list by
adding one element after the other. How far do you get before you
enter the break loop?
Exit the break loop with
Do it again. How far do you get?
Quit GAP. Start it again. See what happens now.
Now generate the list at once. That is, without appending things.
How far do you get now? Also look at the timing.
Problem (advanced): try to make sense of what you saw.
You can define lists by applying functions to existing lists. And there is a short hand notation for functions. Like this:
gap> l:=[1..10]; [ 1 .. 10 ] gap> square:=function(x) > return x^2; > end; function( x ) ... end gap> List(l,square); [ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 ] gap> List(l,i->i^2); [ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 ] |
You can assign parts of lists separately:
gap> list:=[1..6];
[ 1 .. 6 ]
gap> list{[1,4]}:=[0,"haha"];
[ 0, "haha" ]
gap> list;
[ 0, 2, 3, "haha", 5, 6 ]
|
There are identical elements and equal elements. Find out what happens:
gap> i:=5;j:=5; 5 5 gap> IsIdenticalObj(i,j); true gap> listi:=[i];listj:=[j]; [ 5 ] [ 5 ] gap> IsIdenticalObj(listi,listj); false |
Problem (medium): Change a list with identical entries:
gap> l:=ListWithIdenticalEntries(6,[1,2,3]); [ [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ] ] gap> # Now do something... gap> # to make l look like this: gap> l; [ [ 1, 2, 3 ], [ 1, 5, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ] ] |
An object is called "immutable" if it cannot be changed. Functions like
Problem (basic/medium): Find out more about mutablility! You can start trying this:
gap> a:=[[1,2],[3,4]]; gap> b:="string"; gap> list:=AsList([a,b]);; gap> IsMutable(a);IsMutable(list); gap> Append(list[2],"2"); gap> Append(b,"2"); gap> MakeImmutable(list); gap> Append(b,"2"); gap> list2:=[a,b]; gap> MakeImmutable(list2); gap> Append(b,"2"); |
In GAP, you can change the index list in "for" loops from within the loop:
list:=[1..10]; gap> for i in list > do > Print(i," \c"); > Unbind(list[i+1]); > od; |
(basic): The arguments of a function may be changed by a function. Try this example:
makelarger:=function(list) local entry; if list=[] then Add(list,1); else entry:=StructuralCopy(list); Add(list,entry); fi; end; |
gap> makeempty:=function(list) > list:=[]; > end; gap> list:=[1,2,3]; gap> makeempty(list); |
Records are very useful structures in GAP. Here is an example:
gap> r:=rec(one:=1, two:=2, other:="much more"); rec( one := 1, two := 2, other := "much more" ) gap> r.other; "much more" gap> 5*r.two; 10 |
gap> r:=rec(); gap> addtorecord(r,"data",1234567); gap> r; rec( data := 1234567 ) gap> addtorecord(r,"important",42); gap> r; rec( data := 1234567, important := 42 ) |
Strings are lists as well. You can apply permutations to them:
gap> hi:="hi there"; "hi there" gap> IsList(hi); true gap> Permuted(hi,(1,2)); "ih there" |
Let
Problem (basic/medium):Find a system of representatives for
the conjugacy classes of elements of order 3. Try different methods.
Problem (basic): Represent G as a permutation group and try
the same again.