(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



{s0, s1} = {1, 1};
Gens[_, -1] = {};
Gens[_, 0] = {1};
Gens[n_,m_] := Gens[n,m]= (List @@ Expand[
(Sum[x[i], {i,n}]+Sum[a[i,j], {i,n}, {j,n}])^m
]) /. (_Integer*b_) :> b;
LR1[i_,j_][Z_] := Module[
{tails},
tails = Union[Cases[{Z}, a[k_,i] :> k, Infinity]];
Expand[Plus[
If[i==j, s0 x[i]Z, 0],
Sum[
(x[i]a[k,j]-x[k]a[i,j])D[Z, a[k,i]],
{k, tails}
]
]]
];
LR2[i_,j_][Z_] := Module[
{tails, heads},
tails = Union[Cases[{Z}, a[k_,j] :> k, Infinity]];
heads = Union[Cases[{Z}, a[j,k_] :> k, Infinity]];
Expand[Plus[
If[i==j, s1 x[i]Z, 0],
Sum[
(x[i]a[k,j]-x[k]a[i,j])D[Z, a[k,j]],
{k, tails}
],
Sum[
(x[j]a[i,k]-x[i]a[j,k])D[Z, a[j,k]],
{k, heads}
]
]]
];
Rels[n_,m_] := DeleteCases[
Union[Flatten[
Table[
{LR1[i,j] /@ Gens[n, m-1], LR2[j,i] /@ Gens[n, m-1]},
{i,2,n}, {j,n}
]
]],
0];
RRels[n_,m_] := Module[
{gens, rels, mat},
gens = Gens[n,m];
rels = Rels[n,m];
mat = rels /. Thread[gens -> IdentityMatrix[Length[gens]]];
DeleteCases[RowReduce[mat].gens, 0]
]



