This question already has an answer here:

Is there some function recently added to Mathematica that facilitates forming all partitions of a n-element set into k subsets?

In other words, something that easily gives the same thing as what Combinatorica`KSetPartitions does?

I'm aware of the defined function KSetP at Partition a set into $k$ non-empty subsets, but that has quite a bit of code.

My query here is asking for something at a higher level than the aforementioned function KSetP that is made possible by some built-in function either that was recently added to Mathematica or was previously available but was not exploited in KSetP.


marked as duplicate by Jason B., m_goldberg, LCarvalho, LLlAMnYP, MarcoB Nov 4 '17 at 15:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ How big is your n likely to be? For small n there may be something simpler, but I would guess that since there are $2^n$ subsets, it quickly becomes tricky to keep the computational costs down. $\endgroup$ – aardvark2012 Oct 31 '17 at 22:52
  • $\begingroup$ @JasonB.: I referenced that; but please look at the framing of my question again. $\endgroup$ – murray Nov 1 '17 at 0:28
  • $\begingroup$ @aardvark2012: I want something that works for general n. The issue is whether some built-in function, especially one added recently, can take care of a lot more of the work at a lower level, hence no need to do the detailed coding shown for kSetP. $\endgroup$ – murray Nov 1 '17 at 0:30
  • 2
    $\begingroup$ @murray - I don't see the distinction really. Is there a built in function to do this? I can't find it if there is. You say the KSetP function has quite a bit of code, but it's definition is only 11 lines. $\endgroup$ – Jason B. Nov 1 '17 at 3:12
  • $\begingroup$ There are more answers here, one of which may be "at a higher level". $\endgroup$ – KennyColnago Nov 1 '17 at 16:34