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^-2*Bf*Cf*Bf*Af*Cf^-1*Bf^-1*Cf^-1*Af*Cf^-1*Bf*Cf^-1,
Bf*Af^2*Cf^-1*Bf^-1*Af^-2*Bf^-1*Cf^-1*Af^-1*Bf*Af^-1*Bf^-1*Af^-1*Cf*Bf*Cf*Bf*Cf*Af^-1*Bf^-1*Cf^-1,
Cf*Bf*Af*Bf*Af*Bf^-1*Cf^-1*Af*Cf^-1*Bf*Af*Bf*Cf*Af^-1*Bf^-1*Cf^-1*Bf^-1*Af^-1*Cf*Af^-2*Bf^-1,
Cf*Af^-1*Cf*Bf*Af*Bf*Cf*Af^-1*Bf^-1*Cf^-1*Bf*Af*Cf*Bf*Af^2*Cf^-1*Bf*Cf^-1*Af*Cf^-1*Bf^-1*Af^-1
];

GammaBarFP:=FreeGp/RelnList;;
AFP:=GammaBarFP.1;
BFP:=GammaBarFP.2;
CFP:=GammaBarFP.3;

index3aFP:=Group(AFP, CFP, BFP*AFP*BFP^-1);
index3bFP:=Group(AFP, CFP, BFP*AFP*BFP, BFP^-1*CFP*BFP);

index3aFCA:=FactorCosetAction(GammaBarFP,index3aFP);
index3bFCA:=FactorCosetAction(GammaBarFP,index3bFP);

index3aFCA:=FactorCosetAction(GammaBarFP,index3aFP);
index3bFCA:=FactorCosetAction(GammaBarFP,index3bFP);

# Check the indexes of the subgroups

Index(GammaBarFP,index3aFP) = 3;
Index(GammaBarFP,index3bFP) = 3;

# Check normality

IsNormal(GammaBarFP,index3aFP);
not IsNormal(GammaBarFP,index3bFP);

# Free group versions of these subgroups
FPtoFGSubgp:=g->Group(List(GeneratorsOfGroup(g),UnderlyingElement));

index3aFG:=FPtoFGSubgp(index3aFP);
index3bFG:=FPtoFGSubgp(index3bFP);

#####
#
# Generators of $(a=2,p=3,\emptyset)$
#
#####

#From: "Donald Cartwright" <donald.cartwright@gmail.com>
#To: steger@uniss.it
#Subject: (a=2,p=3) results [Re: (a=1,p=5) ... hmmm]
#Date: Mon, 24 Dec 2007 16:41:23 +1100

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-3/10,
3/10*Zm^2+1/10*(Sqrt(-2)-1)*Zm+1/10*(-3*Sqrt(-2)+6),
1/10*(2*Sqrt(-2)+1)*Zm^2+1/10*(3*Sqrt(-2)-3)*Zm+3/10*Sqrt(-2)]];

CDM:=One(mm)*[
[1/2*Sqrt(-2)*Zm^2+1/2*(Sqrt(-2)-2)*Zm,
0,
0],
[0,
1/2*(-Sqrt(-2)+1)*Zm^2+1/2*(-2*Sqrt(-2)+1)*Zm+1/2*(-3*Sqrt(-2)+2),
0],
[0,
0,
-1/2*Zm^2+1/2*(Sqrt(-2)+1)*Zm-1/2*Sqrt(-2)]];

ADMVec:=DMtoDMVec(ADM);;
BDMVec:=DMtoDMVec(BDM);;
CDMVec:=DMtoDMVec(CDM);;

ADMVec in DMVec;
BDMVec in DMVec;
CDMVec in DMVec;

IsOne(iotaDM(ADM)*ADM);
IsOne(iotaDM(BDM)*BDM);
IsOne(iotaDM(CDM)*CDM);

# Check that the relations hold (projectively) for all our matrix
# generators

GammaBarDM:=Group(ADM,BDM,CDM);;
DMHom:=GroupHomomorphismByImages(FreeGp,GammaBarDM,
  [Af,Bf,Cf],[ADM,BDM,CDM]);;
ForAll(RelnList,x->IsPOne(x^DMHom));
	
#####
#
# Construct matrices for the group generators acting on~$\D$ by
# conjugation
#
######

DMtoPDM:=mtx->TransposedMat(
  List(basisDM,
    bmtx->Coefficients(basisDMVec,DMtoDMVec(mtx*bmtx*mtx^-1))
));

APDM:=DMtoPDM(ADM);;
BPDM:=DMtoPDM(BDM);;
CPDM:=DMtoPDM(CDM);;

IsZero(LieBracket(iotaPDM,APDM));
IsZero(LieBracket(iotaPDM,BPDM));
IsZero(LieBracket(iotaPDM,CPDM));

GammaBarPDM:=Group(APDM,BPDM,CPDM);;
FGtoPDM:=GroupHomomorphismByImages(FreeGp,GammaBarPDM,
  [Af,Bf,Cf],[APDM,BPDM,CPDM]);;
ForAll(RelnList,x->IsOne(x^FGtoPDM));

######
#
# Find the matrices for the group generators acting by conjugation on
# the self-adjoint, traceless part of~$\D$.
#
#####

PDMtoPSA:=mtx->TransposedMat(
  List(DMVecSelfAdjBasis,SAVec->
    Coefficients(DMVecSelfAdjBasis,mtx*SAVec)
));

APSA0:=PDMtoPSA(APDM);;
BPSA0:=PDMtoPSA(BPDM);;
CPSA0:=PDMtoPSA(CPDM);;

#####
#
# Adjust the basis of the self-adjoint part of~$\D$ so that
# the group generators correspond to integral matrices.
#
#####

GammaBarPSA0:=Group(APSA0,BPSA0,CPSA0);;

ILatPSA0:=InvariantLattice(GammaBarPSA0)^-1;
APSA:=APSA0^ILatPSA0;
BPSA:=BPSA0^ILatPSA0;
CPSA:=CPSA0^ILatPSA0;

GammaBarPSA:=Group(APSA,BPSA,CPSA);;
FGtoPSA:=GroupHomomorphismByImages(FreeGp,GammaBarPSA,
  [Af,Bf,Cf],[APSA,BPSA,CPSA]);;
ForAll(RelnList,x->IsOne(x^FGtoPSA));

######
#
# Do calculations $\mod 2$
#
######

toMod2:=x->x*One(GF(2));
toMod2M:=mtx->fOnM(toMod2,mtx);

APSAMod2:=toMod2M(APSA);;
BPSAMod2:=toMod2M(BPSA);;
CPSAMod2:=toMod2M(CPSA);;

GammaBarPSAMod2:=Group(APSAMod2,BPSAMod2,CPSAMod2);;
FGtoPSAMod2:=GroupHomomorphismByImages(FreeGp,GammaBarPSAMod2,
  [Af,Bf,Cf],[APSAMod2,BPSAMod2,CPSAMod2]);;
ForAll(RelnList,x->IsOne(x^FGtoPSAMod2));
	
Size(GammaBarPSAMod2) = 192;
ListMod2H1:=Filtered(NormalSubgroups(GammaBarPSAMod2),h->Size(h)=32);
Size(ListMod2H1) = 1;
Mod2H1:=ListMod2H1[1];
Mod2H1LAL:=LinearActionLayer(
  GammaBarPSAMod2,GeneratorsOfGroup(GammaBarPSAMod2),Pcgs(Mod2H1));
Mod2Q1:=Group(Mod2H1LAL);
Size(Mod2Q1)*Size(Mod2H1) = Size(GammaBarPSAMod2);
StructureDescription(Mod2H1) = "C2 x C2 x C2 x C2 x C2";
IdSmallGroup(Mod2Q1) = IdSmallGroup(PGL(2,2));
IdSmallGroup(Mod2Q1) = IdSmallGroup(SymmetricGroup(3));

MTXMod2H1:=GModuleByMats(Mod2H1LAL,GF(2));
List(MTX.BasesCompositionSeries(MTXMod2H1),Size) = [0,1,3,5];
List(MTX.BasesMinimalSubmodules(MTXMod2H1),Size) = [1,2,2,2];

index3aPSAMod2:=Image(FGtoPSAMod2,index3aFG);
index3bPSAMod2:=Image(FGtoPSAMod2,index3bFG);

index3aPSAMod2 = GammaBarPSAMod2;
Index(GammaBarPSAMod2,index3bPSAMod2) = 3;

######
#
# Do calculations $\mod 4$
#
######

toMod4M:=mtx->fOnM(x->ZmodnZObj(x,4),mtx);

APSAMod4:=toMod4M(APSA);;
BPSAMod4:=toMod4M(BPSA);;
CPSAMod4:=toMod4M(CPSA);;

GammaBarPSAMod4:=Group(APSAMod4,BPSAMod4,CPSAMod4);;
FGtoPSAMod4:=GroupHomomorphismByImages(FreeGp,GammaBarPSAMod4,
  [Af,Bf,Cf],[APSAMod4,BPSAMod4,CPSAMod4]);;
ForAll(RelnList,x->IsOne(x^FGtoPSAMod4));
	
Size(GammaBarPSAMod4) = 192*2^8;

index3aPSAMod4:=Image(FGtoPSAMod4,index3aFG);
index3bPSAMod4:=Image(FGtoPSAMod4,index3bFG);

index3aPSAMod4 = GammaBarPSAMod4;
Index(GammaBarPSAMod4,index3bPSAMod4) = 3;

######
#
# Do calculations $\mod 3$
#
######

toMod3:=x->x*One(GF(3));
toMod3M:=mtx->fOnM(toMod3,mtx);

APSAMod3:=toMod3M(APSA);;
BPSAMod3:=toMod3M(BPSA);;
CPSAMod3:=toMod3M(CPSA);;

GammaBarPSAMod3:=Group(APSAMod3,BPSAMod3,CPSAMod3);;
FGtoPSAMod3:=GroupHomomorphismByImages(FreeGp,GammaBarPSAMod3,
  [Af,Bf,Cf],[APSAMod3,BPSAMod3,CPSAMod3]);;
ForAll(RelnList,x->IsOne(x^FGtoPSAMod3));
	
Size(GammaBarPSAMod3) = 3*13*3^6;
ChSGammaBarPSAMod3:=ChiefSeries(GammaBarPSAMod3);
Length(ChSGammaBarPSAMod3) = 5;
List(ChSGammaBarPSAMod3,Size)=[3*13*3^6,13*3^6,3^6,3^3,1];
Mod3H1:=ChSGammaBarPSAMod3[3];
Mod3H0:=ChSGammaBarPSAMod3[4];
Mod3H0 = Center(Mod3H1);
StructureDescription(Mod3H0) = "C3 x C3 x C3";
StructureDescription(Mod3H1/Mod3H0) = "C3 x C3 x C3";
#
# whence follows
# StructureDescription(Mod3H1) = "(C3 x C3 x C3) . (C3 x C3 x C3)"
#
Mod3Q1Hom:=NaturalHomomorphismByNormalSubgroup(GammaBarPSAMod3,Mod3H1);;
Mod3Q1:=Image(Mod3Q1Hom);
StructureDescription(Mod3Q1) = "C13 : C3";

index3aPSAMod3:=Image(FGtoPSAMod3,index3aFG);
index3bPSAMod3:=Image(FGtoPSAMod3,index3bFG);

Index(GammaBarPSAMod3,index3aPSAMod3) = 3;
index3bPSAMod3 = GammaBarPSAMod3;

FGtoMod3Q1:=CompositionMapping(Mod3Q1Hom,FGtoPSAMod3);
ForAll(RelnList,x->IsOne(x^FGtoMod3Q1));

index3aMod3Q1:=Image(FGtoMod3Q1,index3aFG);
index3bMod3Q1:=Image(FGtoMod3Q1,index3bFG);

Index(Mod3Q1,index3aMod3Q1) = 3;
index3bMod3Q1 = Mod3Q1;

######
#
# Do calculations $\mod 5$
#
######

toMod5:=x->x*One(GF(5));
toMod5M:=mtx->fOnM(toMod5,mtx);

APSAMod5:=toMod5M(APSA);;
BPSAMod5:=toMod5M(BPSA);;
CPSAMod5:=toMod5M(CPSA);;

GammaBarPSAMod5:=Group(APSAMod5,BPSAMod5,CPSAMod5);;
FGtoPSAMod5:=GroupHomomorphismByImages(FreeGp,GammaBarPSAMod5,
  [Af,Bf,Cf],[APSAMod5,BPSAMod5,CPSAMod5]);;
ForAll(RelnList,x->IsOne(x^FGtoPSAMod5));

ChSGammaBarPSAMod5:=ChiefSeries(GammaBarPSAMod5);
Length(ChSGammaBarPSAMod5) = 3;
Mod5H1:=ChSGammaBarPSAMod5[2];
IsSimple(Mod5H1);
#IsomorphismGroups(PSU(3,5),Mod5H1);
#IsomorphismGroups(PGU(3,5),GammaBarPSAMod5);
index3aPSAMod5:=Image(FGtoPSAMod5,index3aFG);
index3bPSAMod5:=Image(FGtoPSAMod5,index3bFG);

Index(GammaBarPSAMod5,index3aPSAMod5) = 3;
index3bPSAMod5 = GammaBarPSAMod5;

######
#
# Do calculations $\mod 7$
#
######

toMod7:=x->x*One(GF(7));
toMod7M:=mtx->fOnM(toMod7,mtx);

APSAMod7:=toMod7M(APSA);;
BPSAMod7:=toMod7M(BPSA);;
CPSAMod7:=toMod7M(CPSA);;

GammaBarPSAMod7:=Group(APSAMod7,BPSAMod7,CPSAMod7);;
FGtoPSAMod7:=GroupHomomorphismByImages(FreeGp,GammaBarPSAMod7,
  [Af,Bf,Cf],[APSAMod7,BPSAMod7,CPSAMod7]);;
ForAll(RelnList,x->IsOne(x^FGtoPSAMod7));
	
#IsomorphismGroups(PGU(3,7),GammaBarPSAMod7);
#Size(GammaBarPSAMod7) = 5663616;

index3aPSAMod7:=Image(FGtoPSAMod7,index3aFG);
index3bPSAMod7:=Image(FGtoPSAMod7,index3bFG);

index3aPSAMod7 = GammaBarPSAMod7;
index3bPSAMod7 = GammaBarPSAMod7;

######
#
# Do calculations $\mod 11$
#
######

# NOT CHECKED YET!

##### toMod11:=x->x*One(GF(11));
##### toMod11M:=mtx->fOnM(toMod11,mtx);
##### 
##### APSAMod11:=toMod11M(APSA);;
##### BPSAMod11:=toMod11M(BPSA);;
##### CPSAMod11:=toMod11M(CPSA);;
##### 
##### GammaBarPSAMod11:=Group(APSAMod11,BPSAMod11,CPSAMod11);;
##### FGtoPSAMod11:=GroupHomomorphismByImages(FreeGp,GammaBarPSAMod11,
#####   [Af,Bf,Cf],[APSAMod11,BPSAMod11,CPSAMod11]);;
##### ForAll(RelnList,x->IsOne(x^FGtoPSAMod11));
##### 	
##### #IsSimple(GammaBarPSAMod11);
##### #Size(GammaBarPSAMod11) = 212427600;
##### #StructureDescription(GammaBarPSAMod11) = "PSL(3,11)";
##### 
##### index3aPSAMod11:=Image(FGtoPSAMod11,index3aFG);
##### index3bPSAMod11:=Image(FGtoPSAMod11,index3bFG);
##### 
##### index3aPSAMod11 = GammaBarPSAMod11;
##### index3bPSAMod11 = GammaBarPSAMod11;

#####
#
# Consider abelianizations
#
#####

# (a=2,p=3,\emptyset)
AbelianInvariants(GammaBarFP) = [2,2,3];
AbelianInvariants(GammaBarPSAMod2) = [2,2];
AbelianInvariants(GammaBarPSAMod4) = [2,2];
AbelianInvariants(GammaBarPSAMod3) = [3];
AbelianInvariants(GammaBarPSAMod5) = [3];

# (a=2,p=3,\emptyset,D_3)
AbelianInvariants(index3aFP) = [2,2,13];
AbelianInvariants(index3aPSAMod2) = [2,2];
AbelianInvariants(index3aPSAMod4) = [2,2];
AbelianInvariants(index3aPSAMod3) = [13];
AbelianInvariants(index3aPSAMod5) = [];

# (a=2,p=3,\{2I\})
#
# When we look at this group as a subgroup of $(a=2,p=3,\emptyset)$,
# we see that its abelianization arises entirely from congruence
# conditions.  Looked at as a subgroup of $(a=2,p=3,\{2\})$ it seems
# as though there may be a problem.  The difference is possible
# because we are considering the action by conjugation on two
# different $\ZZ$-lattices of the trace-free self-adjoing elements
# of~$\D$.  Both lattices are fixed by this particular group.
#
# When we work with the action on the lattice here mod~4 instead of
# mod~2, the extra factor of C2 in the abelianization shows up.
#
AbelianInvariants(index3bFP) = [2,2,2,2,3];
AbelianInvariants(index3bPSAMod2) = [2,2,2];
AbelianInvariants(index3bPSAMod4) = [2,2,2,2];
AbelianInvariants(index3bPSAMod3) = [3];
AbelianInvariants(index3bPSAMod5) = [3];
