p:=2;   
q:=2; // Potenz von p   
N := 3;   

MRbig:=MatrixRing(GF(q),N);   

//splitting field
CyN<zeN> := CyclotomicField(q*(q^N-1));  
wmsi := &+[LegendreSymbol(i,7) * (-zeN)^i : i in [1..6]]; 
K<th> := sub<CyN | (1 + wmsi)/2 >; 


G3:=GL(N,q); 
G_List:=[g: g in G3];
CT:=CharacterTable(G3);     
G_FP,phi := FPGroup(G3);   
G_perm,psi2 := PermutationGroup(G_FP);   

//Group relations
FactorNumberLists := [<ElementToSequence(x@@psi2),x> : x in G_perm];  
FactorNumberListsShort := [];   
OG1 := Order(G3.1);   
OG3 := Order(G3.2);   
for k in [1..#G3] do      
 fnl := FactorNumberLists[k][1];   
 i := 1;   
 while i le #fnl do   
  simplification := false;   
  if i+OG1-1 lt #fnl and SequenceToSet(fnl[i..i+OG1-1]) in [{-1},{1}] then   
   simplification := true;   
   for k in [i..i+OG1-1] do   
    Remove(~fnl,i); // sic, dann werden Eintraege in [i..i+OG1-1] der urspruenglichen Liste entfernt   
   end for;   
  end if;   
  if i+OG3-1 lt #fnl and SequenceToSet(fnl[i..i+OG3-1]) in [{-2},{2}] then   
   for k in [i..i+OG3-1] do   
    Remove(~fnl,i); // sic, dann werden Eintraege in [i..i+OG3-1] der urspruenglichen Liste entfernt   
   end for;   
  end if;   
  if not simplification then   
   i +:= 1;   
  end if;   
  if simplification and i ge 2 then   
   i +:= -1;   
  end if;   
 end while;   
 FactorNumberListsShort cat:= [<fnl,FactorNumberLists[k][2]>];    
end for;   

charactercheck:=function(B,i,CT)
if not i in [1,31,32,6,7,8] then 
r:="i is not in {1,31,32,6,7,8}";
else
case i:
  when 1:
     k:=1;
  when 31:
     k:=2;
  when 32:
     k:=3;
  when 6:
     k:=4;
  when 7:
     k:=5;
  when 8:
     k:=6;
end case;
r:=[r : r in [1..#CT]| &and[CT[r](g) eq CyN!Trace(B[Index(G_List,g)][k]):g in G_List]];
end if;
return r; 
end function;
//load generators for irreducible representations
load "rep_matrices_Z";

sig:= hom<K ->K| 1-th>;
tens_Matrix:=function(A,f)
nor := NumberOfRows(A);
noc := NumberOfColumns(A);
B:=RMatrixSpace(Codomain(f),nor,noc)!0;
for i in [1..nor] do
  for j in [1..noc] do
     B[i,j]:=A[i,j]@f;
  end for;
end for;
return B;
end function;

Mat1_Mred2:=tens_Matrix(Mat1_Mred,sig);
Mat2_Mred2:=tens_Matrix(Mat2_Mred,sig);

rep_Mred:=function(FactorNumberListsShort,Mat1,Mat2) 
Mat1inv:=Mat1^-1; 
Mat2inv:=Mat2^-1; 
mat := map<{-2,-1,1,2} -> MatrixRing(K,NumberOfRows(Mat1)) | [<-2,Mat2inv>, <-1,Mat1inv>, <1,Mat1>, <2,Mat2>]>;   
matrices := [<x[2]@@psi2@phi,&*([MatrixRing(K,NumberOfRows(Mat1))!1] cat [mat(i) : i in x[1]])> : x in FactorNumberListsShort]; 
return map<G3->MatrixRing(K,NumberOfRows(Mat1)) |matrices>; 
end function; 

print("Calculation of list B_th of  Wedderburnimages for each group element (takes about 1min)");
B:=[<1,rep_Mred(FactorNumberListsShort,Mat1_Mred,Mat2_Mred)(g), rep_Mred(FactorNumberListsShort,Mat1_4,Mat2_4)(g), rep_Mred(FactorNumberListsShort,Mat1_5,Mat2_5)(g), rep_Mred(FactorNumberListsShort,Mat1_6,Mat2_6)(g)>: g in G3]; 


print("Loading lists of conjugating elements for each irreducible representation");
load "conj_elements_Z";
conj_C := function(P,P_inv,R,B_int,k) // Repr = representing matrix, Ties = matrix with ties in columns,
 B:=B_int;
 r:=NumberOfColumns(P);
 for i in [1..#G3] do 
  B[i][k]:= RMatrixSpace(K,r,r)!(RMatrixSpace(K,r,r)!P_inv*RMatrixSpace(K,r,r)!B[i][k]*RMatrixSpace(K,r,r)!RMatrixSpace(K,r,r)!P); 
 end for; 
 return B; 
end function; 

C_5:=&*Conj_5;
C_4:=&*Conj_4;
C_3:=&*Conj_3;
C_2:=&*Conj_2;
C_5_inv:=C_5^-1;
C_4_inv:=C_4^-1;
C_3_inv:=C_3^-1;
C_2_inv:=C_2^-1;
B_conj:=conj_C(C_2,C_2_inv,Integers(),conj_C(C_3,C_3_inv,Integers(),conj_C(C_4,C_4_inv,Integers(),conj_C(C_5,C_5_inv,Integers(),B,5),4),3),2); 
