/* Tests for standard representations of Lie algebras and groups of Lie type
   DET 2024-1-15
*/

rootDtm := function(n)
  case n:
  when 1:
    "A3 C4";
    A := DiagonalJoin(CartanMatrix("A3"),CartanMatrix("C4"));
    B := IdentityMatrix(Integers(),Nrows(A));
    R := RootDatum(A,B);
  when 2:
    "A3 C4 permuted";
    A := DiagonalJoin(CartanMatrix("A3"),CartanMatrix("C4"));
    B := IdentityMatrix(Integers(),Nrows(A));
    pi := Sym(7)!(1, 4, 2, 7, 5);
    P := PermutationMatrix(Integers(),pi);
    A := P^-1*A*P;
    R := RootDatum(A,B);
  when 3:
    "D4 permuted";
    A := Matrix(Integers(), 4,4, 
        [ 2, -1,  0, 0,
        -1, 2,  -2, 0,
         -1, 0,   2, -2,
         -1, 0,  0, 2 ]);
    B := Matrix(Integers(), 4, 4, 
        [ 1, 0, 0, 0, 
          0, 1, 0, 0, 
          0, 1, 1, 0, 
          0, 1, 1, 1 ]);
    R := RootDatum(A,B);
  when 4:
    "A3 B3 C3 D4 permuted";
    A := DiagonalJoin(<CartanMatrix(tp) : tp in ["A3","B3","C3","D4"]>);
    B := IdentityMatrix(Integers(),Nrows(A));
    pi := Sym(13)!(3, 5, 11)(4, 7, 10)(9, 12);
    P := PermutationMatrix(Integers(),pi);
    A := P^-1*A*P;
    R := RootDatum(A,B);
  else error "value out of range",n;
  end case;
  return R;
end function;

time for q in [2,3,4] do
  for n in [1..4] do
    R := rootDtm(n);
    K := GF(q);
    L := LieAlgebra(R,K);
    L;
    psi := StandardRepresentation(L);
    m := Dimension(L);
    for i,j in [1..m] do
      assert psi(L.i)*psi(L.j) eq psi(L.i*L.j);
    end for;
  end for;
end for;


time for q in [2,3,4] do
  for n in [1..4] do
    R := rootDtm(n);
    K := GF(q);
    xi := PrimitiveElement(K);
    G := GroupOfLieType(R,K);
    G;
    f := StandardRepresentation(G);
    N := NumPosRoots(R);
    for i,j in [1..2*N] do 
      x := elt<G|<i,xi>>;
      y := elt<G|<j,xi>>;
      assert f(x*y) eq f(x)*f(y);
    end for;
  end for;
end for;

