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

diag=BasisAArrow[4][[120]]

diag3=BasisAArrow[3][[12]]

UGLnBiAlg[diag3]

U[deg_, diag_] :=Expand[Plus[
UGLnBiAlg[diag] /. n^p_.*RW[l___] :> EW[n^p*FromDigits[{l}, base^2]] //. h[i_]^p_. EW[l_] :> EW[h[i]^p l],
Coproduct[diag, 1] /. T[d1_, d2_] :> Distribute[T[UGLnBiAlg[d1], UGLnBiAlg[d2]]] /.
T[c_?NumberQ * a1_, a2_] :> c*T[a1,a2] /. T[a1_, c_?NumberQ * a2_] :> c*T[a1,a2] /. T[a1_, a2_] :> EW[1, a1, a2],
Coproduct[diag, 2] /. T[d1_, d2_] :> Distribute[T[UGLnBiAlg[d1], UGLnBiAlg[d2]]] /.
T[c_?NumberQ * a1_, a2_] :> c*T[a1,a2] /. T[a1_, c_?NumberQ * a2_] :> c*T[a1,a2] /. T[a1_, a2_] :> EW[2, a1, a2]
]]

SOU[deg_, diag_] :=Expand[Plus[
USO[diag] /. n^p_.*RW[l___] :> EW[n^p*FromDigits[{l}, base^2]] //. h[i_]^p_. EW[l_] :> EW[h[i]^p l],
(*Coproduct[diag, 1] /. T[d1_, d2_] :> Distribute[T[UGLnBiAlg[d1], UGLnBiAlg[d2]]] /.
T[c_?NumberQ * a1_, a2_] :> c*T[a1,a2] /. T[a1_, c_?NumberQ * a2_] :> c*T[a1,a2] /. T[a1_, a2_] :> EW[1, a1, a2],
Coproduct[diag, 2] /. T[d1_, d2_] :> Distribute[T[UGLnBiAlg[d1], UGLnBiAlg[d2]]] /.
T[c_?NumberQ * a1_, a2_] :> c*T[a1,a2] /. T[a1_, c_?NumberQ * a2_] :> c*T[a1,a2] /. T[a1_, a2_] :> EW[2, a1, a2]*)
]]

U[3, diag3]

vs=U[3, #]&  /@ Diagrams[3ar]

EWs=Union[Cases[vs, _EW, Infinity]]

EWRule=Dispatch[Thread[EWs -> Array[v, {Length[EWs]}]]]

Total[Head/@ vs]

mat = SparseArray[
Join @@ Table[
t=List @@ (vs[[i]] /. EWRule);
Replace[#, c_.*v[j_] :> ({i,j} -> c)]& /@ t,
{i,Length[vs]}
],
{Length[vs], Length[EWs]}
]

MatrixRank[mat]

ds=Take[BasisAArrow[3],2];
vs=Table[
Print[i," ",ds[[i]]];
U[4, ds[[i]]],
{i, Length[ds]}
];
Print["Finding EWs..."];
EWs=Union[Cases[vs, _EW, Infinity]];
EWRule=Dispatch[Thread[EWs -> Array[v, {Length[EWs]}]]];
Print["Computing mat..."];
Print[{Length[vs], Length[EWs]}];
mat = SparseArray[
Join @@ Table[
t=List @@ (vs[[i]] /. EWRule);
Replace[#, c_.*v[j_] :> ({i,j} -> c)]& /@ t,
{i,Length[vs]}
],
{Length[vs], Length[EWs]}
];
Print["Computing Rank..."];
MatrixRank[mat]

ds=Take[BasisAArrow[4],All];
vs=Table[
Print[i," ",ds[[i]]];
U[4, ds[[i]]],
{i, Length[ds]}
];
Print["Finding EWs..."];
EWs=Union[Cases[vs, _EW, Infinity]];
EWRule=Dispatch[Thread[EWs -> Array[v, {Length[EWs]}]]];
Print["Computing mat..."];
Print[{Length[vs], Length[EWs]}];
mat = SparseArray[
Join @@ Table[
t=List @@ (vs[[i]] /. EWRule);
Replace[#, c_.*v[j_] :> ({i,j} -> c)]& /@ t,
{i,Length[vs]}
],
{Length[vs], Length[EWs]}
];
Print["Computing Rank..."];
MatrixRank[mat]

diag=BasisAArrow[4][[101]]

Timing[UGLnBiAlg[diag]]
Timing[USO[diag]]

diag2=BasisAArrow[4][[1]]
Timing[UGLnBiAlg[diag2]]
Timing[USO[diag2]]

diag3=Diag[ar[1,2],ar[3,4],ar[5,6],ar[7,8]]
Timing[UGLnBiAlg[diag3]]
Timing[USO[diag3]]

diag1 : diag3

61015./12980

240520./120263

diag2 : diag3

69759./12980

249731./120263

diag4=Diag[ar[8,1],ar[7,2],ar[6,3],ar[5,4]]
Timing[UGLnBiAlg[diag4]]
Timing[USO[diag4]]

16405./60

18300./60

?b

Diagrams[4 ar]

Diagrams[4 ar]

arbit={Diagrams[4 ar][[1]]};
For[i=1,i<17,i++,
arbit=Append[arbit,Diagrams[4 ar][[i*100]]]];

arbit

ds=Join[Take[BasisAArrow[4],All],arbit];

Length[ds]

ds=Join[Take[BasisAArrow[4],All],arbit];
vs=Table[
Print[i," ",ds[[i]]];
SOU[4, ds[[i]]],
{i, Length[ds]}
];
Print["Finding EWs..."];
EWs=Union[Cases[vs, _EW, Infinity]];
EWRule=Dispatch[Thread[EWs -> Array[v, {Length[EWs]}]]];
Print["Computing mat..."];
Print[{Length[vs], Length[EWs]}];
mat = SparseArray[
Join @@ Table[
t=List @@ (vs[[i]] /. EWRule);
Replace[#, c_.*v[j_] :> ({i,j} -> c)]& /@ t,
{i,Length[vs]}
],
{Length[vs], Length[EWs]}
];
Print["Computing Rank..."];
MatrixRank[mat]

SaveUSO[diag_Diag] := Module[
{fname},
fname= StringJoin[
"USOFor",
ToString[FromDigits[Cases[diag, _Integer, Infinity], sbase]],
".m"
];
Print["Saving ", fname, " ..."];
Put[{diag, USO[diag]},fname];
]

For[i=1,i≤Length[ds],i++,
Print[i," ",ds[[i]]];
SaveUSO[ds[[i]]]
];

For[i=1,i≤Length[BasisAArrow[2]],i++,
Print[i," ",BasisAArrow[2][[i]]];
SaveUSO[BasisAArrow[2][[i]]]
];

Directory[]

SetDirectory[/scratch/leung]

?HomeDirectory

DirectoryStack[]

Put[liefile]

SetDirectory["/scratch/leung"]

Directory[]

Directory[]

For[index=1,index≤Length[ds],i++,
Print[i," ",ds[[i]]];
SaveUSO[ds[[i]]]
];

For[index=45,index≤Length[ds],index++,
Print[index," ",ds[[index]]];
Timing[SaveUSO[ds[[index]]]]
];

Length[Diagrams[4 ar]]

For[index=1,index≤Length[ds],index++,
Print[index," ",ds[[index]]];
];