/* In this case we let H denote a copy of PSL(2,25), L denote the subgroup 5^2.12, and let G denote F4(81).
   We give matrices defining L, an element of order 5 and an element of order 12. L lies in the normalizer of
   a torus of F4(81), as constructed using the GroupOfLieType command. We give H as L and a single matrix,
   which were chosen at random. A posteriori, one could produce H as a subgroup of F4 and show that no other
   overgroup of L preserves the F4 trilinear form, but we prefer a less synthetic proof.
*/

F<ww>:=GF(81);
l1:=GL(26,F)![[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,ww^64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,ww^32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,ww^64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,ww^48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,ww^32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,ww^16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,ww^16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,ww^48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,ww^32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,ww^16,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,ww^48,0,0,0],
[0,ww^32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,ww^8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,ww^8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,ww^64,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,ww^16,0,0,0,0,0,0,0,0],
[0,0,ww^16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]];

L:=sub<GL(26,F)|[l1,l2]>;

h1:=GL(26,F)![[0,ww^43,ww^19,ww^42,ww^24,ww^5,ww^69,0,ww^14,ww^30,0,ww^13,ww^73,ww^7,0,ww^21,ww^26,ww^10,ww^45,0,ww^69,ww^56,ww^38,ww^15,ww^31,0],
[ww^65,ww^66,ww^62,0,ww^67,0,ww^62,ww^73,ww^67,ww^3,ww^64,0,ww^76,ww^10,ww^56,0,ww^19,ww^3,ww^18,ww^13,0,ww^19,0,ww^58,ww^14,ww^21],
[ww^25,ww^46,ww^72,ww^65,ww^67,0,0,0,ww^27,ww^3,ww^34,ww^66,ww^50,ww^71,ww^46,ww^14,ww^59,ww^3,0,0,0,ww^19,ww^21,ww^8,ww^34,ww^61],
[ww^42,0,ww^59,0,ww^14,ww^5,ww^69,0,ww^24,ww^50,ww^71,ww^53,ww^68,ww^33,ww^3,ww^61,ww^56,ww^70,ww^45,0,ww^69,ww^26,0,ww^55,0,ww^38],
[ww^72,ww^13,ww^29,ww^62,0,0,ww^79,ww^30,ww^14,0,ww^61,ww^3,ww^28,ww^73,ww^53,ww^71,ww^26,0,ww^75,ww^50,0,0,ww^18,ww^45,ww^21,ww^48],
[ww^75,0,0,ww^75,0,ww^38,ww^32,ww^3,ww^57,ww^53,ww^14,ww^26,ww^76,ww^10,ww^66,ww^54,ww^69,ww^73,ww^8,ww^43,ww^2,0,ww^51,0,0,ww^51],
[ww^75,ww^46,0,ww^75,ww^37,ww^48,ww^22,ww^43,0,ww^13,0,ww^6,ww^71,ww^36,0,ww^74,0,ww^33,ww^58,ww^3,ww^32,ww^9,ww^51,0,ww^34,ww^51],
[0,ww^3,0,0,ww^14,ww^45,ww^69,ww^70,ww^34,2,ww^11,ww^13,ww^47,ww^68,ww^63,ww^21,ww^6,2,ww^45,ww^10,ww^29,ww^26,0,0,ww^71,0],
[ww^62,ww^13,ww^69,ww^72,ww^14,ww^35,0,ww^50,0,0,ww^61,ww^43,ww^33,ww^47,ww^53,ww^31,0,0,0,ww^30,ww^79,ww^26,ww^48,ww^5,ww^21,ww^18],
[ww^62,ww^13,ww^29,ww^2,0,ww^15,ww^39,2,0,ww^50,ww^21,0,ww^47,ww^68,ww^13,0,0,ww^70,ww^35,1,ww^19,0,ww^78,ww^45,ww^21,ww^18],
[0,ww^16,ww^2,ww^45,ww^67,ww^78,0,ww^33,ww^67,ww^43,ww^34,0,ww^71,ww^36,ww^46,0,ww^19,ww^43,0,ww^53,ww^42,ww^19,ww^41,ww^38,ww^24,0],
[ww^35,0,ww^2,ww^75,ww^57,ww^58,ww^22,ww^3,ww^17,0,0,ww^56,ww^50,ww^71,0,ww^64,ww^29,0,ww^58,ww^43,ww^62,ww^69,ww^51,ww^38,0,ww^11],
[ww^33,ww^14,ww^70,ww^73,ww^65,ww^46,ww^70,ww^41,ww^25,ww^41,ww^22,ww^54,ww^34,ww^69,ww^14,ww^62,ww^57,ww^41,ww^46,ww,ww^30,ww^17,ww^49,ww^6,ww^22,ww^9],
[ww^73,ww^54,ww^30,ww^33,ww^25,ww^6,ww^30,ww,ww^65,ww,ww^62,ww^14,ww^8,ww^74,ww^54,ww^22,ww^17,ww,ww^6,ww^41,ww^70,ww^57,ww^9,ww^46,ww^62,ww^49],
[0,ww^56,ww^62,ww^25,ww^27,ww^18,0,ww^53,ww^27,ww^3,ww^14,0,ww^31,ww^76,ww^66,0,ww^59,ww^3,0,ww^33,ww^22,ww^59,ww^61,ww^58,ww^64,0],
[ww^75,0,ww^62,ww^35,ww^77,ww^38,ww^42,ww^43,ww^37,0,0,ww^16,ww^10,ww^31,0,ww^24,ww^9,0,ww^38,ww^3,ww^2,ww^49,ww^11,ww^58,0,ww^51],
[ww^42,ww^13,ww^69,ww^72,ww^74,ww^15,0,ww^70,0,0,ww^61,ww^23,ww^33,ww^47,ww^53,ww^51,0,0,0,ww^10,ww^19,ww^46,ww^48,ww^5,ww^21,ww^38],
[ww^42,ww^13,ww^29,ww^22,0,ww^35,ww^59,2,0,ww^70,ww^21,0,ww^47,ww^68,ww^13,0,0,ww^50,ww^15,1,ww^79,0,ww^58,ww^45,ww^21,ww^38],
[ww^35,ww^66,0,ww^35,ww^17,ww^8,ww^42,ww^3,0,ww^73,0,ww^26,ww^31,ww^76,0,ww^54,0,ww^53,ww^38,ww^43,ww^72,ww^29,ww^11,0,ww^14,ww^11],
[0,ww^23,0,0,ww^34,ww^5,ww^29,ww^10,ww^14,1,ww^31,ww^53,ww^7,ww^28,ww^43,ww^61,ww^26,1,ww^5,ww^70,ww^69,ww^6,0,0,ww^51,0],
[ww^75,0,0,ww^75,0,ww^18,ww^32,ww^3,ww^37,ww^73,ww^74,ww^46,ww^76,ww^10,ww^6,ww^34,ww^9,ww^53,ww^8,ww^43,ww^22,0,ww^51,0,0,ww^51],
[ww^72,ww^13,ww^29,ww^42,0,0,ww^19,ww^10,ww^74,0,ww^61,ww^63,ww^28,ww^73,ww^53,ww^11,ww^46,0,ww^55,ww^70,0,0,ww^38,ww^45,ww^21,ww^48],
[ww^22,0,ww^79,0,ww^34,ww^45,ww^29,0,ww^64,ww^30,ww^51,ww^13,ww^28,ww^73,ww^23,ww^21,ww^16,ww^10,ww^5,0,ww^29,ww^6,0,ww^35,0,ww^58],
[ww^5,ww^26,ww^72,ww^45,ww^67,0,0,0,ww^27,ww^3,ww^54,ww^6,ww^50,ww^71,ww^26,ww^74,ww^59,ww^3,0,0,0,ww^19,ww^41,ww^8,ww^54,ww],
[ww^5,ww^46,ww^2,0,ww^27,0,ww^2,ww^13,ww^27,ww^43,ww^24,0,ww^36,ww^50,ww^16,0,ww^59,ww^43,ww^78,ww^73,0,ww^59,0,ww^38,ww^34,ww],
[0,ww^63,ww^39,ww^22,ww^64,ww^45,ww^29,0,ww^34,ww^50,0,ww^53,ww^33,ww^47,0,ww^61,ww^6,ww^70,ww^5,0,ww^29,ww^16,ww^58,ww^75,ww^11,0]];

H:=sub<GL(26,F)|l1,l2,h1>;
// We need the indices of the trilinear form as well.
seqs:=[[i,j,k]:i,j,k in [1..NumberOfRows(l1)]|i le j and j le k];

ents:=[273,295,313,327,332,571,584,597,608,628,644,840,855,883,926,942,1081,1098,1158,1181,1209,1295,1314,1410,1433,1452,1581,1613,
1640,1653,1674,1773,1807,1836,1861,2012,2039,2052,2072,2167,2196,2220,2361,2374,2384,2483,2507,2615,2718,2731];
vals:=[1,2,1,2,1,1,2,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,1,2,2,1,2,1,1,2,2,1,2,1,2,1,1,2,2,1,1,1,1];

f26:=[F!0:i in [1..#seqs]];
for i in [1..#ents] do f26[ents[i]]:=vals[i]; end for;

// Now set up the centralizer of L in GL(26,F), which is given by all possible matrices scal below.

R<a,b,c,d>:=PolynomialRing(F,4);
scal:=DiagonalMatrix([a,b,b,a,a,b,b,a,a,a,b,b,c-d,c+d,b,b,a,a,b,a,b,a,a,b,b,a]);
scal[14,13]:=d;
scal[13,14]:=-d;


// We also need this matrix ring so we can multiply elements of F4 by scal, as we have to coerce them into this ring first
mats:=MatrixRing(R,26);

//mats!l1*scal eq scal*mats!l1 and mats!l2*scal eq scal*mats!l2;

function Matricise(v)
return Matrix(1,NumberOfColumns(v),[R!v[i]:i in [1..NumberOfColumns(v)]]);
end function;

// We now show that g, which is the second generator of H (the first lies in L, so is fine) satisfies the equations mentioned
V:=GModule(L);
g:=mats!h1;

intseqs1:=[seqs[i]:i in ents];
intseqs:=&join{{[i[1],i[2],i[3]],[i[1],i[3],i[2]],[i[2],i[1],i[3]],[i[2],i[3],i[1]],[i[3],i[1],i[2]],[i[3],i[2],i[1]]}:i in intseqs1};

function ProdRel(seq)

u:=V.seq[1]; v:=V.seq[2]; w:=V.seq[3];
u1:=Matricise(u)*scal; v1:=Matricise(v)*scal; w1:=Matricise(w)*scal;
u2:=Matricise(u)*g*scal; v2:=Matricise(v)*g*scal; w2:=Matricise(w)*g*scal;
e1:=&+[u1[1,i[1]]*v1[1,i[2]]*w1[1,i[3]]*f26[Position(seqs,Sort([i[1],i[2],i[3]]))]:i in intseqs];
e2:=&+[u2[1,i[1]]*v2[1,i[2]]*w2[1,i[3]]*f26[Position(seqs,Sort([i[1],i[2],i[3]]))]:i in intseqs];

return e1-e2;
end function;

function CheckRel(seq,gg)
u:=V.seq[1]; v:=V.seq[2]; w:=V.seq[3];
u2:=u^gg; v2:=v^gg; w2:=w^gg;
e1:=&+[u[i[1]]*v[i[2]]*w[i[3]]*f26[Position(seqs,Sort([i[1],i[2],i[3]]))]:i in intseqs];
e2:=&+[u2[i[1]]*v2[i[2]]*w2[i[3]]*f26[Position(seqs,Sort([i[1],i[2],i[3]]))]:i in intseqs];
return e1-e2;
end function;

function CheckDetermination()

ProdRel([1,1,8]) eq -(a-ww^79*c)^3;
ProdRel([2,2,11]) eq -(b-ww^42*c)^3;

coeffs1:=[ww^79*c,ww^42*c,c,d];
// Now kill off d.
Evaluate(ProdRel([1,7,26]),coeffs1) eq c^2*(d-ww^69*c);

coeffs2:=[ww^79*c,ww^42*c,c,ww^69*c];

scal2:=Evaluate(scal,coeffs2);
sca:=GL(26,F)!Evaluate(scal2,[1:i in [1..4]]);

gg:=h1^sca;

// Then that gg does lie in F4.
{*CheckRel(i,gg):i in seqs*} eq {*0^^3276*};

// Now check that the normalizer of L normalizes H1.
H1:=sub<GL(26,F)|l1,l2,gg>;
NH:=sub<GL(26,F)|l1,l2,gg,l3>;
Index(NH,H1) eq 2 and IsIsomorphic(H1,PSL(2,25));
// We will check that <L,l3> is the normalizer of L in NGT, which is the normalizer of L in G, in CheckF4Form.

return "";
end function;

// We now give code that can prove that the trilinear form we gave is the correct one. The normalizer of a torus
// has a small space of trilinear forms for F4. We use two random generators to quickly reduce to that space, and
// and then choose a random element of F4 to reduce the space of trilinear forms down to 1 dimension.

function CheckF4Form()

q:=81;
GG:=GroupOfLieType("F4",q);
z:=PrimitiveElement(F)^16;
W:=VectorSpace(GF(q),4);
rho:=StandardRepresentation(GG);
Over:=GL(26,q);
g1:=elt<GG|W![z,1,1,1]>;
g2:=elt<GG|W![1,z,1,1]>;
g3:=elt<GG|W![1,1,z,1]>;
g4:=elt<GG|W![1,1,1,z]>;
Refs:=Reflections(GG);
Mats:=[rho(i):i in [g1,g2,g3,g4]];
MatsE:=[rho(i):i in Refs];
NGT:=sub<Over|Mats cat MatsE>;

// Confirm that L is a subgroup of F4:

l1 in NGT and l2 in NGT and l3 in NGT;
Normalizer(NGT,L) eq sub<NGT|L,l3>;

// Check our assertions from the paper:

// Note that the character of M(F4) on elements of order 5 is 1.
subs:=[i`subgroup:i in Subgroups(NGT:OrderEqual:=25)|{BrauerCharacter(GModule(i`subgroup))[j]:j in {2..25}} eq {1}];
#subs eq 1;
Bool:=IsConjugate(NGT,DerivedSubgroup(L),subs[1]); Bool;
Ns:=Normalizer(NGT,subs[1]);
subs2:=Subgroups(Ns:OrderEqual:=12,IsCyclic:=true);
Ltest:=sub<NGT|subs[1],subs2[1]`subgroup>;
Bool:=IsConjugate(NGT,L,Ltest); Bool;
Index(NGT,Centralizer(NGT,subs[1])) eq 1152; //the order of W(F4). This shows that C_G(L0)=T.

// Now build the matrix of linear relations that the trilinear form must satisfy.
mat:=[];
repeat y1:=Random(NGT); y2:=Random(NGT); until NGT eq sub<NGT|y1,y2>;
for h in [y1,y2] do
  for nn in [1..#seqs] do a:=seqs[nn,1]; b:=seqs[nn,2]; c:=seqs[nn,3];
    val:=[F!0:i in [1..#seqs]];
    for i in [1..NumberOfRows(h)] do if(h[a,i] ne 0) then for j in [1..NumberOfRows(h)] do if(h[b,j] ne 0) then for k in [1..NumberOfRows(h)] do
      val[Position(seqs,Sort([i,j,k]))]+:=h[a,i]*h[b,j]*h[c,k];
    end for; end if; end for; end if; end for;
    val[nn]-:=1; Append(~mat,val); delete val;
  end for;
  delete h;
end for;

repeat
  h:=rho(Random(GG));
  for iii in [1..5] do nn:=Random([1..#seqs]); a:=seqs[nn,1]; b:=seqs[nn,2]; c:=seqs[nn,3];
    val:=[F!0:i in [1..#seqs]];
    for i in [1..NumberOfRows(h)] do if(h[a,i] ne 0) then for j in [1..NumberOfRows(h)] do if(h[b,j] ne 0) then for k in [1..NumberOfRows(h)] do
      val[Position(seqs,Sort([i,j,k]))]+:=h[a,i]*h[b,j]*h[c,k];
    end for; end if; end for; end if; end for;
    val[nn]-:=1; Append(~mat,val); delete val;
  end for;
  delete h;
until Dimension(Nullspace(Transpose(Matrix(F,mat)))) eq 1;

ftest:=Nullspace(Transpose(Matrix(F,mat))).1;
"Is the trilinear form given in this document correct?";
return &and[ftest[i] eq f26[i]:i in [1..#f26]];

end function;

"The function CheckF4Form() checks that the trilinear form f26 from F4 is correct";
"The function CheckDetermination() checks that the determination of the possible conjugates into F4 is correct.";