Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

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/


  • Prev by Date: using functions with package name prefixed.
  • Next by Date: RE: Wolfram Functions Site
  • Previous by thread: Re: Powerset operation: how?
  • Next by thread: Re: Powerset operation: how?