t[N|M,V_]:=V
t[V_,N|M]:=V

t[X,Xb]=N+V2;
t[V2,X]=X+V3;
t[V3,Xb]=V2+P+Q;
t[P,X]=V3+W;
t[Q,X]=V3+Z;
t[W,Xb]=P+S;
t[Z,Xb]=Q+S2;
t[S,X]=W;
t[S2,X]=Z;
t[Xb,X]=A+M;
t[A,Xb]=Xb+D;
t[D,X]=A+B+C;
t[C,Xb]=D;
t[B,Xb]=D+E+F;
t[E,X]=B;
t[F,X]=B;

NmodN={N,V2,P,Q,S,S2};
NmodM={X,V3,W,Z};
MmodM={M,A,B,C};
MmodN={Xb,D,E,F};

Nmod=NmodN~Join~NmodM;
Mmod=MmodM~Join~MmodN;
modN=NmodN~Join~MmodN;
modM=MmodM~Join~NmodM;

modules=NmodN~Join~NmodM~Join~MmodN~Join~MmodM;

d[N|M]=1;
d[Z_Plus]:=d/@Z
d[α_Integer V_]:=α d[V]
d[t[V1_,V2_]]:=d[V1]d[V2]

unknownTensorProducts:=Cases[Flatten[Outer[t,modN,Nmod]]~Join~Flatten[Outer[t,modM,Mmod]],_t]

unknownTensorProducts

dimensionEquations={d[X]==d[Xb]}~Join~Cases[DownValues[t],(p_HoldPattern:>v_)/;FreeQ[p,Blank]:>{Hold@@p,v}]/.{Hold[t[V1_,V2_]],V3_}:>d[V1]d[V2]==d[V3]

dimensions=Together[Select[(d/@modules)/.Solve[dimensionEquations],And@@(Positive/@#)&][[1]]]

Chop[N[dimensions]]

(d[#[[1]]]=#[[2]])&/@Transpose[{modules,dimensions}];

d[P]

unknownTensorProducts

associativityEquation[A_,B_,C_]:=Simplify[t[t[A,B],C]==t[A,t[B,C]]]

t[α_Integer X_,Z_]:=α t[X,Z]
t[X_, α_Integer Z_]:=α t[X,Z]

t[Z_Plus,X_]:=t[#,X]&/@Z
t[X_,Z_Plus]:=t[X,#]&/@Z

associativityEquations:=Union[associativityEquation@@#&/@(Flatten[Outer[List,modN,NmodN,Nmod],2]~Join~Flatten[Outer[List,modN,NmodM,Mmod],2]~Join~Flatten[Outer[List,modM,MmodN,Nmod],2]~Join~Flatten[Outer[List,modM,MmodM,Mmod],2])]

Select[associativityEquations,Count[#,_t,∞]==1&]

Select[associativityEquations,Count[#,_t,∞]==1&]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]=V3),(V3_==t[V1_,V2_]):>(t[V1,V2]=V3)};

Select[associativityEquations,Count[#,_t,∞]==1&]

Select[associativityEquations,Count[#,_t,∞]==1&]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]=V3),(V3_==t[V1_,V2_]):>(t[V1,V2]=V3)};

Select[associativityEquations,Count[#,_t,∞]==1&]

Cases[associativityEquations,HoldPattern[_t+_t==2x_]|HoldPattern[2x_==_t+_t]]

t[Xb,W]=B;
t[Xb,Z]=B;
t[C,E]=D;
t[C,F]=D;

Select[associativityEquations,Count[#,_t,∞]==1&]

Select[associativityEquations,Count[#,_t,∞]==1&]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]=V3),(V3_==t[V1_,V2_]):>(t[V1,V2]=V3)};

Select[associativityEquations,Count[#,_t,∞]==1&]

Select[associativityEquations,Count[#,_t,∞]==1&]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]=V3),(V3_==t[V1_,V2_]):>(t[V1,V2]=V3)};

Select[associativityEquations,Count[#,_t,∞]==1&]

Select[associativityEquations,Count[#,_t,∞]==1&]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]=V3),(V3_==t[V1_,V2_]):>(t[V1,V2]=V3)};

Select[associativityEquations,Count[#,_t,∞]==1&]

Select[associativityEquations,Count[#,_t,∞]==1&]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]=V3),(V3_==t[V1_,V2_]):>(t[V1,V2]=V3)};

Select[associativityEquations,Count[#,_t,∞]==1&]

Select[associativityEquations,Count[#,_t,∞]==1&]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]=V3),(V3_==t[V1_,V2_]):>(t[V1,V2]=V3)};

Select[associativityEquations,Count[#,_t,∞]==1&]

Select[associativityEquations,Count[#,_t,∞]==1&]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]=V3),(V3_==t[V1_,V2_]):>(t[V1,V2]=V3)};

Select[associativityEquations,Count[#,_t,∞]==1&]

Select[associativityEquations,Count[#,_t,∞]==1&]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]=V3),(V3_==t[V1_,V2_]):>(t[V1,V2]=V3)};

Select[associativityEquations,Count[#,_t,∞]==1&]

Cases[associativityEquations,(t[U_,V_]/;FreeQ[{U,V},t])==X_Plus]

Cases[associativityEquations,X_Plus==(t[U_,V_]/;FreeQ[{U,V},t])]

Cases[associativityEquations,(X_Plus==(t[U_,V_]/;FreeQ[{U,V},t])):>(t[U,V]=X)]

Select[associativityEquations,Count[#,_t,∞]==1&]

Select[associativityEquations,Count[#,_t,∞]==1&]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]=V3),(V3_==t[V1_,V2_]):>(t[V1,V2]=V3)};

Select[associativityEquations,Count[#,_t,∞]==1&]

Select[associativityEquations,Count[#,_t,∞]==1&]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]=V3),(V3_==t[V1_,V2_]):>(t[V1,V2]=V3)};

Select[associativityEquations,Count[#,_t,∞]==1&]

Cases[associativityEquations,(t[U_,V_]/;FreeQ[{U,V},t])==X_Plus]

Cases[associativityEquations,X_Plus==(t[U_,V_]/;FreeQ[{U,V},t])]

Cases[associativityEquations,(X_Plus==(t[U_,V_]/;FreeQ[{U,V},t])):>(t[U,V]=X)]

Select[associativityEquations,Count[#,_t,∞]==1&]

Cases[associativityEquations,HoldPattern[_t+_t==2x_]|HoldPattern[2x_==_t+_t]]

N[d/@{D,E,F,Xb,t[D,P],t[D,Q]}]

Cases[associativityEquations,(t[U_,V_]+t[Z_,W_])==(X_+Y_)]

ae=Cases[associativityEquations,(X_/;FreeQ[X,t])==t[U_,V_]+t[Z_,W_]]

possibleSplittings[(X_/;FreeQ[X,t])==t[U_,V_]+t[Z_,W_]]:=Module[{coefficients},
coefficients=Coefficient[X,#]&/@modules;
Cases[Flatten[Outer[List,Sequence@@(Range[0,#]&/@coefficients)],Length[modules]-1],(c_/;c.dimensions==d[t[U,V]]):>{t[U,V]->c.modules,t[Z,W]->(coefficients-c).modules}]
]

possibleSplittings[D+E+F==t[Xb,P]+t[Xb,S]]

possibleSplittings[N+2 P+2 Q+S+2 V2==t[Q,P]+t[Q,Q]]

(* post hoc, changed ==1 to ≤1 *)

brokenRulesQ[rules_]:=MemberQ[Simplify[Select[associativityEquations//.rules,Count[#,_t,∞]≤1&]],(X_/;MemberQ[modules,X])+Y_==(Z_/;FreeQ[Z,t|X])]

brokenRulesQ[{t[Xb,P]->D+F,t[Xb,S]->E}]

brokenRulesQ[{t[Q,P]->P+2 Q+S,t[Q,Q]->N+P+2 V2}]

possibleSplittings2[(X_/;FreeQ[X,t])==t[U_,V_]+t[Z_,W_]]:=DeleteCases[possibleSplittings[X==t[U,V]+t[Z,W]],rules_/;brokenRulesQ[rules]]

lookForConsequences[rules_]:=Cases[Simplify[Select[associativityEquations//.rules,Count[#,_t,∞]==1&]]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]->V3),(V3_==t[V1_,V2_]):>(t[V1,V2]->V3)},_Rule]

lookForConsequences[{t[Q,P]->P+2 Q+S,t[Q,Q]->N+P+2 V2}]

lookForAllConsequences[rules_]:=FixedPoint[Union[#~Join~lookForConsequences[#]]&,rules]

lookForAllConsequences[{t[Xb,P]->D+E,t[Xb,S]->F}]

possibleSplittings3[(X_/;FreeQ[X,t])==t[U_,V_]+t[Z_,W_]]:=DeleteCases[possibleSplittings[X==t[U,V]+t[Z,W]],rules_/;brokenRulesQ[lookForAllConsequences[rules]]]

possibleSplittings2[D+E+F==t[Xb,P]+t[Xb,S]]

possibleSplittings3[D+E+F==t[Xb,P]+t[Xb,S]]

possibleSplittings[N+2 P+2 Q+S+2 V2==t[Q,P]+t[Q,Q]]

possibleSplittings2[N+2 P+2 Q+S+2 V2==t[Q,P]+t[Q,Q]]

possibleSplittings3[N+2 P+2 Q+S+2 V2==t[Q,P]+t[Q,Q]]

ps=possibleSplittings3/@ae

Cases[ps,r_/;Length[r]==1]

t[V2,Q]=P+Q+S+V2;
t[V2,S2]=P;
t[D,P]=2D+E+F+Xb;
t[D,S]=D;
t[D,Q]=2D+E+F+Xb;
t[D,S2]=D;

Select[associativityEquations,Count[#,_t,∞]==1&]

Select[associativityEquations,Count[#,_t,∞]==1&]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]=V3),(V3_==t[V1_,V2_]):>(t[V1,V2]=V3)};

Select[associativityEquations,Count[#,_t,∞]==1&]

Select[associativityEquations,Count[#,_t,∞]==1&]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]=V3),(V3_==t[V1_,V2_]):>(t[V1,V2]=V3)};

Select[associativityEquations,Count[#,_t,∞]==1&]

Cases[associativityEquations,HoldPattern[_t+_t==2x_]|HoldPattern[2x_==_t+_t]]

Cases[associativityEquations,(t[U_,V_]/;FreeQ[{U,V},t])==X_Plus]

Cases[associativityEquations,X_Plus==(t[U_,V_]/;FreeQ[{U,V},t])]

Cases[associativityEquations,(X_Plus==(t[U_,V_]/;FreeQ[{U,V},t])):>(t[U,V]=X)]

Select[associativityEquations,Count[#,_t,∞]==1&]

Cases[associativityEquations,HoldPattern[_t+_t==2x_]|HoldPattern[2x_==_t+_t]]

Cases[associativityEquations,(t[U_,V_]/;FreeQ[{U,V},t])==X_Plus]

Cases[associativityEquations,X_Plus==(t[U_,V_]/;FreeQ[{U,V},t])]

Cases[associativityEquations,(t[U_,V_]+t[Z_,W_])==(X_+Y_)]

ae=Cases[associativityEquations,(X_/;FreeQ[X,t])==t[U_,V_]+t[Z_,W_]]

ps=possibleSplittings3/@ae

Cases[ps,r_/;Length[r]==1]

(*Now we're really stuck!*)

t[S,S]=S2;
t[S2,S2]=S;
t[S,S2]=N;
t[S2,S]=N;

Select[associativityEquations,Count[#,_t,∞]==1&]

Select[associativityEquations,Count[#,_t,∞]==1&]/.{(t[V1_,V2_]==V3_):>(t[V1,V2]=V3),(V3_==t[V1_,V2_]):>(t[V1,V2]=V3)};

Select[associativityEquations,Count[#,_t,∞]==1&]

Cases[associativityEquations,HoldPattern[_t+_t==2x_]|HoldPattern[2x_==_t+_t]]

Cases[associativityEquations,(t[U_,V_]/;FreeQ[{U,V},t])==X_Plus]

Cases[associativityEquations,X_Plus==(t[U_,V_]/;FreeQ[{U,V},t])]

Cases[associativityEquations,(t[U_,V_]+t[Z_,W_])==(X_+Y_)]

ae=Cases[associativityEquations,(X_/;FreeQ[X,t])==t[U_,V_]+t[Z_,W_]]

ps=possibleSplittings3/@ae

ps//TableForm

allPossibilities=DeleteCases[Flatten[Outer[Join,Sequence@@ps,1],Length[ps]-1],{___,x_->y_,___,x_->z_,___}/;(y=!=z)]

Length[%]

Select[Take[allPossibilities,{1,10}],(!brokenRulesQ[#])&]

Select[Take[allPossibilities,{11,100}],(!brokenRulesQ[#])&]

Select[Take[allPossibilities,{101,300}],(!brokenRulesQ[#])&]

Select[Take[allPossibilities,{301,600}],(!brokenRulesQ[#])&]

Select[Take[allPossibilities,{601,1000}],(!brokenRulesQ[#])&]

Select[Take[allPossibilities,{1001,1024}],(!brokenRulesQ[#])&]

rule1={t[Xb,S]->F,t[Xb,S2]->E,t[E,W]->A+M,t[E,Z]->B,t[E,W]->A+M,t[F,W]->B,t[E,Z]->B,t[F,Z]->A+M,t[F,W]->B,t[F,Z]->A+M,t[X,E]->P+S2,t[X,F]->Q+S,t[Z,E]->S+V2,t[Z,F]->N+P,t[W,E]->N+Q,t[W,F]->S2+V2,t[F,S]->E,t[F,S2]->Xb,t[E,S]->Xb,t[E,S2]->F};

rule2={t[Xb,S]->E,t[Xb,S2]->F,t[E,W]->B,t[E,Z]->A+M,t[E,W]->B,t[F,W]->A+M,t[E,Z]->A+M,t[F,Z]->B,t[F,W]->A+M,t[F,Z]->B,t[X,E]->Q+S,t[X,F]->P+S2,t[Z,E]->N+P,t[Z,F]->S+V2,t[W,E]->S2+V2,t[W,F]->N+Q,t[F,S]->Xb,t[F,S2]->E,t[E,S]->F,t[E,S2]->Xb};

Sort[(rule2/.{E->F,F->E})]-Sort[rule1]

Union[Simplify[associativityEquations//.rule1]]

Union[Simplify[associativityEquations//.rule2]]

unknownTensorProducts

Outer[t,modN,Nmod]/.rule1 //TableForm

Outer[t,modM,Mmod]/.rule1 //TableForm

Outer[t,modN,Nmod]/.rule2//TableForm

Outer[t,modM,Mmod]/.rule2 //TableForm

rule1/.(t[U_,V_]->W_):>(t[U,V]=W)

Clear[dual]

dual[N]=N;
dual[M]=M;
dual[X]=Xb;
dual[Xb]=X;

dual[α_Integer Z_]:=α dual[Z]
dual[Z_Plus]:=dual/@Z

dualEquation[U_,V_]:=(dual[t[U,V]]==t[dual[V],dual[U]])

dualEquation[X,Xb]

dualEquations:=Union[Simplify[Flatten[Outer[dualEquation,modN,Nmod]]~Join~Flatten[Outer[dualEquation,modM,Mmod]]]]

Cases[dualEquations,eq_/;(Count[eq,_dual,∞]==1)]

dual[A]=A;
dual[V2]=V2;

Cases[dualEquations,eq_/;(Count[eq,_dual,∞]==1)]

dual[V3]=D;
dual[D]=V3;

Cases[dualEquations,eq_/;(Count[eq,_dual,∞]==1)]

dual[S]=S2;
dual[S2]=S;

Cases[dualEquations,eq_/;(Count[eq,_dual,∞]==1)]

dual[Z]=F;
dual[P]=P;
dual[Q]=Q;
dual[F]=Z;
dual[W]=E;

Cases[dualEquations,eq_/;(Count[eq,_dual,∞]==1)]

dual[B]=B;

Cases[dualEquations,eq_/;(Count[eq,_dual,∞]==1)]

dual[C]=C;
dual[E]=W;

Cases[dualEquations,eq_/;(Count[eq,_dual,∞]==1)]

s[N]=N;
s[V2]=V2;
s[P]=Q;
s[Q]=P;
s[S]=S;
s[S2]=S2;

s[Z_Plus]:=s/@Z

Flatten[Outer[List,NmodN,NmodN],1]

t[#[[1]],#[[2]]]-t[#[[2]],#[[1]]]&/@Flatten[Outer[List,NmodN,NmodN],1]

t[#[[1]],#[[2]]]-t[s[#[[2]]],s[#[[1]]]]&/@Flatten[Outer[List,NmodN,NmodN],1]

t[#[[1]],#[[2]]]-s[t[#[[2]],#[[1]]]]&/@Flatten[Outer[List,NmodN,NmodN],1]

t[#[[1]],#[[2]]]-s[t[s[#[[2]]],s[#[[1]]]]]&/@Flatten[Outer[List,NmodN,NmodN],1]

s[α_Integer Z_]:=α s[Z]

s[s[U_]]:=U

s[X]=Xb;
s[Xb]=X;

s[D]=V3;
s[V3]=D;

s[F]=W;
s[W]=F;
s[E]=Z;
s[Z]=E;

s[A]=A;
s[B]=B;
s[C]=C;
s[M]=M;

t[#[[1]],#[[2]]]-s[t[s[#[[2]]],s[#[[1]]]]]&/@Flatten[Outer[List,modN,Nmod],1]

s[P]

modules

dual/@modules

dual[P]=P;
dual[Q]=Q;

dualEquations

fundamentalSums=Transpose[{IdentityMatrix[Length[modules]],dimensions}]

variables=i/@Range[Length[modules]]

Clear[allSums]

allSums[max_Integer]:=allSums[max]=Module[{variables,iterators},
variables=i/@Range[Length[modules]];
iterators=Table[{i[j],0,Floor[((N[max]-Sum[i[k]d[modules[[k]]],{k,1,j-1}])/(d[modules[[j]]]))]},{j,1,Length[modules]}];
Flatten[Table[{variables,variables.dimensions},Evaluate[Sequence@@iterators]],Length[modules]-1]
]

allSums[4]

Clear[possibleSums]
possibleSums[x_]:=possibleSums[x]=Cases[allSums[Ceiling[x]],({s_List,d_}/;Simplify[d-x]==0):>s]

unknownTensorProducts

Ceiling/@d/@unknownTensorProducts

allSums/@Range[5];

Cases[unknownTensorProducts,t[W|Z,_]|t[_,W|Z]]

Length/@possibleSums/@d/@unknownTensorProducts

Length/@possibleSums/@d/@Cases[unknownTensorProducts,t[W|Z,_]|t[_,W|Z]]

Times@@%

possibleRules[t[U_,V_]]:={t[U,V]->#}&/@(possibleSums[d[t[U,V]]].modules)

possibleRules[t[F,W]]

lookForAllConsequences[{t[F,W]->B}]

brokenRulesQ[lookForAllConsequences[{t[F,W]->B}]]

possibleRules2[X_]:=DeleteCases[possibleRules[X],rules_/;brokenRulesQ[lookForAllConsequences[rules]]]

Length[possibleRules[t[Z,E]]]

possibleRules2/@unknownTensorProducts

Length/@%

unknownTensorProducts

possibleRules3[X__]:=DeleteCases[Flatten[Outer[Join,Sequence@@(possibleRules2/@{X}),1],Length[{X}]-1],rules_/;brokenRulesQ[lookForAllConsequences[rules]]]

Length[possibleRules2[#]]&/@{t[P,S],t[P,S2],t[Q,S],t[Q,S2]}

possibleRules3[t[P,S],t[P,S2],t[Q,S],t[Q,S2]]

Length[%]