Help:=proc(): print(`choose1(S,k), Fnk(n,k) `): end: #choose1(S,k): inputs a set S and a non-negative #integer k, and outputs the set of k-element #subsets of S. For example, try: #choose1({1,2,3},2); choose1:=proc(S,k) local fa,S1,T1,T2,t2: option remember: if not type(S,set) then ERROR(`Bad input`): fi: if k=0 then RETURN({{}}): fi: if ( k>nops(S) or k<0 or not type(k,integer) ) then RETURN({}): fi: fa:=S[1]: S1:=S minus {fa}: T1:=choose1(S1,k): T2:=choose1(S1,k-1): T1 union { seq(t2 union {fa}, t2 in T2) }: end: ##Fnk(n,k): the set of lists of 1'2 and 2's #of length k, that sum to n #For example: #Fnk(5,3)={[1,2,2],[2,1,2],[2,2,1]} . Fnk:=proc(n,k) local a, F1,F2 : option remember: if n<0 or k<0 then RETURN({}): fi: if n=0 then if k=0 then RETURN({[]}): else RETURN({}): fi: fi: ###The case where the last element is 1 F1:=Fnk(n-1,k-1): ###The case where the last element is 2 F2:=Fnk(n-2,k-1): {seq([op(f1),1],f1 in F1), seq([op(f2),2],f2 in F2)}: end: