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,3,6,7,8] then 
r:="i is not in {1,3,6,7,8}";
else
case i:
  when 1:
     k:=1;
  when 3:
     k:=2;
  when 6:
     k:=3;
  when 7:
     k:=4;
  when 8:
     k:=5;
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 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;
C:=<1,C_2,C_3,C_4,C_5>;
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); 
Bs:=[[ElementToSequence(B_conj[i][j]) : j in [1..5]]: i in [1..#G3]]; 
for i in [1..#G3] do 
  Bs[i][2]:=&cat[ ElementToSequence(Bs[i][2][k]) : k in [1..9]]; 
end for; 
Bmat:=RMatrixSpace(Rationals(),168,168)![&cat Bs[i] : i in [1..#G3]]; 
Bmat_inv:=Bmat^-1; 
ZBmat_inv:=RMatrixSpace(Integers(),168,168)!(168*Bmat_inv); 
ZBmat_mod168:=RMatrixSpace(Integers(168),168,168)!(ZBmat_inv); 
ZBmat_mod3:=RMatrixSpace(Integers(3),168,168)!(ZBmat_inv); 
ZBmat_mod7:=RMatrixSpace(Integers(7),168,168)!(ZBmat_inv); 
ZBmat_mod8:=RMatrixSpace(Integers(8),168,168)!(ZBmat_inv); 

E_mod3,H_3:=EchelonForm(Transpose(ZBmat_mod3)); 
E_mod7,H_7:=EchelonForm(Transpose(ZBmat_mod7)); 
E_mod8,H_8:=EchelonForm(Transpose(ZBmat_mod8)); 
H_3:=Transpose(H_3);
H_7:=Transpose(H_7);
H_8:=Transpose(H_8);
E_mod3:=Transpose(E_mod3); 
E_mod7:=Transpose(E_mod7); 
E_mod8:=Transpose(E_mod8); 
E_3:=[[<i,E_mod3[i,s]>: i in [1..168]| E_mod3[i,s] ne 0]: s in [1..Rank(E_mod3)]];
E_7:= [[<i,E_mod7[i,s]>: i in [1..168]| E_mod7[i,s] ne 0]: s in [1..Rank(E_mod7)]];
E_8:= [[<i,E_mod8[i,s]>: i in [1..168]| E_mod8[i,s] ne 0]: s in [1..Rank(E_mod8)]];

print("type: charactercheck(B,i,CT);, to obtain the number of the character of ~omega_i in the charactertable (i must be an element of {1,3,6,7,8})");
print("type: C; to see the element with whom was conjugated");
print("the list B_conj consists of the conjugated Wedderburnimages for each group element, B_conj[8] is the image of g1, B_conj[2] is the image of g2");
print("type: E_3; to see the congruences modulo 3");
print("type: E_7; to see the congruences modulo 7");
print("type: E_8; to see the congruences modulo 8");
print("type: Factorisation(Integers()!Determinant(Bmat)); for the index");
