Re: Listing the partitions of a set
- To: mathgroup at smc.vnet.net
- Subject: [mg65311] Re: Listing the partitions of a set
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sat, 25 Mar 2006 05:17:48 -0500 (EST)
- Organization: The Open University, Milton Keynes, UK
- References: <e0022d$plp$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Richard Palmer wrote: > Is there a simple way to list the partitions of a set? For example, there > are 15 partitions on a set of 4 elements. {{{1, 2, 3, 4}}, {1, {2, 3, 4}}, > {{1, 3, 4}, 2}, {{1, 2, 4}, 3}, {{1, 2, 3}, 4}, {{1, 2}, {3, 4}}, {{1, > 3}, {2, 4}}, {{1, 4}, {2, 3}}, {1, 2, {3, 4}}, {1, 3, {2, 4}}, {1, 4, {2, > 3}}, {2, 3, {1, 4}}, {2, 4, {1, 3}}, {3, 4, {1, 2}}, {1, 2, 3, 4}} . > > Hi Richard, You can use the *SetPartitions* function from the *Combinatorica* package: In[1]:= Needs["DiscreteMath`Combinatorica`"] In[2]:= SetPartitions[4] Out[2]= {{{1, 2, 3, 4}}, {{1}, {2, 3, 4}}, {{1, 2}, {3, 4}}, {{1, 3, 4}, {2}}, {{1, 2, 3}, {4}}, {{1, 4}, {2, 3}}, {{1, 2, 4}, {3}}, {{1, 3}, {2, 4}}, {{1}, {2}, {3, 4}}, {{1}, {2, 3}, {4}}, {{1}, {2, 4}, {3}}, {{1, 2}, {3}, {4}}, {{1, 3}, {2}, {4}}, {{1, 4}, {2}, {3}}, {{1}, {2}, {3}, {4}}} In[3]:= Length[%] Out[3]= 15 Best regards, /J.M.