// p7g2qmo.m : This program is an analogue of p7exp.m
print "\nConstruct a 2-generator anti-Hughes 7-group of class 14",
  "\nwhich satisfies 6 commutator defining relators and in which",
  "\nthe normal closures of the generators both have class 7.",
  "\nThen repeatedly factor out complements to [b,a]^7 in the centre",
  "\nof the group, to obtain smaller counterexamples";

F<a,b> := FreeGroup(2); p := 7;
Q := quo < F | (b,a,a,a,a,b), (b,a,a,a,a,a,b), (b,a,a,a,a,a,a,b), 
               (a,b,b,b,b,a), (a,b,b,b,b,b,a), (a,b,b,b,b,b,b,a) >;
P := pQuotientProcess( Q, p, p : Exponent :=p );
NextClass( ~P : Exponent := p, MaxOccurrence := [p,p] );
NextClass( ~P : Exponent := p, MaxOccurrence := [p,p] );
NextClass( ~P : Exponent := p, MaxOccurrence := [p,p] );
NextClass( ~P : Exponent := p, MaxOccurrence := [p,p] );
NextClass( ~P : Exponent := p, MaxOccurrence := [p,p] );
NextClass( ~P : Exponent := p, MaxOccurrence := [p,p] );
printf "\nB(2,7 q6 MO77 : 13) has order %o^%o\n", p, FactoredOrder(P)[1][2];
cl14start := FactoredOrder(P)[1][2] + 1;
NextClass( ~P : Exponent := 0, MaxOccurrence := [p,p] );
G<a,b> := ExtractGroup(P); 
printf "\nThe p-covering group G has order %o^%o and class %o",
  p, FactoredOrder(G)[1][2], pClass(G);
print  "\nG is generated by a and b; and [b,a] has order", Order( (b,a) ),
  "\n[b,a,a] has order", Order( (b,a,a) ),
  "; [b,a,b] has order", Order( (b,a,b) ),
  "\ngamma_3(G) is the normal closure of < [b,a,a], [b,a,b] >,",
  "\nand gamma_3(G) has class at most 4, so gamma_3(G) has exponent 7";

print "\nNow compute suitable 7th powers of elements outside the derived group";
load "twB27c8q"; // should be already computed by gettestwq.m
S := [ x^p : x in testwords ];
H<a,b> := quo< G | S >;
printf "The quotient group H has order %o^%o", p, FactoredOrder(H)[1][2];
print "\nH is generated by a and b; and [b,a] has order", Order( (b,a) ),
  "\nH is anti-Hughes; the normal closures of a and b both have class 7";

print "\nNow factor out a complement for [b,a]^7 in the multiplier";
ba7 := Eltseq( (b,a)^p );
lastg := FactoredOrder(H)[1][2];
for alive in [cl14start..lastg] do

  if ba7[alive] eq 0 then continue; end if; // skip if dead
  // Since the exponent of H.alive is nonzero in [b,a]^7 we
  // choose a complement of H.alive
  print "\nFactoring out a complement of", H.alive,
        "gives us a smaller anti-Hughes group";
  CurrentQ<a,b> := quo< H | [ H.i : i in 
                       ([cl14start..alive-1] cat [alive+1..lastg]) ] >;
  printf "CurrentQ with order %o^%o", p, FactoredOrder(CurrentQ)[1][2];
  print "\n  CurrentQ is generated by a and b; and [b,a]^7 =", (b,a)^p;

//Repeatedly factor out complements for [b,a]^7 in the centre
  Z := Centre(CurrentQ);
  while Order(Z) ne p do
    rank := FactoredOrder(Z)[1][2];
    printf "  Z, its centre, has order %o^%o", p, rank;
    print "\n  Now build a complement for [b,a]^7 in Z";
    ZGens := [ CurrentQ!Z.i : i in [1..rank] ];
    _, index := Max( Eltseq( (b,a)^p ) ); 
    ComplGens := [ ZGens[i] * (CurrentQ.index)^-Eltseq(ZGens[i])[index]
                       : i in [1..rank] ];
    NextQ<a,b> := quo< CurrentQ | ComplGens >;
    printf "  Factor it out to get an anti-Hughes group of order %o^%o",
           p, FactoredOrder(NextQ)[1][2];
    print "\n  generated by a and b; and [b,a]^7 =", (b,a)^p;
    CurrentQ := NextQ;
    Z := Centre(CurrentQ);
  end while;

  printf "The centre is generated by %o and has order %o^%o",
         CurrentQ!(Z.1), p, FactoredOrder(Z)[1][2];
  printf "\nSo this method reduces to an anti-Hughes group with order %o^%o",
         p, FactoredOrder(CurrentQ)[1][2];
  print "\nwhich is as far as we can reduce the group (by this method!)";
end for;
