Help:=proc(): print(`gAFt(A,F,t) , Overlap(w,v), FindEq1(F,f,t,w) `): print(`Cgf(F,t)`): end: #all the ways in which a tail of w can be a head of #v, for example Overlap([0,1,0,1],[1,0,1,0]) should #output {1,3}; Overlap:=proc(w,v) local k,S,Tailsw,Headsv: S:={}: Tailsw:={seq([op(k..nops(w),w)],k=2..nops(w))}: Headsv:={seq([op(1..k,v)],k=1..nops(v)-1)}: map(nops,Tailsw intersect Headsv): end: #The equation for W[f]: the generating function #in t, for those clusters that start out #with the dirty word f FindEq1:=proc(F,f,t,W) local e,g,S,coe,s: e:=W[f]+t^(nops(f)): for g in F do S:=Overlap(f,g): coe:=add(t^(nops(f)-s), s in S): e:=e+coe*W[g]: od: e: end: #Inputs a set of dirty words F, and a variable (symbol t) #outputs the cluster generating function Cgf:=proc(F,t) local var,eq,W,f,var1: var:={seq(W[f], f in F)}: eq:={seq(FindEq1(F,f,t,W), f in F)}: var1:=solve(eq,var): normal(add(subs(var1,v), v in var)): end: #The Goulden-Jacskon Cluster method for an #alphebat A and a set of dirty words F in the variable t gAFt:=proc(A,F,t): normal(1/(1-nops(A)*t-Cgf(F,t))): end: