/* This program checks that the elements of orders dividing 65 are determined
up to G-conjugacy by their eigenvalues on L(G). In addition, we find all
elements of order 195 in N_G(T) that power to a fixed element of order 65 with
the correct eigenvalues on L(G), and show that the properties claimed in the
text are correct. We give here the eigenvalues of the elements, which we assume
have been deduced already using the program ComputeConspicuousFactorsE8.
*/

load "Subgroups/functions.txt";

function FindOrb(Orbs,i)
for Orb in Orbs do if(i in Orb) then return Orb; end if; end for;
return {};
end function;

q:=2^12;
F<w2>:=GF(q);
G:=GroupOfLieType("E8",q);
V:=VectorSpace(GF(q),8);
rho1:=StandardRepresentation(G);
Over1:=GL(248,q);
g1:=elt<G|V![w2,1,1,1,1,1,1,1]>;
g2:=elt<G|V![1,w2,1,1,1,1,1,1]>;
g3:=elt<G|V![1,1,w2,1,1,1,1,1]>;
g4:=elt<G|V![1,1,1,w2,1,1,1,1]>;
g5:=elt<G|V![1,1,1,1,w2,1,1,1]>;
g6:=elt<G|V![1,1,1,1,1,w2,1,1]>;
g7:=elt<G|V![1,1,1,1,1,1,w2,1]>;
g8:=elt<G|V![1,1,1,1,1,1,1,w2]>;
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>;

T13:=sub<T|[T.i^315:i in [1..8]]>;
T65:=sub<T|[T.i^63:i in [1..8]]>;
T195:=sub<T|[T.i^21:i in [1..8]]>;

R:=ResidueClassRing(195);
X:=[[R!((Log((T195.j)[i,i])*195) div 4095):i in [1..248]]:j in [1..8]];


Eigs1:={ <w2^2835, 5>, <w2^1638, 3>, <w2^2016, 3>, <w2^819, 3>, <w2^504, 3>, <w2^2583,4>, <w2^2646, 4>, <w2^3276, 3>, <w2^4032, 3>, <w2^2457, 3>, <w2^2205, 5>,
<w2^3780, 5>, <w2^2772, 4>, <w2^2331, 3>, <w2^693, 4>, <w2^1701, 4>, <w2^1890,5>, <w2^882, 3>, <w2^2079, 3>, <w2^3150, 5>, <w2^1449, 4>, <w2^1323, 4>,
<w2^2520, 5>, <w2^1575, 5>, <w2^2394, 4>, <w2^2709, 4>, <w2^1512, 4>, <w2^1197,4>, <w2^3906, 4>, <w2^315, 5>, <w2^2142, 4>, <w2^2961, 3>, <w2^3213, 3>,
<w2^3465, 5>, <w2^252, 3>, <w2^567, 3>, <w2^3528, 3>, <w2^1953, 4>, <w2^3717,4>, <w2^1386, 4>, <w2^3339, 4>, <w2^1134, 3>, <w2^3087, 3>, <w2^378, 4>,
<w2^1071, 4>, <w2^2268, 3>, <w2^1827, 3>, <w2^3024, 4>, <w2^441, 3>, <w2^3591,3>, <w2^630, 5>, <w2^945, 5>, <w2^1008, 3>, <w2^1764, 3>, <w2^2898, 4>, <w2^189,
4>, <w2^63, 3>, <w2^3843, 3>, <w2^3969, 3>, <1, 8>, <w2^756, 4>, <w2^3402, 4>,<w2^3654, 3>, <w2^126, 3>, <w2^1260, 5> };

Eigs2:={ <w2^1575, 19>, <w2^2205, 19>, <w2^3150, 19>, <w2^3780, 19>, <w2^2835, 19>,<w2^1260, 19>, <w2^945, 19>, <w2^3465, 19>, <1, 20>, <w2^630, 19>, <w2^315, 19>,
<w2^1890, 19>, <w2^2520, 19> };

El1:=[90,105,90,90,180,60,90,120];
Els1:=ConstructPreimages(El1,195,5);
e13:={*i[1]^^i[2]:i in Eigs1*};
e1:={*R!((Log(i)*195) div 4095):i in e13*};

NextEls1:=[];
for ii in [1..#Els1] do
  if e1 eq {*&+[Els1[ii,i]*X[i,j]:i in [1..8]]:j in [1..248]*} then Append(~NextEls1,Els1[ii]); end if;
end for;

gg1:=ProduceGroupElements(T195,NextEls1);
EltsToMerge:=[E.1*E.2*E.4*E.2*E.5*E.4*E.2*E.3*E.4*E.5*E.6*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3*E.1*E.7*E.6*E.5*E.4*E.2*E.3*E.4*E.5*E.6*E.7*E.8*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3*E.7*E.6,E.3*E.1*E.5*E.4*E.2*E.3*E.4*E.5*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3*E.1*E.7*E.6*E.5*E.4*E.2*E.3*E.4*E.5*E.6*E.7*E.8*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3*E.1*E.7*E.6*E.5*E.4*E.2*E.3*E.4*E.5*E.6*E.7];
Orbs:={{i}:i in [1..#NextEls1]};
for e in EltsToMerge do
  for i in [1..#NextEls1] do
    j:=Position(gg1,gg1[i]^e);
    Orb1:=FindOrb(Orbs,i);
    if(j ne 0 and not(j in Orb1)) then
      Orb2:=FindOrb(Orbs,j);
      Exclude(~Orbs,Orb1);
      Exclude(~Orbs,Orb2);
      Include(~Orbs,Orb1 join Orb2);// printf "Merged %o and %o.\n",Orb1,Orb2;
      delete Orb1; delete Orb2; if(#Orbs eq 1) then "All merged"; break e; end if;
    end if;
  end for;
  "So far we have merged elements into",#Orbs,"orbits";
end for;

El2:=NextEls1[1];
Els2:=ConstructPreimages(El2,195,3);
NextEls2:=[];
for ii in [1..#Els2] do
  if #{&+[Els2[ii,i]*X[i,j]:i in [1..8]]:j in [1..248]} le 91 and GCD(Els2[ii]) eq 1 then Append(~NextEls2,Els2[ii]); end if;
end for;

Ei:=[{*&+[ii[i]*X[i,j]:i in [1..8]]:j in [1..248]*}:ii in NextEls2];


/* Depending on your choice of an element x of order 65, you obtain that the eigenvalues of x on 24_i
   are one of the two options below, and the eigenvalues of x on 24_{3-i} are the other set. */

EigsOf24s:=[{<w2^2520,1>,<w2^693,1>,<w2^2772,1>,<w2^2898,1>,<w2^630,1>,<w2^3465,1>,<w2^1953,1>,<w2^819,1>,<1,4>,<w2^1197,1>,<w2^1890,1>,
<w2^3276,1>,<w2^1323,1>,<w2^3402,1>,<w2^2142,1>,<w2^1575,1>,<w2^2583,1>,<w2^2205,1>,<w2^3717,1>,<w2^1512,1>,<w2^378,1>},
{<w2^1260,1>,<w2^2394,1>,<w2^2457,1>,<w2^2709,1>,<w2^3024,1>,<w2^189,1>,<w2^2646,1>,<w2^1701,1>,<w2^3906,1>,<w2^315,1>,<w2^1449,1>,
<w2^945,1>,<1,4>,<w2^2835,1>,<w2^1071,1>,<w2^3780,1>,<w2^756,1>,<w2^1638,1>,<w2^1386,1>,<w2^3150,1>,<w2^3339,1>}];
EigsOf24s:=[{*i[1]^^i[2]:i in j*}:j in EigsOf24s];

//We now obtain the exponents of these as 195th roots of unity.

EiOf24s:=[{*R!((Log(i)*195) div 4095):i in j*}:j in EigsOf24s];

/* We want to test whether, for each possibility in EigsOf24s, each eigenspace represented there is *not* split
   from x of order 65, to a preimage \hat x of order 195. We do this by cubing the eigenvalues of \hat x and
   counting multiplicities, then checking that the multiplicity is 1 for each eigenvalue in EigsOf24s. */

Ei2:=[{*3*i:i in MultisetToSet(Ei[j])*}:j in [1,2,3,4]];
"Should be true for one and false for the other";
for ii in [1..4] do 
  [&and[Multiplicity(Ei2[ii],i) eq 1:i in EiOf24s[jj]]:jj in [1..2]];
end for;

"We see that each set of eigenvalues for 24_i is stabilized by two preimages";

