# general procedures to manufacture string C-groups; or chiral rotation groups
# First, to cover special relations, a function which
# takes ge = GeneratorsOfGroup(f) (say M of them)
# and a list ls of indices or their negatives (from -m...-1 or 1...m)
# and outputs the corresponding word in the generators
wd:=function(ge,ls)
local x,j,y;
if  0<Size(Filtered(ls,y->(Size(ge)<AbsInt(y)))) then 
	Print("bad input","\n"); return; 
	else
x:=ge[1]^0;
for j in [1..Size(ls)] do
	x:=x*(ge[SignInt(ls[j])*ls[j]])^(SignInt(ls[j]));od;
		fi;
return x;
end; # end of function wd
#
# the first function returns the string C-group with
# n generators and branch labels p_1,p_2 ... p_(n-1)
#
stref:=function(lab,ex) # lab = [p_1,p_2 ... p_(n-1)]
  			# ex = [list of extra relations]
  			# assumed to be in format 
  			# [[1,2,3,4,2,3],[5,-6,5,-6], etc], all 
  			# indices <= n in absolute value
local n,fr,g,rels,j,k;
n:=1+Size(lab);
fr:=FreeGroup(n);g:=GeneratorsOfGroup(fr);
# That is the group; now assemble relations.
rels:=[];
for j in [1..n] do 
	Append(rels,[g[j]^2]);od;
for j in [1..(n-1)] do 
	Append(rels,[(g[j]*g[j+1])^lab[j]]);od;
for j in [1..(n-2)] do
	for k in [(j+2)..n] do
	Append(rels,[(g[j]*g[k])^2]);
		od;
	od;
for j in [1..Size(ex)] do
	Append(rels,[wd(g,ex[j])]);
	od;
return fr/rels;
end; # end of function stref
#
# Now a function to return the string rotation subgroup.
#
strot:=function(lab,ex) # lab = [p_1,p_2 ... p_(n-1)]; 
			# ex=[list of extra relations]
			# assumed to be in format 
  			# [[1,2,3,4,2,3],[5,6,5,6], etc], all 
  			# indices <= n-1  in absolute value
local n,fr,g,rels,j,k;
n:=1+Size(lab);
fr:=FreeGroup(n-1);g:=GeneratorsOfGroup(fr);
# That is the group; now assemble relations.
rels:=[];
for j in [1..(n-1)] do 
	Append(rels,[(g[j])^lab[j]]);od;
#
for j in [1..(n-2)] do
	for k in [(j+1)..(n-1)] do
	Append(rels,[ (Product(g{[j..k]}))^2]);
		od;
	od;
for j in [1..Size(ex)] do
	Append(rels,[wd(g,ex[j])]);
	od;	
#
return fr/rels;
end; # end of function strot
##
# Groups of type {3,6,3} - rotations only 
try363:=function(parms)
# parms =  [b,c,b1,c1] ; parameters for toroidal facet {3,6}_(b,c}
#          				and vertex figure {6,3}_(b1,c1)
# 				assume these to be >=0. 
local b,c,b1,c1,tr,tr2,ex,j;
#
# 
# lets set the parameters c, b, c1, b1, for facet and vertex figure
#
b:=parms[1];c:=parms[2];b1:=parms[3];c1:=parms[4];
#
# now the translation relations:
ex:=[];
tr:=[]; for j in [1..b] do tr:=Concatenation(tr,[1,-2,-1,2]); od;
	for j in [1..c] do tr:=Concatenation(tr,[2,1,-2,-1]); od;
Append(ex,[tr]);
tr:=[];	for j in [1..b1] do  tr:=Concatenation(tr,[-3,2,3,-2]); od;
	for j in [1..c1] do  tr:=Concatenation(tr,[-2,-3,2,3]); od;
Append(ex,[tr]); 
#
#
tr:=strot([3,6,3],ex);
Print(" Here are the toroidal parameters:","\n");
#
Print("b = ", b, ";  c = ", c,";  b1 = ",b1,";  c1 = ",c1, "\n","\n");
#
Print(" Here are the relations:","\n"); 
Print(RelatorsOfFpGroup(tr),"\n");
#
return tr;
end; # end function try363
#
#
# Groups of type {4,4,4} - rotations only 
try444:=function(parms)
# parms =  [b,c,b1,c1] ; parameters for toroidal facet {4,4}_(b,c}
#          				and vertex figure {4,4}_(b1,c1)
# 				assume these to be >=0. 
local b,c,b1,c1,tr,tr2,ex,j;
#
# 
# lets set the parameters c, b, c1, b1, for facet and vertex figure
#
b:=parms[1];c:=parms[2];b1:=parms[3];c1:=parms[4];
#
# now the translation relations:
ex:=[];
tr:=[]; for j in [1..b] do tr:=Concatenation(tr,[-1,2]); od;
	for j in [1..c] do tr:=Concatenation(tr,[1,-2]); od;
Append(ex,[tr]);
tr:=[];	for j in [1..b1] do  tr:=Concatenation(tr,[-2,3]); od;
	for j in [1..c1] do  tr:=Concatenation(tr,[2,-3]); od;
Append(ex,[tr]); 
#
#
tr:=strot([4,4,4],ex);
Print(" Here are the toroidal parameters:","\n");
#
Print("b = ", b, ";  c = ", c,";  b1 = ",b1,";  c1 = ",c1, "\n","\n");
#
Print(" Here are the relations:","\n"); 
Print(RelatorsOfFpGroup(tr),"\n");
#
return tr;
end; # end function try444
#
#
#
# Groups of type {6,3,3} - rotations only 
try633:=function(parms)
# parms =  [b,c] ; parameters for toroidal facet {6,3}_(b,c}
#          				#
# 				assume these to be >=0. 
local b,c,tr,ex,j;
#
# 
# lets set the parameters c, b  for facet 
#
b:=parms[1];c:=parms[2]; 
#
# now the translation relations:
ex:=[];
tr:=[]; for j in [1..b] do tr:=Concatenation(tr,[-2,1,2,-1]); od;
	for j in [1..c] do tr:=Concatenation(tr,[-1,-2,1,2]); od;
Append(ex,[tr]);
#
#
tr:=strot([6,3,3],ex);
Print(" Here are the toroidal parameters:","\n");
#
Print("b = ", b, ";  c = ", c,"\n","\n");
#
Print(" Here are the relations:","\n"); 
Print(RelatorsOfFpGroup(tr),"\n");
#
return tr;
end; # end function try633
#
##
# Groups of type {6,3,6} - rotations only 
try636:=function(parms)
# parms =  [b,c,b1,c1] ; parameters for toroidal facet {3,6}_(b,c}
#          				and vertex figure {6,3}_(b1,c1)
# 				assume these to be >=0. 
local b,c,b1,c1,tr,tr2,ex,j;
#
# 
# lets set the parameters c, b, c1, b1, for facet and vertex figure
#
b:=parms[1];c:=parms[2];b1:=parms[3];c1:=parms[4];
#
# now the translation relations:
ex:=[];
tr:=[]; for j in [1..b] do tr:=Concatenation(tr,[-2,1,2,-1]); od;
	for j in [1..c] do tr:=Concatenation(tr,[-1,-2,1,2]); od;
Append(ex,[tr]);
tr:=[];	for j in [1..b1] do  tr:=Concatenation(tr,[2,-3,-2,3]); od;
	for j in [1..c1] do  tr:=Concatenation(tr,[3,2,-3,-2]); od;
Append(ex,[tr]); 
#
#
tr:=strot([6,3,6],ex);
Print(" Here are the toroidal parameters:","\n");
#
Print("b = ", b, ";  c = ", c,";  b1 = ",b1,";  c1 = ",c1, "\n","\n");
#
Print(" Here are the relations:","\n"); 
Print(RelatorsOfFpGroup(tr),"\n");
#
return tr;
end; # end function try636
#
#
#Print("\n","Now let's try to compute size:","\n");
#Print(Size(gp));
#Print("\n","If that worked, try to find a faithful perm. rep:","\n");  
#G:=Image(IsomorphismPermGroup(gp));
