From: J Jacobs
Subject: Power
Date: 
Message-ID: <3j198s$4ig@itu1.sun.ac.za>
Can someone tell me how to impliment a function power set of 
a set in Common Lisp. 
  The power set of eg. '(a b c) is 
  '((a b c) (a b) (a c) (b c) (a) (b) (c) nil)
It should work for any number of elements in a set.

Thanx
Jonavan

From: Peter Ward
Subject: Re: Power
Date: 
Message-ID: <794130193snz@mondas.demon.co.uk>
In article <··········@itu1.sun.ac.za> ········@cs.sun.ac.za "J Jacobs" writes:

> Can someone tell me how to impliment a function power set of 
> a set in Common Lisp. 
>   The power set of eg. '(a b c) is 
>   '((a b c) (a b) (a c) (b c) (a) (b) (c) nil)
> It should work for any number of elements in a set.

I'm no Lisp programmer but you just need to think how to do it
recursively. To work through your example...

To get the power set of '(a b c), you could start with
the power set of '(b c). You are allowed to think like this
when writing recursive functions. This gives you
  '((b c) (b) (c) nil)
Now if you made a copy of that with 'a added into each member, you get
  '((a b c) (a b) (a c) (a))
Join those together and
  '((a b c) (a b) (a c) (a) (b c) (b) (c) nil)
Which is right unless the order is important to you.
The recursion terminates because the power set of nil is (nil).

BTW I suspect there is a neater, more efficient way but this
makes the thought process clear.

-- 

Pete Ward
Mondas IT Ltd
From: Erik Naggum
Subject: Re: Power
Date: 
Message-ID: <3003245326.092020@naggum.no>
[J Jacobs]

|   Can someone tell me how to impliment a function power set of 
|   a set in Common Lisp. 
|     The power set of eg. '(a b c) is 
|     '((a b c) (a b) (a c) (b c) (a) (b) (c) nil)
|   It should work for any number of elements in a set.

what is the difference between (power '(b c)) and (power '(a b c))?
this should allow you to make a recursive definition, and ... voila!

#<Erik>
-- 
miracle of miracles.  look what the Net dragged in.
From: Jeffrey Mark Siskind
Subject: Re: Power
Date: 
Message-ID: <QOBI.95Mar5221439@qobi.ai>
If you use Screamer the power set of a set can be defined as follows:

(defun a-subset-of (x)
 (if (null x)
     nil
     (let ((y (a-subset-of (rest x)))) (either (cons (first x) y) y))))

(defun powerset (x) (all-values (a-subset-of x)))

Screamer is available from ftp.cs.toronto.edu:/pub/qobi/screamer.tar.Z.

    Jeff (home page http://www.cdf.toronto.edu/DCS/Personal/Siskind.html)
--

    Jeff (home page http://www.cdf.toronto.edu/DCS/Personal/Siskind.html)