Re: Creating combinations from a group of sets
- To: mathgroup at smc.vnet.net
- Subject: [mg48718] Re: Creating combinations from a group of sets
- From: "Rob Pratt" <Rob.Pratt at sas.com>
- Date: Fri, 11 Jun 2004 03:52:51 -0400 (EDT)
- References: <ca91bp$t8h$1@smc.vnet.net>
- Reply-to: "Rob Pratt" <Rob.Pratt at sas.com>
- Sender: owner-wri-mathgroup at wolfram.com
"Jeanette L Domber" <Jeanette.L.Domber at aero.org> wrote in message news:ca91bp$t8h$1 at smc.vnet.net... > > I have a group of sets: > > {1,2,3} > {4,5} > {6} > {7,8} > > I wish to create all unique combinations of the sets that contain exactly one element from each set: > > {1,4,6,7} > {1,5,6,7} > {1,4,6,8} > {1,5,6,8} > {2,4,6,7} > {2,5,6,7} > etc. > > In all, there should be 12 combinations. > > If I use KSubsets giving it a list {1,2,3,4,5,6,7,8} to create combinations containing 4 elements, I get a list of 70 combinations, 58 of which are extraneous to my application. > > Does anyone know how to manipulate the functions in DiscreteMath`Combinatorica` to accomplish this efficiently? > > Thanks, > Jeanette You don't need Combinatorica to do this. In[1]:= ?Distribute Distribute[f[x1, x2, ... ]] distributes f over Plus appearing in any of the xi. Distribute[expr, g] distributes over g. Distribute[expr, g, f] performs the distribution only if the head of expr is f. In[2]:= Distribute[{{1,2,3},{4,5},{6},{7,8}}, List] Out[2]= {{1, 4, 6, 7}, {1, 4, 6, 8}, {1, 5, 6, 7}, {1, 5, 6, 8}, > {2, 4, 6, 7}, {2, 4, 6, 8}, {2, 5, 6, 7}, {2, 5, 6, 8}, {3, 4, 6, 7}, > {3, 4, 6, 8}, {3, 5, 6, 7}, {3, 5, 6, 8}} Rob Pratt