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_flatten_termA := proc(varp) local terml, d, cf, v; terml := []; cf := varp; for v in indets(varp) do d := degree(varp, v); terml := [op(terml), [op(1,v), d]]; cf := cf/v^d; od; [cf, terml]; end; pet_cycleind_mset := proc(msdata) local msrep, res, cycs, num, slist; msrep := convert(msdata, `multiset`); res := 1; for cycs in msrep do num := op(2, cycs); slist := [seq(a[q]=a[q]^op(1, cycs), q=1..num)]; res := res *subs(slist, pet_cycleind_symm(num)); od; expand(res); end; set_seq := proc(n) option remember; local part, idx_slots, idx_syms, res, a, b, flat_a, flat_b, cyc_a, cyc_b, len_a, len_b, p, q; if n > 1 then idx_syms := pet_cycleind_symm(n); else idx_syms := [a[1]]; fi; res := 0; for part in partition(n) do idx_slots := pet_cycleind_mset(part); if not type(idx_slots, `+`) then idx_slots := [idx_slots]; fi; for a in idx_slots do flat_a := pet_flatten_termA(a); for b in idx_syms do flat_b := pet_flatten_termA(b); p := 1; for cyc_a in flat_a[2] do len_a := op(1, cyc_a); q := 0; for cyc_b in flat_b[2] do len_b := op(1, cyc_b); if len_a mod len_b = 0 then q := q + len_b*op(2, cyc_b); fi; od; p := p*q^op(2, cyc_a); od; res := res + p*flat_a[1]*flat_b[1]; od; od; od; res; end; set_seq_enum := proc(n) option remember; local orbits, orbit, ind, slist, perm, part, comb, item, entlst, sofar, sb, len; if n=1 then return 1 fi; slist := []; for perm in permute(n) do slist := [op(slist), [seq(q-1=perm[q]-1, q=1..n)]]; od; orbits := table(); for ind from n^n to 2*n^n-1 do item := convert(ind, base, n)[1..n]; for part in partition(n) do for comb in permute(part) do entlst := []; sofar := 0; for len in comb do entlst := [op(entlst), item[1+sofar..len+sofar]]; sofar := sofar + len; od; orbit := []; for sb in slist do orbit := [op(orbit), sort(subs(sb, entlst))]; od; orbits[convert(orbit, `set`)] := 1; od; od; od; nops([indices(orbits, `nolist`)]); end;