// Tests for Coxeter groups
// DET 2022-01-14

display := false;

R := RootDatum("E6");
W := CoxeterGroup(R);
J := [2,3,4,5];
W0 := ReflectionSubgroup(W,J);
T := Transversal(W,W0);
d := T[#T];
assert Minimum([Length(W,w*d) : w in W0]) eq Length(W,d);

print "Permutation group to matrix group";
for tp in ["A3","B3","C3","D4","E6","E7","E8","F4","G2","H3","H4"] do
  if display then print tp; end if;
  W := CoxeterGroup(tp);
  M, f := CoxeterGroup(GrpMat,W);
  for i in [1..Ngens(W)] do
    assert f(W.i) eq M.i;
  end for;
  for i in [1..Ngens(M)] do
    assert M.i @@ f eq W.i;
  end for;
end for;

print "Permutation group to GrpFPCox";
for tp in ["A3","B3","C3","D4","E6","E7","E8","F4","G2","H3","H4"] do
  if display then print tp; end if;
  W := CoxeterGroup(tp);
  M, f := CoxeterGroup(GrpFP,W);
  for i in [1..Ngens(W)] do
    assert f(W.i) eq M.i;
  end for;
  for i in [1..Ngens(M)] do
    assert M.i @@ f eq W.i;
  end for;
end for;

print "Matrix group to permutation group";
for tp in ["A3","B3","C3","D4","E6","E7","E8","F4","G2","H3","H4"] do
  if display then print tp; end if;
  M := CoxeterGroup(GrpMat,tp);
  W, f := CoxeterGroup(GrpPerm,M);
  for i in [1..Ngens(M)] do
    assert f(M.i) eq W.i;
  end for;
  for i in [1..Ngens(W)] do
    assert W.i @@ f eq M.i;
  end for;
end for;

print "Matrix group to GrpPermCox";
for tp in ["A3","B3","C3","D4","E6","E7","E8","F4","G2","H3","H4"] do
  if display then print tp; end if;
  M := CoxeterGroup(GrpMat,tp);
  W, f := CoxeterGroup(GrpPermCox,M);
  for i in [1..Ngens(M)] do
    assert f(M.i) eq W.i;
  end for;
  for i in [1..Ngens(W)] do
    assert W.i @@ f eq M.i;
  end for;
end for;

print "GrpFPCox to matrix group";
for tp in ["A3","B3","C3","D4","E6","E7","E8","F4","G2","H3","H4"] do
  if display then print tp; end if;
  M := CoxeterGroup(GrpFPCox,tp);
  W, f := CoxeterGroup(GrpMat,M);
  for i in [1..Ngens(M)] do
    assert f(M.i) eq W.i;
  end for;
  for i in [1..Ngens(W)] do
    assert W.i @@ f eq M.i;
  end for;
end for;

print "GrpFPCox to GrpPermCox";
for tp in ["A3","B3","C3","D4","E6","E7","E8","F4","G2","H3","H4"] do
  if display then print tp; end if;
  M := CoxeterGroup(GrpFPCox,tp);
  W, f := CoxeterGroup(GrpPermCox,M);
  for i in [1..Ngens(M)] do
    assert f(M.i) eq W.i;
  end for;
  for i in [1..Ngens(W)] do
    assert W.i @@ f eq M.i;
  end for;
end for;

print "Root system to Coxeter group";
// avoid types B_n and C_n
for tp in ["A3","D4","E6","E7","E8","F4","G2","H3","H4"] do
  if display then print tp; end if;
  R := RootSystem(tp);
  W := CoxeterGroup(GrpMat,R);
  assert CartanName(W) eq tp;
  W := CoxeterGroup(GrpPermCox,R);
  assert CartanName(W) eq tp;
  W := CoxeterGroup(GrpFPCox,R);
  assert CartanName(W) eq tp;
end for;

print "Root datum to Coxeter group";
// avoid types B_n and C_n
for tp in ["A3","D4","E6","E7","E8","F4","G2"] do
  if display then print tp; end if;
  R := RootDatum(tp);
  W := CoxeterGroup(GrpMat,R);
  assert CartanName(W) eq tp;
  W := CoxeterGroup(GrpPermCox,R);
  assert CartanName(W) eq tp;
  W := CoxeterGroup(GrpFPCox,R);
  assert CartanName(W) eq tp;
end for;

print "Coxeter matrix to Coxeter group";
// avoid types B_n and C_n
for tp in ["A3","D4","E6","E7","E8","F4","G2","H3","H4"] do
  if display then print tp; end if;
  M := CoxeterMatrix(tp);
  W := CoxeterGroup(GrpMat,M);
  assert CartanName(W) eq tp;
  W := CoxeterGroup(GrpPermCox,M);
  assert CartanName(W) eq tp;
  W := CoxeterGroup(GrpFPCox,M);
  assert CartanName(W) eq tp;
end for;

print "Cartan matrix to Coxeter group";
// avoid types B_n and C_n
for tp in ["A3","D4","E6","E7","E8","F4","G2","H3","H4"] do
  if display then print tp; end if;
  M := CartanMatrix(tp);
  W := CoxeterGroup(GrpMat,M);
  assert CartanName(W) eq tp;
  W := CoxeterGroup(GrpPermCox,M);
  assert CartanName(W) eq tp;
  W := CoxeterGroup(GrpFPCox,M);
  assert CartanName(W) eq tp;
end for;

print "Coxeter graph to Coxeter group";
for tp in ["A3","D4","E6","E7","E8","F4","G2","H3","H4"] do
  if display then print tp; end if;
  G := CoxeterGraph(tp);
  W := CoxeterGroup(GrpMat,G);
  assert CartanName(W) eq tp;
  W := CoxeterGroup(GrpPermCox,G);
  assert CartanName(W) eq tp;
  W := CoxeterGroup(GrpFPCox,G);
  assert CartanName(W) eq tp;
end for;

print "Dynkin digraph to Coxeter group";
for tp in ["A3","D4","E6","E7","E8","F4","G2"] do
  if display then print tp; end if;
  G := DynkinDigraph(tp);
  W := CoxeterGroup(GrpMat,G);
  assert CartanName(W) eq tp;
  W := CoxeterGroup(GrpPermCox,G);
  assert CartanName(W) eq tp;
  W := CoxeterGroup(GrpFPCox,G);
  assert CartanName(W) eq tp;
end for;

print "Cartan name to Coxeter group";
for tp in ["A3","D4","E6","E7","E8","F4","G2","H3","H4"] do
  if display then print tp; end if;
  W := CoxeterGroup(GrpMat,tp);
  assert CartanName(W) eq tp;
  W := CoxeterGroup(GrpPermCox,tp);
  assert CartanName(W) eq tp;
  W := CoxeterGroup(GrpFPCox,tp);
  assert CartanName(W) eq tp;
end for;

print "Cartan name and rank to irreducible Coxeter group";
for tprk in [<"A",3>,<"D",4>,<"E",6>,<"E",7>,<"E",8>,
             <"F",4>,<"G",2>,<"H",3>,<"H",4>] do
  tp, rk := Explode(tprk);
  type := tp * IntegerToString(rk);
  if display then print type; end if;
  W := IrreducibleCoxeterGroup(GrpMat,tp,rk);
  assert CartanName(W) eq type;
  W := IrreducibleCoxeterGroup(GrpPermCox,tp,rk);
  assert CartanName(W) eq type;
  W := IrreducibleCoxeterGroup(GrpFPCox,tp,rk);
  assert CartanName(W) eq type;
end for;

