#C2.txt, Sept. 12, Help:=proc(): print(` Comp(n,S), NuC(n,S), SeqNuC(N,S), CompC(n,C,m), SeqNuCompC(N,C), GFS(S,t), NuCompC(n,C,m), SeqNuCompC(N,C) `): end: #Comp(n,S): inputs a non-neg. integer n, and a finite set of POS. integers #and outputs the SET of lists whose entries are from S and that add-up to n Comp:=proc(n,S) local T, s,T1,t1: option remember: if n<0 then RETURN({}): fi: if n=0 then RETURN({[]}): fi: T:={}: for s in S do T1:=Comp(n-s,S): T:=T union {seq( [ op(t1), s], t1 in T1)}: od: T: end: #NuC(n,S): inputs a non-neg. integer n, and a finite set of POS. integers #and outputs the NUMBER of lists whose entries are from S and that add-up to n NuC:=proc(n,S) local T, s,T1,t1: option remember: if n<0 then RETURN(0): fi: if n=0 then RETURN(1): fi: add(NuC(n-s,S),s in S): end: SeqNuC:=proc(N,S) local n: [seq(NuC(n,S),n=0..N)]: end: #GFS(S,t): inputs a set of positive integers and a variable name t, outputs #a rational function of t whose Maclaurin expansion is such that the coeff. #of t^n is NuC(n,S) weight(word):=t^sum(word) GFS:=proc(S,t) #T=[] OR TxS #f(t)=1+f(t)*add(t^s,s in S) 1/(1-add(t^s, s in S)): end: #CompC(n,C,m): inputs a non-neg. integer n, and a condition C given as a funcion #and outputs the SET of lists whose entries satisfy the same condition phrased in terms of the #symbol m, and add-up to n. Using an idea of Andrew Lohr #For example #CompC(6, m->evalb(m mod 2=1)); CompC:=proc(n,C) local s,T1,T: option remember: if n<0 then RETURN({}): fi: if n=0 then RETURN({[]}): fi: T:={}: for s from 1 to n do if C(s) then T1:= CompC(n-s,C): T:=T union {seq( [ op(t1), s], t1 in T1)}: fi: od: T: end: #NuCompC(n,C,m): inputs a non-neg. integer n, and a condition C given as a funcion #and outputs the NUMBER of lists whose entries satisfy the same condition phrased in terms of the #symbol m, and add-up to n. Using an idea of Andrew Lohr #For example #NuCompC(6, m->evalb(m mod 2=1)); NuCompC:=proc(n,C) local s,T1,T: option remember: if n<0 then RETURN(0): fi: if n=0 then RETURN(1): fi: T:=0: for s from 1 to n do if C(s) then T1:= NuCompC(n-s,C): T:=T+T1: fi: od: T: end: #SeqNuCompC(N,C): the first N+1 terms inthe sequence NuComp(n,C) SeqNuCompC:=proc(N,C) local n: [seq(NuCompC(n,C), n=0..N)]: end: