# Compute the product of two sets in a group ProdSets := function ( A, B ) local AB, a, b; AB := []; for a in A do for b in B do AddSet(AB, a*b); od; od; return AB; end; # Compute a factorization of a group into susbets FactorizationIntoSubsets:=function(G, H, K, a) local BuildKnuthMat, Knuth, b, aq, bq, iH, iK, RHT, LK, LKT, D, coset, Els, Dict, M, Combs, FirstKnuthMat, Solution, Way, lvl, PartSols, KnuthMat, KnuthArray, A, B, i, j, k, s, colnum, x, comb, h; BuildKnuthMat:=function(M, aq, bq, comb) #this function builds matrix of 0s and 1s for Knuth's algorithm X local Sets, CurSet, FirstKnuthMat, l, x; Sets:=[]; #assigning collection of sets for i in [1..Size(M[1])] do #filling the collection with sets CurSet:=[]; for j in [1..aq] do Add(CurSet, M[comb[j]][i]); od; Add(Sets, CurSet); od; FirstKnuthMat:=NullMat(aq*bq+1, Size(Sets)); #assigning matrix of 0s and 1s with additional column for rows numeration, where the first index is column and the second one is row FirstKnuthMat[1]:=[1..Size(Sets)]; #numeration of rows for i in [1..Size(Sets)] do #filling the matrix with 1s for j in Sets[i] do FirstKnuthMat[j+1][i]:=1; od; od; for i in [1..Size(Sets)] do #removing rows obtained from lists with repeating elements that are not sets if Size(SSortedList(Sets[i]))Representative(LK[x])); D:=DoubleCosets(G,H,K); M:=NullMat(iH,iK); Els := Elements(G);; Dict := NewDictionary(Els[1], true);; k := 1;; for coset in D do for x in Elements(coset) do AddDictionary(Dict, x, k);; od; k := k+1;; od; for i in [1..iH] do for j in [1..iK] do M[i][j]:=LookupDictionary(Dict, RHT[i]*LKT[j]); od; od; Print("Matrix of double cosets was built."); Combs:=IteratorOfCombinations([1..iH], aq); for comb in Combs do FirstKnuthMat:=BuildKnuthMat(M, aq, bq, comb); Solution:=0; Way:=[1]; lvl:=1; PartSols:=[]; while Solution=0 do if lvl=1 then KnuthMat:=StructuralCopy(FirstKnuthMat); PartSols:=[]; fi; KnuthArray:=Knuth(KnuthMat, Way, lvl, PartSols); KnuthMat:=KnuthArray[1]; Way:=KnuthArray[2]; lvl:=KnuthArray[3]; Solution:=KnuthArray[4]; PartSols:=KnuthArray[5]; od; if Solution=1 then break; fi; od; A:=[]; B:=[]; for i in comb do for h in H do AddSet(A,h*RHT[i]); od; od; for j in PartSols do for k in K do AddSet(B,LKT[j]*k); od; od; return [A, B]; end;