Help:=proc(): print(`fAFt(A,F,t) , FindEq(A,F,T,a,W) `): print(`newT(A,F,T,a) , FindEq(A,F,T,t,W), SeqC(A,F,N)`): end: #newT(A,F,T,a): inputs an alphabet A, a set #of global restrctions F, a set of starting #restrictions T, and a letter a (a in A) #and ouputs the set of starting restrictions #that a word in A should have such that if #you stick a at the very beginning you neither #get anything in F, nor anything in T newT:=proc(A,F,T,a) local T1,f: T1:={}: for f in F do if f[1]=a then T1:=T1 union {[op(2..nops(f),f)]}: fi: od: for f in T do if f[1]=a then T1:=T1 union {[op(2..nops(f),f)]}: fi: od: T1: end: #FindEq(A,F,T,t,W): inputs an alphabet A, a set of #global restrictions F, another set of restrictions #T (that correspond to not starting with any word of T) #and outputs the equation for W[T] as a linear combination #of w[T']-s for various different T', followed by the #set of T' used FindEq:=proc(A,F,T,t,W) local aek,a,T1,S: S:={}: aek:=W[T]-1: for a in A do T1:=newT(A,F,T,a): if not member([],T1) then aek:=aek-t*W[T1]: S:=S union {T1}: fi: od: aek,S: end: #fAFt(A,F,t): Inputs a set A (the alphabet) and a set #F of words in the alphabet A, and a variable t, #and outputs the formal power series (that will turn out) #to be a rational function of t, whose (Maclaurin) coeff. #of t^n equals exactly the number of words in the letters #A that do not have as FACTORS (i.e. consecutive subword) #any of the "curse words" of F. For example #f({1,2},{[1,1]},t) should give the (ordinary) generating #function for the sequence a[n]:=number of n-letter words #in {1,2} that never have two 1's next to each other fAFt:=proc(A,F,t) local eq,var,W,StillToDo,guest,brian,AlreadyDone: eq:={}: var:={}: StillToDo:={{}}: AlreadyDone:={}: while StillToDo<>{} do guest:=StillToDo[1]: var:=var union {W[guest]}: brian:=FindEq(A,F,guest,t,W): eq:=eq union {brian[1]}: AlreadyDone:=AlreadyDone union {guest}: StillToDo:=StillToDo union brian[2] minus AlreadyDone: od: normal(subs(solve(eq,var), W[{}])): end: #SeqC(A,F,N): The first N terms (n=1...N) #for the seq. number of n-letter words in the #alphabet A, avoiding (as factors) the "dirty" words #in the set of words F. For example, try: #SeqC({H,T},{[H,H,H],[T,T,T]},10); SeqC:=proc(A,F,N) local f,t,n: f:=fAFt(A,F,t): f:=taylor(f,t=0,N+1): [ seq( coeff(f,t,n),n=1..N)]: end: