Computing dim ((Subscript[H, d])^p)(D)

dimH(p,d,D) returns the dimension of the space (Subscript[(H^p), d])(D) defined on p.11 of [Carlet-Casati-Shadrin].

Tbasis[dd_,DD_]:=v@@@Union@@Table[Sort[Sort/@Tuples[Range[DD-1],i]],{i,0,dd}]; 
degreem[m_]:=Plus@@Length/@List@@m;  
Tpoly[pp_,dd_,basis_]:=Select[NonCommutativeMultiply@@@Subsets[basis,{pp}],degreem[#]==dd&]; 
der[n_,x_Plus]:=der[n,#]&/@x;
der[n_,c_?NumberQ x_]:=c der[n,x];
der[n_,NonCommutativeMultiply[a_,b_]]:=der[n,a]**b+a**der[n,b];
der[n_,v[a___]]:=v@@Sort[{a,n}];
expand[expr_]:=Expand[expr//.{Plus[x__]**y_:>Distribute[Plus[x]**y],y_**Plus[x__]:>Distribute[y**Plus[x]]}];
order[a_,b_]:=If[Length[a]>Length[b],False,OrderedQ[{a,b}]];
sortm[mon_]:=Module[{ordo},
ordo=Ordering[mon,All,order];
Signature[ordo]mon[[ordo]]
];
sortp[p_]:=(p/.aa_NonCommutativeMultiply:>sortm[aa]);
killm[m_]:=If[DuplicateFreeQ[m],m,0];
killp[pp_]:=(pp/.aa_NonCommutativeMultiply:>killm[aa]);
dert[n_,p_]:=sortp@killp@expand@der[n,p];
dimHt[ppp_,ddd_,DD_]:=
Module[{tba,tba1,tpba,tpba1,rul1,dimim,ltpba},
tba=Tbasis[ddd,DD];
tba1=Tbasis[ddd-1,DD];
tpba=Tpoly[ppp,ddd,tba];
ltpba=Length[tpba];
tpba1=Tpoly[ppp,ddd-1,tba1];
rul1=Thread[tpba->Thread[V@Range[ltpba]]];
ima=(Flatten@Table[dert[i,#]&/@tpba1,{i,1,DD-1}]/.rul1)/.V[n_]:>UnitVector[ltpba,n];
dimim=If[ima=={},0,MatrixRank[ima]];
{ltpba,dimim,ltpba-dimim}
];
dimH[ppp_,ddd_,DD_]:=Which[(ppp==0||ppp==1),If[ddd==0,1,0],ppp≥2&&ddd==0,0,True,dimHt[ppp,ddd,DD][[3]]];

D=2

Table[fdimH[p,d,2]=dimH[p,d,2],{p,0,5},{d,0,10}]//MatrixForm

Table[fdimH[p,d,2]+fdimH[p+1,d,2],{p,0,4},{d,0,10}]//MatrixForm

D=3

Table[fdimH[p,d,3]=dimH[p,d,3],{p,0,5},{d,0,10}]//MatrixForm

Table[fdimH[p,d,3]+fdimH[p+1,d,3],{p,0,4},{d,0,10}]//MatrixForm

D=4

Table[fdimH[p,d,4]=dimH[p,d,4],{p,0,4},{d,6,6}]//MatrixForm

Table[fdimH[p,d,4],{p,0,4},{d,0,6}]//MatrixForm

Table[fdimH[p,d,4]+fdimH[p+1,d,4],{p,0,3},{d,0,6}]//MatrixForm

p=d+1

Table[dimH[d+1,d,DD],{d,1,5},{DD,2,6}]//MatrixForm