SetDirectory["C:/drorbn/AcademicPensieve/Projects/Arrow_Diagrams_and_gl(N)"];
<< "Arrow_Diagrams_and_gl(N).m"

Coproduct[diag_Diag, l_] := Total[
T[
NormalizeDiag[#],
NormalizeDiag[Complement[diag, #]]
]& /@ Subsets[diag, {l}]
]

diag=Diag[ar[1,7],ar[5,3],ar[6,2],ar[8,4]]; l=2;

Subsets[diag, {l}]

Coproduct[diag,2]

vs1=Expand[
UGL2BiAlg[Coproduct[#, 1]& /@ Diagrams[3ar]] /. t_T :> Distribute[t]
] //. {
T[c_?NumberQ*a_, b_] :> c T[a,b], T[a_, c_?NumberQ*b_] :> c T[a,b]
};
vs0=Expand[
UGL2BiAlg[Coproduct[#, 0]& /@ Diagrams[3ar]] /. t_T :> Distribute[t]
] //. {
T[c_?NumberQ*a_, b_] :> c T[a,b], T[a_, c_?NumberQ*b_] :> c T[a,b]
};
vs=vs1+vs0

MonomialsIn[expr_] /; !MemberQ[{List, Plus, Times}, Head[expr]] := {expr};
MonomialsIn[p_Times] := {Replace[p, c_?NumberQ  :> 1, {1}]};
MonomialsIn[l_List] := Union @@ (MonomialsIn /@ l);
MonomialsIn[s_Plus] := MonomialsIn[List @@ s];

ts=MonomialsIn[vs]

rule=Dispatch[Thread[ts -> Array[b, {Length[ts]}]]];
mat = SparseArray[
Join @@ Table[
v=vs[[i]];
Table[
t=v[[j]];
c=t/. {_T -> 1, _h->1, _RW->1, n->1};
{i, Replace[t/c, rule] /. b[k_] :>k} -> c,
{j, Length[v]}
],
{i,Length[vs]}
],
{Length[vs], Length[ts]}
]

MatrixRank[mat]