**GAP Lesson 2
**

*Change to the directory where you store your GAP files, and then start up GAP. In the session which follows, pause for discussion at the spaces between command groupings.
*

Lists

gap> Primes;

gap> Primes[29];

gap> Position(Primes,29);

gap> 15 in Primes;

gap> Length(Primes);

gap> things:=["apple",true,,17];

gap> things[1];

gap> things[3];

gap> things[4]:=[1,2,3];

gap> things;

gap> newthings[1]:=72;

gap> newthings;

gap> newthings:=[];

gap> newthings;

gap> newthings[4]:=9;

gap> newthings;

gap> newthings:=things;

gap> newthings[1]:=23;

gap> newthings;

gap> things;

gap> things[1]:=14;

gap> things;

gap> newthings;

gap> newthings:=ShallowCopy(things);

gap> newthings[1]:=23;

gap> newthings;

gap> things;

gap> Add(things,16);

gap> things;

gap> Add(things,newthings);

gap> things;

gap> Append(things,newthings);

gap> things;

gap> Flat(things);

gap> things;

gap> r:=[3,1,4,1];

gap> 2*r;

gap> r+[,2,3];

gap> r+1;

gap> List(r,x->x^2);

gap> r;

gap> Sort(r);

gap> r;

gap> List([1..10],IsPrime);

gap> [1..10];

gap> List([1..10],x->x);

gap> g:=Group((1,2,3),(1,2));

gap> els:=Elements(g);

gap> List(els,x->Order(x));

gap> els[3]:=14;

gap> els:=ShallowCopy(els);

gap> els[3]:=14;

gap> els;

Programming

gap> g:=Group((1,2,3),(1,2));

gap> els:=Elements(g);

gap> for i in els do

> Order(i);

> od;

gap> orders:=[];

gap> for i in els do

> Add(orders,Order(i));

> od;

gap> orders;

gap> orders:=[];

[ ]

gap> for i in [1..Length(els)] do

> orders[i]:=Order(els[i]);

> od;

gap> orders;

[ 1, 2, 2, 3, 3, 2 ]

while ... do ... od;

and

repeat... until...;

Note the following:

gap> for i in [1..10] do

> Print(i);

> od;

gap> for i in [1..10] do

> Print(i,"\n");

> od;

Conway:=function(seq)

local i, r, newseq;

newseq:=[];

i:=1;

while i<=Length(seq) do

r:=0;

repeat r:=r+1;

until i+r>Length(seq) or not seq[i]=seq[i+r];

Append(newseq,[r,seq[i]]);

i:=i+r;

od;

return(newseq);

end;

gap> Read("Conway");

gap> Print(Conway);

gap> Conway([2]);

gap> Conway([1,2]);

gap> Conway(last);

gap> Conway(last);

gap> Conway(last);