/*This function takes a set X, consisting of a set N of integers, and a permutation g in Sym(N), and returns the set of
representatives of orbits of elements of X under the action of g.
*/

load "Subgroups/functions.txt";

function EigsToMultiset(E)
return {*i[1]^^i[2]:i in E*};
end function;

function OrbitReps(X,frob)

Orbs:=[];
SpanOfOrbs:=[];
for i in X do
  if(not(Sort(i) in SpanOfOrbs)) then
    Append(~Orbs,i);
    SpanOfOrbs cat:=[Sort(i^(frob^j)):j in [1..Order(frob)-1]];
  end if;
end for;
return Orbs;
end function;

frob:=Sym(8)!(2,3,4,5,6,7,8);

/* We use E8(1741) to do our calculations, as it has an element of order 145*3. We will also need GF(128^4)
   to compute eigenvalues of our element of order 145. */

q:=1741;
F:=GF(q);
w435:=F!16;
w145:=w435^3;
w29:=w145^5;
w5:=w145^29;
FF<vv>:=GF(128^4);
v145:=vv^(Order(vv) div 145);
v29:=vv^(Order(vv) div 29);


/* First we set up the group and its modules up to dimension 64. It is possible, but takes a long time,
   to find the conjugacy classes of 2B2(128). */

G2:=SuzukiGroup(128);

S1:=TrivialModule(G2,GF(128));
S41:=GModule(G2);
S42:=GModule(G2,FrobeniusImage(S41,1));
S43:=GModule(G2,FrobeniusImage(S41,2));
S44:=GModule(G2,FrobeniusImage(S41,3));
S45:=GModule(G2,FrobeniusImage(S41,4));
S46:=GModule(G2,FrobeniusImage(S41,5));
S47:=GModule(G2,FrobeniusImage(S41,6));

S1612:=TensorProduct(S41,S42); S1613:=TensorProduct(S41,S43); S1614:=TensorProduct(S41,S44);
S1615:=TensorProduct(S41,S45); S1616:=TensorProduct(S41,S46); S1617:=TensorProduct(S41,S47);
S1623:=TensorProduct(S42,S43); S1624:=TensorProduct(S42,S44); S1625:=TensorProduct(S42,S45);
S1626:=TensorProduct(S42,S46); S1627:=TensorProduct(S42,S47); S1634:=TensorProduct(S43,S44);
S1635:=TensorProduct(S43,S45); S1636:=TensorProduct(S43,S46); S1637:=TensorProduct(S43,S47);
S1645:=TensorProduct(S44,S45); S1646:=TensorProduct(S44,S46); S1647:=TensorProduct(S44,S47);
S1656:=TensorProduct(S45,S46); S1657:=TensorProduct(S45,S47); S1667:=TensorProduct(S46,S47);

Irr:=[S1,S41,S42,S43,S44,S45,S46,S47,S1612,S1613,S1614,S1615,S1616,S1617,S1623,S1624,
S1625,S1626,S1627,S1634,S1635,S1636,S1637,S1645,S1646,S1647,S1656,S1657,S1667];

for i in [2..6] do for j in [i+1..7] do for k in [j+1..8] do Append(~Irr,TensorProduct(TensorProduct(Irr[i],Irr[j]),Irr[k])); end for; end for; end for;

labs:=["1","4_1","4_2","4_3","4_4","4_5","4_6","4_7","16_{12}","16_{13}","16_{14}","16_{15}","16_{16}","16_{17}","16_{23}","16_{24}",
"16_{25}","16_{26}","16_{27}","16_{34}","16_{35}","16_{36}","16_{37}","16_{45}","16_{46}","16_{47}","16_{56}","16_{57}","16_{67}",
"64_{123}","64_{124}","64_{125}","64_{126}","64_{127}","64_{134}","64_{135}","64_{136}","64_{137}","64_{145}","64_{146}","64_{147}","64_{156}","64_{157}",
"64_{167}","64_{234}","64_{235}","64_{236}","64_{237}","64_{245}","64_{246}","64_{247}","64_{256}","64_{257}","64_{267}","64_{345}","64_{346}","64_{347}",
"64_{356}","64_{357}","64_{367}","64_{456}","64_{457}","64_{467}","64_{567}"];

// CC:=ConjugacyClasses(G2);
// for i in [104..131] do if(v145 in {j[1]:j in EigenvaluesOfElement(ChangeRing(S41,FF),CC[i,3])}) then x145:=XX[i,3]; break i; end if; end for;

repeat xx:=Random(G2); until Order(xx) eq 145;
for i in [1..144] do if v145 in {j[1]:j in EigenvaluesOfElement(ChangeRing(S41,FF),xx^i)} then x145:=xx^i; break i; end if; end for; delete xx;

// We choose ^30 so that we can multiply x29 by an element of order 5 to get x145.
x29:=x145^30;



/* Now we set up the group of Lie type. We need some subgroups of the torus for constructing elements */

G:=GroupOfLieType("E8",q);
V:=VectorSpace(GF(q),8);
rho1:=StandardRepresentation(G);
Over1:=GL(248,q);
g1:=elt<G|V![w435,1,1,1,1,1,1,1]>;
g2:=elt<G|V![1,w435,1,1,1,1,1,1]>;
g3:=elt<G|V![1,1,w435,1,1,1,1,1]>;
g4:=elt<G|V![1,1,1,w435,1,1,1,1]>;
g5:=elt<G|V![1,1,1,1,w435,1,1,1]>;
g6:=elt<G|V![1,1,1,1,1,w435,1,1]>;
g7:=elt<G|V![1,1,1,1,1,1,w435,1]>;
g8:=elt<G|V![1,1,1,1,1,1,1,w435]>;
W:=Reflections(G);
Mats1:=[rho1(i):i in [g1,g2,g3,g4,g5,g6,g7,g8]];
MatsE:=[rho1(i):i in W];
NGT:=sub<Over1|Mats1 cat MatsE>;
T:=sub<NGT|Mats1>;
E:=sub<NGT|MatsE>;

T435:=sub<T|[T.i:i in [1..8]]>;
T145:=sub<T|[T.i^3:i in [1..8]]>;
T29:=sub<T|[T.i^(3*5):i in [1..8]]>;
T5:=sub<T|[T.i^(3*29):i in [1..8]]>;

/* Find the eigenvalues of our elements on the simple modules we have. We also give the coefficients
   for later computation. */

ModEigs145:=[EigsToMultiset(EigenvaluesOfElement(ChangeRing(M,FF),x145)):M in Irr];
ModEigs29:=[EigsToMultiset(EigenvaluesOfElement(ChangeRing(M,FF),x29)):M in Irr];
EigsCoeffs145:=[[Multiplicity(i,v145^j):j in [0..144]]:i in ModEigs145];
EigsCoeffs29:=[[Multiplicity(i,v29^j):j in [0..28]]:i in ModEigs29];

/* We need the elements of orders 29 and 5 in T29 and T5 respectively. We choose representatives
   of the elements of order 29 from a file we loaded earlier, and then load all elements of T5
   with trace -2 on L(E8), again that we constructed earlier. Constructing the elements of order
   29 takes some time. */

load "Traces/E8/Order5Reps";
MultBy5s:=[[29*i:i in j]:j in MyElts];
EigsOfMats:=[[i[j,j]^3:j in [1..248]]:i in Mats1];
load "Traces/E8/Tr29E8OrbReps";
Eigs:={};
EigsReps:=[];
for El in Els do
  gg:=ProduceGroupElement(T29,El);
  Append(~EigsReps,EigsToMultiset(Eigenvalues(gg)));
  Eigs join:={EigsToMultiset(Eigenvalues(gg^i)):i in [1..14]};
  delete gg;
end for;

//There are 17341 classes of elements of order 29, each determined by its eigenvalues

//These are the possible dimensions of composition factors of H on L(E8)

AnsAll:=[{* 1^^8, 4^^12, 16^^4, 64^^2 *},
{* 1^^12, 4^^15, 16^^3, 64^^2 *},
{* 1^^16, 4^^18, 16^^2, 64^^2 *},
{* 1^^20, 4^^21, 16, 64^^2 *},
{* 1^^8, 4^^16, 16^^7, 64 *},
{* 1^^12, 4^^19, 16^^6, 64 *},
{* 1^^16, 4^^22, 16^^5, 64 *},
{* 1^^20, 4^^25, 16^^4, 64 *},
{* 1^^24, 4^^28, 16^^3, 64 *},
{* 1^^28, 4^^31, 16^^2, 64 *},
{* 1^^32, 4^^34, 16, 64 *},
{* 1^^36, 4^^37, 64 *},
{* 1^^8, 4^^20, 16^^10 *},
{* 1^^12, 4^^23, 16^^9 *},
{* 1^^16, 4^^26, 16^^8 *},
{* 1^^20, 4^^29, 16^^7 *},
{* 1^^24, 4^^32, 16^^6 *},
{* 1^^28, 4^^35, 16^^5 *},
{* 1^^32, 4^^38, 16^^4 *},
{* 1^^36, 4^^41, 16^^3 *},
{* 1^^40, 4^^44, 16^^2 *},
{* 1^^44, 4^^47, 16 *},
{* 1^^48, 4^^50 *}
];

/*
We now attack those with no 64 in them. In this case, the 1-eigenspace of the
action of x29 must just be the trivial factors, and is the same as the action
of x145. We first check if there are any rational solutions to the possible
traces of an element of order 29 with the 1-eigenspace of a specified dimension
*/

Mat29:=Matrix(Rationals(),[EigsCoeffs29[i]:i in [1..29]]);
Mat145:=Matrix(Rationals(),[EigsCoeffs145[i]:i in [1..29]]);

"The 1-eigenspace of an element of order 29 on L(E8) has dimension one of";
{Multiplicity(i,1):i in Eigs};
"This eliminates 1^44,4^47,16 and 1^8,4^20,16^10";

"Prove that there is no solution for the ones with eigenspaces of dimension 28, 36, 40 or 48.";

for ttt in [48,40,36,28] do
  EigsSubs:=[i:i in Eigs|Multiplicity(i,1) eq ttt];
  ttt,#EigsSubs;
  NoSoln:=[];
  for ii in [1..#EigsSubs] do
    Ans:=[Multiplicity(EigsSubs[ii],w29^i):i in [0..28]]; MatAns:=Matrix(Rationals(),[Ans]);
    try s:=Solution(Mat29,MatAns); catch e Append(~NoSoln,ii); end try;
  end for;
  NoSoln eq [1..#EigsSubs];
end for;

//We have therefore eliminated Cases 13, 18, 20, 21, 22, 23

// For 32 there are 14 traces for 29 that have a solution, two groups of 7. The labels are [ 8, 8, 21, 10, 5, 24, 9, 0 ] and [ 14, 23, 12, 6, 0, 4, 0, 3 ]
// For 24 there are 7 traces for 29 that have a solution, one group of 7. The label is [ 17, 25, 9, 14, 22, 25, 11, 28 ]
// For 20 we get 21, three groups, labels are [ 15, 11, 0, 15, 9, 16, 19, 13 ] and [ 6, 2, 12, 11, 9, 15, 5, 24 ] and [ 28, 6, 18, 25, 5, 0, 12, 0 ]
// For 16 we get 14, two groups, labels are [ 4, 9, 27, 27, 5, 20, 1, 5 ] and [ 11, 0, 24, 10, 9, 17, 8, 18 ]
// For 12 we get 14, two groups, labels are [ 10, 14, 16, 19, 28, 17, 5, 26 ] and [ 13, 13, 26, 24, 27, 21, 9, 5 ]

ValidEigs:=[];

for ttt in [12,16,20,24,32] do
  EigsSubs:=[i:i in Eigs|Multiplicity(i,1) eq ttt];
  Soln:=[];
  for ii in [1..#EigsSubs] do
    Ans:=[Multiplicity(EigsSubs[ii],w29^i):i in [0..28]]; MatAns:=Matrix(Rationals(),[Ans]);
    try s:=Solution(Mat29,MatAns); Append(~Soln,EigsSubs[ii]); catch e ; end try;
  end for;
  Append(~ValidEigs,[Els[Position(EigsReps,ii)]:ii in Soln|Position(EigsReps,ii) gt 0]);  
end for;

ValidEigs eq [[[13,13,26,24,27,21,9,5],[10,14,16,19,28,17,5,26]],
[[11,0,24,10,9,17,8,18],[4,9,27,27,5,20,1,5]],
[[6,2,12,11,9,15,5,24],[15,11,0,15,9,16,19,13],[28,6,18,25,5,0,12,0]],
[[17,25,9,14,22,25,11,28]],[[14,23,12,6,0,4,0,3],[8,8,21,10,5,24,9,0]]];

/* Now we move to 145. We have to find the preimages of the interesting elements of order 29
   and see which of those are also consistent, but this time with the traces of x145 on the
   simple modules. Our first cut is just by the 1-eigenspace. */

OfInterest:=[]; 
OfInterestx:=[];
for El in &cat ValidEigs do
  El1:=[5*i:i in El];
  // Now find all preimages of our given element of order 29 by elements of order 5 with trace -2.
  Els1:=[[El1[i]+j[i]:i in [1..8]]:j in MultBy5s];
  Eigs145:=[SequenceToMultiset([&*[EigsOfMats[j,i]^El[j]:j in [1..8]]:i in [1..124]]):El in Els1];
  //Takes less than two minutes to do this for each one.
  Eig29:={*i^5:i in Eigs145[1]*};
  E145:=[i:i in [1..#Eigs145]|Multiplicity(Eigs145[i],1) eq Multiplicity(Eig29,1)];
  Append(~OfInterest,[Eigs145[i] join {*j^-1:j in Eigs145[i]*}:i in E145]); Append(~OfInterestx,[Els1[i]:i in E145]); [#i:i in OfInterest];
  delete Eigs145; delete E145; delete Els1;
end for;

/* From those that remain after that first cut, we see if any are consistent for all of the eigenspaces. */

EltForx:=[];
Soln1:=[];
for i in [1..#OfInterest] do
  EigsSubs:=OfInterest[i];
  for ii in [1..#EigsSubs] do
    Ans:=[Multiplicity(EigsSubs[ii],w145^i):i in [0..144]]; MatAns:=Matrix(Rationals(),[Ans]);
    try s:=Solution(Mat145,MatAns); ss:=[s[1,i]:i in [1..29]]; Append(~Soln1,ss); Append(~EltForx,OfInterestx[i,ii]); catch e ; end try;
  end for;
end for;
EltForx:=[[i mod 145:i in j]:j in EltForx];

// These are the multiplicities of the composition factors in the conspicuous sets of composition factors.

Soln1 eq [[16,4,0,4,8,1,8,1,0,0,0,0,2,0,0,0,0,0,0,2,0,0,0,0,4,0,0,0,0],
[16,4,0,8,9,1,0,4,0,2,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,2,0,0,0],
[24,9,0,0,12,3,0,8,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0],
[32,6,0,0,16,0,0,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0]];

// And the element of the torus that has the eigenvalues of x.

EltForx eq [[113,0,33,108,45,27,69,32],
[136,132,77,77,141,13,63,141],
[56,9,16,128,81,9,55,82],
[128,144,89,1,0,136,0,73]];

// Now give the solutions:
for j in Soln1 do
  {*labs[i]^^Integers()!j[i]:i in [1..#j]*};
end for;

/* Since Mat145 has full rank, there is a unique solution if there is any solution. Thus we obtain the
   four conspicuous sets of factors above. We now check that they have the elements of order 435 that
   we claim in the text. */

EigsOfMats435:=[[i[j,j]:j in [1..248]]:i in Mats1];

for OneToCheck in [1..#EltForx] do
  Els2:=ConstructPreimages([3*i:i in EltForx[OneToCheck]],435,3);
  Eigs435:=[SequenceToMultiset([&*[EigsOfMats435[j,i]^El[j]:j in [1..8]]:i in [1..248]]):El in Els2];
  // There is an element of order 145 here, so can use that as the minimum
  nn:=Minimum([#MultisetToSet(i):i in Eigs435]);
  "There are",#[i:i in [1..#Eigs435]|#MultisetToSet(Eigs435[i]) eq nn]-1,"elements of order 435 stabilizing the same eigenspaces";
end for;


"On to cases with a single 64.";

// Having dealt with all cases with no 64, we now consider the ones with a single 64.

Mat29:=Matrix(Rationals(),EigsCoeffs29);

ValidEigs2:=[];

for ttt in [8,12,16,20,24,28,32,36] do
  EigsSubs:=[i:i in Eigs|Multiplicity(i,1) in {ttt,ttt+4}];
  Soln:=[];
  for ii in [1..#EigsSubs] do
    Ans:=[Multiplicity(EigsSubs[ii],w29^i):i in [0..28]]; MatAns:=Matrix(Rationals(),[Ans]);
    try s:=Solution(Mat29,MatAns); Append(~Soln,EigsSubs[ii]); catch e ; end try;
  end for;
  Append(~ValidEigs2,[Els[Position(EigsReps,ii)]:ii in Soln|Position(EigsReps,ii) gt 0]);
end for;

ValidEigs2 eq 
[[[13,13,26,24,27,21,9,5],[10,14,16,19,28,17,5,26]],
[[11,0,24,10,9,17,8,18],[13,13,26,24,27,21,9,5],[10,14,16,19,28,17,5,26],[4,9,27,27,5,20,1,5]],
[[11,0,24,10,9,17,8,18],[6,2,12,11,9,15,5,24],[4,9,27,27,5,20,1,5],[15,11,0,15,9,16,19,13],[28,6,18,25,5,0,12,0]],
[[17,25,9,14,22,25,11,28],[6,2,12,11,9,15,5,24],[15,11,0,15,9,16,19,13],[28,6,18,25,5,0,12,0]],
[[17,25,9,14,22,25,11,28]],
[[14,23,12,6,0,4,0,3],[8,8,21,10,5,24,9,0]],
[[14,23,12,6,0,4,0,3],[8,8,21,10,5,24,9,0]],
[]];

// We store the 1-eigenspaces of the elements of order 29 here
tt:=[8,8,12,12,12,12,16,16,16,16,16,20,20,20,20,24,28,28,32,32,36];
VE2:=&cat ValidEigs2;
OfInterest2:=[]; 
OfInterestx2:=[];

for El in [1..#VE2] do
  El1:=[5*i:i in VE2[El]];
  Els1:=[[(El1[i]+j[i]) mod 145:i in [1..8]]:j in MultBy5s];

  Eigs145:=[SequenceToMultiset([&*[EigsOfMats[j,i]^E[j]:j in [1..8]]:i in [1..124]]):E in Els1];
  //Takes under two minutes to do this for each one.
  E145:=[i:i in [1..#Eigs145]|2*Multiplicity(Eigs145[i],1) eq tt[El]];
  Append(~OfInterest2,[Eigs145[i] join {*j^-1:j in Eigs145[i]*}:i in E145]); Append(~OfInterestx2,[Els1[i]:i in E145]); [#i:i in OfInterest2];
  delete Eigs145; delete E145; delete Els1;
end for;

// Now we check which of them has a solution when we remove a 64. The solution needs to consist of non-negative integers, of course.

function DominatesSequence(A,B)
return &and[A[i] ge B[i]:i in [1..#A]];
end function;

EltForx2:=[];
Soln2:=[];

for cas in [1..#OfInterest2] do
  for OneToCheck in [1..#OfInterest2[cas]] do
    aa:=[Multiplicity(OfInterest2[cas,OneToCheck],w145^i):i in [0..144]];
    ff:=[i:i in [30..#Irr]|DominatesSequence(aa,EigsCoeffs145[i])];
    for ii in ff do
      Ans:=[aa[i]-EigsCoeffs145[ii,i]:i in [1..#aa]];
      MatAns:=Matrix(Rationals(),[Ans]);
      try s:=Solution(Mat145,MatAns);
        ss:=[s[1,i]:i in [1..29]] cat [ii];
        if(&and[i ge 0:i in ss]) then Append(~Soln2,ss); Append(~EltForx2,OfInterestx2[cas,OneToCheck]); #Soln2; end if;
        catch e ;
      end try;
    end for;
  end for;
end for;
EltForx2:=[[i mod 145:i in j]:j in EltForx2];

Soln2 eq [[12,4,0,4,6,1,0,4,0,1,0,0,0,1,0,0,0,0,0,2,0,0,0,0,0,2,0,0,0,57]];
EltForx2 eq [[137,12,80,124,82,85,141,72]];


for j in Soln2 do
  {*labs[i]^^Integers()!j[i]:i in [1..#j-1]*} join {*labs[Integers()!j[#j]]*};
end for;

/* Now we check that again there are elements of order 435 stabilizing all of the eigenspaces */

for OneToCheck in [1..#EltForx2] do
  Els2:=ConstructPreimages([3*i:i in EltForx2[OneToCheck]],435,3);
  Eigs435:=[SequenceToMultiset([&*[EigsOfMats435[j,i]^El[j]:j in [1..8]]:i in [1..248]]):El in Els2];
  // There is an element of order 145 here, so can use that as the minimum
  nn:=Minimum([#MultisetToSet(i):i in Eigs435]);
  "There are",#[i:i in [1..#Eigs435]|#MultisetToSet(Eigs435[i]) eq nn]-1,"elements of order 435 stabilizing the same eigenspaces";
end for;

// Having dealt with all cases with one 64, we now consider the ones with two 64s.

"On to cases with two 64s.";

ValidEigs3:=[];

for ttt in [8,12,16,20] do
  EigsSubs:=[i:i in Eigs|Multiplicity(i,1) in {ttt,ttt+4,ttt+8}];
  Soln:=[];
  for ii in [1..#EigsSubs] do
    Ans:=[Multiplicity(EigsSubs[ii],w29^i):i in [0..28]]; MatAns:=Matrix(Rationals(),[Ans]);
    try s:=Solution(Mat29,MatAns); Append(~Soln,EigsSubs[ii]); catch e ; end try;
  end for;
  Append(~ValidEigs3,[Els[Position(EigsReps,ii)]:ii in Soln|Position(EigsReps,ii) gt 0]);
end for;

ValidEigs3 eq [[[11,0,24,10,9,17,8,18],[13,13,26,24,27,21,9,5],[10,14,16,19,28,17,5,26],[4,9,27,27,5,20,1,5]],
[[11,0,24,10,9,17,8,18],[6,2,12,11,9,15,5,24],[13,13,26,24,27,21,9,5],[10,14,16,19,28,17,5,26],
[4,9,27,27,5,20,1,5],[15,11,0,15,9,16,19,13],[28,6,18,25,5,0,12,0]],
[[11,0,24,10,9,17,8,18],[17,25,9,14,22,25,11,28],[6,2,12,11,9,15,5,24],
[4,9,27,27,5,20,1,5],[15,11,0,15,9,16,19,13],[28,6,18,25,5,0,12,0]],
[[17,25,9,14,22,25,11,28],[6,2,12,11,9,15,5,24],[15,11,0,15,9,16,19,13],[28,6,18,25,5,0,12,0]]];

tt:=[8,8,8,8,12,12,12,12,12,12,12,16,16,16,16,16,16,20,20,20,20];
VE3:=&cat ValidEigs3;
OfInterest3:=[]; 
OfInterestx3:=[];

for El in [1..#VE3] do
  El1:=[5*i:i in VE3[El]];
  Els1:=[[(El1[i]+j[i]) mod 145:i in [1..8]]:j in MultBy5s];

  Eigs145:=[SequenceToMultiset([&*[EigsOfMats[j,i]^E[j]:j in [1..8]]:i in [1..124]]):E in Els1];
  //Takes under two minutes to do this for each one.
  E145:=[i:i in [1..#Eigs145]|2*Multiplicity(Eigs145[i],1) eq tt[El]];
  Append(~OfInterest3,[Eigs145[i] join {*j^-1:j in Eigs145[i]*}:i in E145]); Append(~OfInterestx3,[Els1[i]:i in E145]); [#i:i in OfInterest3];
  delete Eigs145; delete E145; delete Els1;
end for;

// Now we check which of them has a solution when we remove two 64s. The solution needs to consist of non-negative integers, of course.


EltForx3:=[];
Soln3:=[];

for cas in [1..#OfInterest3] do
  "Checking case",cas,"of",#OfInterest3;
  for OneToCheck in [1..#OfInterest3[cas]] do
    aa:=[Multiplicity(OfInterest3[cas,OneToCheck],w145^i):i in [0..144]];
    ff:=[i:i in [30..#Irr]|DominatesSequence(aa,EigsCoeffs145[i])];
    for ii in ff do
      for jj in [ind:ind in ff|ind ge ii] do
        Ans:=[aa[i]-EigsCoeffs145[ii,i]-EigsCoeffs145[jj,i]:i in [1..#aa]]; if(Minimum(Ans) lt 0) then continue jj; end if;
        MatAns:=Matrix(Rationals(),[Ans]);
        try s:=Solution(Mat145,MatAns);
          ss:=[s[1,i]:i in [1..29]] cat [ii,jj];
          if(&and[i ge 0:i in ss]) then Append(~Soln3,ss); Append(~EltForx3,OfInterestx3[cas,OneToCheck]); end if;
          catch e;
        end try;
      end for;
    end for;
  end for;
end for;

Soln3a:=[Soln3[j]:j in Sort([Position(Soln3,i):i in SequenceToSet(Soln3)])];
EltForx3a:=[EltForx3[j]:j in Sort([Position(Soln3,i):i in SequenceToSet(Soln3)])];

Soln3a eq [[8,0,2,4,0,4,0,2,0,0,0,0,0,0,1,0,0,0,0,0,2,0,0,0,0,0,0,1,0,37,42],
[8,0,4,4,0,0,2,2,0,0,0,0,0,0,2,0,0,0,1,0,0,1,0,0,0,0,0,0,0,52,58],
[12,0,1,5,0,4,4,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,33,33],
[12,5,0,0,5,1,0,4,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,57,57],
[12,4,0,4,1,1,0,5,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,56,56],
[12,4,4,0,1,1,1,4,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,55,55],
[12,0,5,0,1,4,1,4,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0,36,36]];

EltForx3a eq [[50,70,22,124,111,114,141,130],
[79,99,109,66,111,143,54,14],
[1,126,31,55,74,17,112,4],
[65,65,72,4,77,76,132,141],
[108,128,109,37,53,27,141,72],
[133,142,0,75,74,80,95,94],
[111,30,90,9,83,0,2,0]];

for j in Soln3a do
  {*labs[i]^^Integers()!j[i]:i in [1..#j-2]*} join {*labs[Integers()!j[#j-1]],labs[Integers()!j[#j]]*};
end for;

for OneToCheck in [1..#EltForx3a] do
  Els2:=ConstructPreimages([3*i:i in EltForx3a[OneToCheck]],435,3);
  Eigs435:=[SequenceToMultiset([&*[EigsOfMats435[j,i]^El[j]:j in [1..8]]:i in [1..248]]):El in Els2];
  // There is an element of order 145 here, so can use that as the minimum
  nn:=Minimum([#MultisetToSet(i):i in Eigs435]);
  "There are",#[i:i in [1..#Eigs435]|#MultisetToSet(Eigs435[i]) eq nn]-1,"elements of order 435 stabilizing the same eigenspaces";
end for;

"We now check the final claim, that there are elements of order 435 stabilizing the eigenspaces comprising the various composition factors of L(E8) for the first and sixth cases.";

EigsFromMods:=[{w145^j:j in [0..144]|k[j+1] ne 0}:k in EigsCoeffs145];

for OneToCheck in [1,6] do
  "Case",OneToCheck;
  Els2:=ConstructPreimages([3*i:i in EltForx3a[OneToCheck]],435,3);
  Eigs435:=[SequenceToSet([&*[EigsOfMats435[j,i]^El[j]:j in [1..8]]:i in [1..248]]):El in Els2];
  E435:=[{*i^3:i in j*}:j in Eigs435];
  for i in [jj:jj in [1..29]|Soln3a[OneToCheck,jj] gt 0] cat [Integers()!Soln3a[OneToCheck,30],Integers()!Soln3a[OneToCheck,31]] do
    i,#[j:j in E435|&*[Multiplicity(j,ii):ii in EigsFromMods[i]] eq 1]-1;
  end for;
end for;


/*
These commands help construct the files imported in this, of the representatives for elements of order 29 and the elements of order 5 with trace -2.


MyElts:=[]; nn:=0;
for a in T5 do nn+:=1; if({i[2]:i in Eigenvalues(a)} eq {48,50}) then Append(~MyElts,ExpressElementInGenerators(T5,a)); nn,#T5,MyElts[#MyElts]; end if; end for;


MyElts:=[]; nn:=0;
for a in T5 do nn+:=1; if({i[2]:i in Eigenvalues(a)} eq {48,50}) then Append(~MyElts,a); nn,#T5; end if; end for;


MyElts:=[];
El1:=[0,0,0,0,0,0,0,0];
Els1:=ConstructPreimages(El1,5,5);
for a in [1..#Els1] do
  if({i[2]:i in Eigenvalues(ProduceGroupElement(T5,Els1[a]))} eq {48,50}) then Append(~MyElts,Els1[a]); a,#MyElts,#Els1,Els1[a]; end if;
end for;

function NextEl(El,n)

if(El[1] lt n-1) then El[1]+:=1; return El; end if;
El[1]:=0;
El2:=NextEl(Remove(El,1),n);
return [0] cat El2;

end function;

procedure AddToList(~Eigs,~Els,El)

gg:=ProduceGroupElement(T29,El);
if(not(Eigenvalues(gg) in Eigs)) then
  Append(~Els,El);
  Eigs join:={Eigenvalues(gg^i):i in [1..14]};
end if;
delete gg;

end procedure;  


El:=[0,0,0,0,0,0,1];
for i in [1..1000000] do
  AddToList(~Eigs,~Els,El);
  El:=NextEl(El,29);
  if(i mod 100 eq 0) then i,#Eigs,#Els,17341; end if;
end for;

for i in [1..1000000] do
  AddToList(~Eigs,~Els,[Random(28):i in [1..8]]);
  if(i mod 100 eq 0) then i,#Eigs,#Els,17341,Els[#Els]; end if;
end for;

*/