#C6.txt, Sept. 26, 2016 Help:=proc(): print(`GJz( A, BadW,z,t), ArielRc(A,Pr,BadW,t), ArielRu(A,Pr,BadW,n) ` ) : print(`ArielR(A,Pr,BadW,t)`): end: #stuff from C5.txt #C5.txt, Sept. 22, 2016 (Math640 (Fall 2016), Rutgers University) #Goulden-Jackson Help5:=proc(): print(` GJ(A,BadW,t), Clu(A,BadW,t) `): end: #GJ(A,BadW,t): inputs a finite alphabet A, and a set of words in A , "the bad words" #and a variable t, outputs a rational function in t whose Maclaurin coef. of t^n #is the number of n-letter words in A AVOIDING (as consecutive subwords) ANY #bad words GJ:=proc(A,BadW,t) local C: C:=Clu(A,BadW,t): normal(1/(1- t*nops(A)-C)): end: #Clu(A,BadW,t): inputs a finite alphabet A, and a set of words in A , "the bad words" #and a variable t, outputs the cluster generating function Clu:=proc(A,BadW,t) local eq,var,x,w,v,eq1,i: eq:={}: var:={}: for w in BadW do var:=var union {x[w]}: eq1:=x[w]- (t^nops(w))*(-1): for v in BadW do for i from 1 to min(nops(v)-1,nops(w)-1) do if v[nops(v)-i+1..nops(v)]=w[1..i] then eq1:=eq1-t^(nops(w)-i)*(-1)*x[v]: fi: od: od: eq:=eq union {eq1}: od: var:=solve(eq,var): normal(add(subs(var,x[w]),w in BadW)): end: ###new stuff #GJz(A,BadW,z,t): inputs a finite alphabet A, and a set of words in A , "the bad words" #and a variable t, outputs a rational function in t whose Maclaurin coef. of t^n #is the weight-enumerator #according to the weight #mul(z[w[i]],i=1..nops(w)) # n-letter words in A AVOIDING (as consecutive subwords) ANY #bad words GJz:=proc(A,BadW,z,t) local C,a: C:=Cluz(A,BadW,z,t): normal(1/(1- t*(add(z[a],a in A))- C)): end: #Cluz(A,BadW,z,t): inputs a finite alphabet A, and a set of words in A , "the bad words" #and a variable t, outputs the cluster generating function Cluz:=proc(A,BadW,z,t) local eq,var,x,w,v,eq1,i: eq:={}: var:={}: for w in BadW do var:=var union {x[w]}: eq1:=x[w]- (t^nops(w))*mul(z[w[i1]],i1=1..nops(w))*(-1): for v in BadW do for i from 1 to min(nops(v)-1,nops(w)-1) do if v[nops(v)-i+1..nops(v)]=w[1..i] then eq1:=eq1-t^(nops(w)-i)*mul(z[w[i1]],i1=i+1..nops(w))*(-1)*x[v]: fi: od: od: eq:=eq union {eq1}: od: var:=solve(eq,var): normal(add(subs(var,x[w]),w in BadW)): end: #ArielRc(A,Pr,BadW,t): Inspired by pp. 74 ff of Ariel Rubinstein's masterpiece #"Economic Fables" (free download, highly recommended), P.S. Ariel Rubinstein #was Dr. Z.'s army buddy #Inputs a LIST of alpbhabet (think of any number-faced die) with a prob. dist. #Pr (prob. of the die lending on A[i] os Pr[i]), a set of words in A #and outputs a rational generating function whose coeff. of t^n is the #Exact prob. of rolling the die n times and getting at least one occurence #of BadW (thereby winning 25 dollars) ArielRc:=proc(A,Pr,BadW,t) local f,z,i: f:=GJz(A,BadW,z,t): f:=subs({ seq(z[A[i]]=Pr[i],i=1..nops(A))}, f): normal(1/(1-t)-f): end: #ArielRu(A,Pr,BadW,n): the prob. of getting at least one occurence of member of BadW #upon rolling the A-die (with loaded Pr) n times ArielRu:=proc(A,Pr,BadW,n) local t,f: f:=ArielRc(A,Pr,BadW,t): f:=taylor(f,t=0,n+1): evalf(coeff(f,t,n)): end: #ArielR(A,Pr,BadW,t): Inspired by pp. 74 ff of Ariel Rubinstein's masterpiece #"Economic Fables" (free download, highly recommended), P.S. Ariel Rubinstein #was Dr. Z.'s army buddy #Inputs a LIST of alpbhabet (think of any number-faced die) with a prob. dist. #Pr (prob. of the die lending on A[i] os Pr[i]), a set of words in A #and outputs a rational generating function whose coeff. of t^n is the #Exact prob. of rolling the die n times and getting NO occurence #of BadW (thereby winning 25 dollars) ArielR:=proc(A,Pr,BadW,t) local f,z,i: f:=GJz(A,BadW,z,t): f:=subs({ seq(z[A[i]]=Pr[i],i=1..nops(A))}, f): f:=normal(f): end: