<< "Arrow_Diagrams_and_gl(N).m"

DescendingDiagram[p_List] := Module[
{n=Length[p]},
Diag @@ Table[ar[i, p[[i]]+ n], {i, n}]
];
DescendingBasis[n_] := DescendingDiagram /@ Permutations[Range[n]]

bas3=DescendingBasis[3]

bas4=DescendingBasis[4]

U[deg_, diag_] := (UGLnBiAlg[diag] /. n^p_.*RW[l___] :> EW[GL*n^p*FromDigits[{l}, base^2]] //. h[i_]^p_. EW[l_] :> EW[h[i]^p l]);
diags=Take[bas4,All];
mat = {};
EWRules ={};
Do[
Print[{i,diags[[i]], MaxMemoryUsed[], TimeUsed[]}];
vect = U[4, diags[[i]]] /. EWRules;
Print["Length[vect] is ", Length[vect]];
EWs=Union[Cases[vect, _EW, Infinity]];
If[EWRules === {}, l=0, l=Length[EWRules[[1]]]];
Print["l is ", l];
If[EWRules === {}, 
EWRules=Dispatch[Thread[
EWs -> Table[v[j+l], {j, Length[EWs]}]
]],
EWRules=Dispatch[Join[EWRules[[1]], Thread[
EWs -> Table[v[j+l], {j, Length[EWs]}]
]]]
];
l=Length[EWRules[[1]]];
Print["l is ", l];
Print[i];
AppendTo[mat, 
Replace[#, c_.*v[j_] :> ({i,j} -> c)]& /@ (List @@ vect /. EWRules)
],
{i, Length[diags]}
];
mat = SparseArray[Flatten[mat], {Length[diags], l}];
Print["Computing Rank..."];
MatrixRank[mat]