with(combinat); pet_cycleind_symm := proc(n) option remember; if n=0 then return 1; fi; expand(1/n* add(a[l]*pet_cycleind_symm(n-l), l=1..n)); end; pet_varinto_cind := proc(poly, ind) local subs1, subs2, polyvars, indvars, v, pot, res; res := ind; polyvars := indets(poly); indvars := indets(ind); for v in indvars do pot := op(1, v); subs1 := [seq(polyvars[k]=polyvars[k]^pot, k=1..nops(polyvars))]; subs2 := [v=subs(subs1, poly)]; res := subs(subs2, res); od; res; end; pet_cycleind_comp := proc(idxtrg, idx) local varstrg, vars, vt, sbstrg, sbs, len; varstrg := indets(idxtrg); vars := indets(idx); sbstrg := []; for vt in varstrg do len := op(1, vt); sbs := [seq(v = a[op(1, v)*len], v in vars)]; sbstrg := [op(sbstrg), a[len] = subs(sbs, idx)]; od; expand(subs(sbstrg, idxtrg)); end; pet_cycleind_mset := proc(msetlst) option remember; local mset, res, ent, idxtrg, idx; mset := convert(msetlst, `multiset`); res := 1; for ent in mset do idx := pet_cycleind_symm(ent[1]); idxtrg := pet_cycleind_symm(ent[2]); res := res * pet_cycleind_comp(idxtrg, idx); od; expand(res); end; GENF := proc(src, msetlst) local vars, srcp, res, gf, term; vars := add(A[q], q=1..nops(src)); srcp := mul(A[q]^src[q], q=1..nops(src)); gf := expand(pet_varinto_cind (vars, pet_cycleind_mset(msetlst))); if not type(gf, `+`) then gf := [gf]; fi; res := 0; for term in gf do if type(srcp/term, `polynom`) then res := res + term; fi; od; res; end; OEIS := proc(mx) local n, part, res; res := []; for n to mx do part := firstpart(n); while type(part, `list`) do res := [op(res), lcoeff(GENF(part, part))]; part := nextpart(part); od; od; op(res); end;