Re: Powerset operation: how?
- To: mathgroup at smc.vnet.net
- Subject: [mg45591] Re: [mg45570] Powerset operation: how?
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Fri, 16 Jan 2004 06:05:05 -0500 (EST)
- References: <200401140626.BAA19730@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 14 Jan 2004, at 06:26, see.address at post.sig wrote: > How should I code efficiently the powerset of a (small) set > represented by a > list? > > A search on Wolfram site turned out nothing useful, but I'm quite sure > somebody has done it already. > > Indeed, you are right. The most elegant way in my opinion is due to Ilan Vardi PowerSet[s_List]:=Distribute[{{},{#}}&/@s,List,List,List,Union] PowerSet[{a,b,c}] {{},{c},{b},{b,c},{a},{a,c},{a,b},{a,b,c}} This is an example of "algebraic programming", a programming style that Mathematica is particularly well suited for (for more on this see my forthcoming article in the Mathematica Journal). Andrzej Kozlowski Chiba, Japan http://www.mimuw.edu.pl/~akoz/
- References:
- Powerset operation: how?
- From: see.address@post.sig
- Powerset operation: how?