x := Indeterminate(Integers,"x"); # MAKEPOLY: build poly from candidates makepoly := function(candvector,basemel) local tallypoly, veccount,m; veccount := 1; for m in candvector do if veccount = 1 then tallypoly := Value(UnivariatePolynomial(Integers,basemel),x^m); veccount := 2; else tallypoly := tallypoly+ x^(Position(CoefficientsOfUnivariatePolynomial(tallypoly),0)-1)* Value(UnivariatePolynomial(Integers,basemel),x^m); fi; od; return tallypoly; end; # POLYVEC: returns texture (integer) vector from canon instance polyvec := function(candvector,basemel) return CoefficientsOfUnivariatePolynomial(makepoly(candvector,basemel)); end; # MAKECANVEC: build canonvector which distinguishes membership for each attack makecanvec := function(candvector,basemel) local tallypoly, veccount,m,vecplace; veccount := 1; vecplace := 1; for m in candvector do if veccount = 1 then tallypoly := Value(UnivariatePolynomial(Integers,basemel),x^m); veccount := 2; else tallypoly := tallypoly+ (vecplace* x^(Position(CoefficientsOfUnivariatePolynomial(tallypoly),0)-1)* Value(UnivariatePolynomial(Integers,basemel),x^m)); fi; vecplace := vecplace+1; od; return tallypoly; end; # CANONVEC: returns indexed (integer) vector of tiled canon canonvec := function(candvector,basemel) return CoefficientsOfUnivariatePolynomial(makecanvec(candvector,basemel)); end; # TILINGS: find tiling canons of motive # from 'minmens' to 'maxmens' mensuration # iters per loop tilings := function(motive,minmens,maxmens,iters) local candidates,selected,tempcandid,testvec,n,i,sel,q; selected := []; for q in [minmens..maxmens] do candidates := [[]]; candidates[1][1] := q; for i in [1..iters] do for n in [minmens..maxmens] do tempcandid := ShallowCopy(candidates[1]); tempcandid[Length(tempcandid)+1] := n; testvec := polyvec(tempcandid,motive); if Maximum(testvec) > 1 # never a tiling canon then continue; elif Minimum(testvec) = 1 and Maximum(testvec) = 1 # it's a canon then Add(selected,tempcandid); else Add(candidates,tempcandid); fi; # possible canon od; if Length(candidates) > 0 then Unbind(candidates[1]); candidates := Compacted(candidates); else break; fi; od; od; Sort(selected, function (u,v) return Length(polyvec(u,motive)) < Length(polyvec(v,motive)); end); for sel in selected do Print(sel," Length ",Length(polyvec(sel,motive)),"\n"); Print(canonvec(sel,motive),"\n\n"); od; end;