Welcome!

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.

General

Evaluation

If GAP is unable to process an instruction, it may return fail or enter a break loop.
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;

Ordering

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;
What else can be compared? What about (1,2,3)>(1,2)(6,7,8,9);(1,2,3)<(1,2)?

Memory magagement

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 quit; .
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.

Lists

Generating lists

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 ]
(basic): Now it's your turn. Generate the following list. Can you do it in one line?
[ [ 2 ], [ 2, 4 ], [ 2, 4, 6 ], [ 2, 4, 6, 8 ], [ 2, 4, 6, 8, 10 ], [ 2, 4, 6, 8, 10, 12 ] ]

Sublist Assignment

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 ]
Problem (medium): Take a random list list:=List([1..50],i->Random(Integers)); and replace all odd elements with their inverses (or whatever you like).
Hint: You might find Filtered helpful. You can also do it without sublist assignment. Try Apply, for example.

Pointers and Lists

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 ] ]
how many commands did you need? Are the first and 4th entry still identical? Play around a little bit (try l[1][1]:=l[3] for example). Discuss the effects.

Mutability

An object is called "immutable" if it cannot be changed. Functions like AsList or AsSet return immutable objects. You can get an immutable copy of an object with Immutable.
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");

Loops

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;
Problem (medium): use this feature to generate a list of the primes in [1..1000].
Problem (basic): What happens, if you use RemoveSet instead of Unbind? And why?

Writing functions

(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;
What is the StructuralCopy for? What happens without it?
(medium): What do you expect in the next case? Find out what happens and write a function that does what you expect.
gap> makeempty:=function(list)
>  list:=[];
> end;
gap> list:=[1,2,3];
gap> makeempty(list);
Write a function calculating Fibonacci numbers recursively. You may use a 2-argument function taking a list of known values.

Records

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
Problem (medium): Find out more about records. Write a function addtorecord which behaves like this:
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 )

Group actions

Permuting lists

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"
Problem (basic): Can you find all even permutations of "hi there" which keep the blank in place?
Problem (medium): What about the permutations of "hi there" that preserve the two blocks?

Conjugacy classes

Let G:=GL(4,9).
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.