You have the right idea but are not using my definition of set. Compare set 'A';'B';'C' NB. My version of your 'ABC' +-------+ |+-+-+-+| ||A|B|C|| |+-+-+-+| +-------+ ps set 'A';'B';'C' NB. my version of your f 'ABC' +----------------------------------------+ |++---+-----+-------+-----+---+-----+---+| |||+-+|+-+-+|+-+-+-+|+-+-+|+-+|+-+-+|+-+|| ||||A|||A|B|||A|B|C|||A|C|||B|||B|C|||C||| |||+-+|+-+-+|+-+-+-+|+-+-+|+-+|+-+-+|+-+|| |++---+-----+-------+-----+---+-----+---+| +----------------------------------------+
--Kip Sent from my iPad > On Nov 14, 2013, at 6:54 PM, "Linda Alvord" <[email protected]> wrote: > > f=: 13 :' <"1 |:((>:i.#y)*/"0 |:((#y)#2)#:i.2^#y){'' '',y' > f 'ABC' > ----T---T---T---T---T---T---T---┐ > │ │ C│ B │ BC│A │A C│AB │ABC│ > L---+---+---+---+---+---+---+---- > > This is a set of the subsets? I haven't looked at your example yet. > > Linda > > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of km > Sent: Thursday, November 14, 2013 3:18 PM > To: [email protected] > Subject: [Jprogramming] Sets > > Here is my latest attempt at sets in J. Would anyone care to write a verb > ps (power set) such that ps y is the set of all subsets of set y? It's > called the power set in part because when a set has n elements its power set > has 2^n elements. --Kip Murray > > NB. A set is a box with a sorted list of boxes inside. > NB. An element is the contents of a box in the list. > NB. A -: B tests whether set A is set B. > > set =: [: < [: /:~ ~. NB. create set from list of boxes > > NB. The list may have duplicates but the set has none. > > EE =: <$0 NB. empty set, same as Ace a: > > eo =: <@[ e. >@] NB. test whether x is an element of y > > uu =: [: set ,&> NB. union > > mm =: [: < -.&> NB. minus > > sd =: mm uu mm~ NB. symmetric difference > > cp =: uu mm sd NB. common part (intersection) > > ss =: uu -: ] NB. test whether x is a subset of y > > (set 1;2;3;3) -: set 3;1;2 > 1 > > ]A =: set 2;'b';1;'a' > +---------+ > |+-+-+-+-+| > ||1|2|a|b|| > |+-+-+-+-+| > +---------+ > > ]B =: set 'b';'a';4;3;'a' > +---------+ > |+-+-+-+-+| > ||3|4|a|b|| > |+-+-+-+-+| > +---------+ > > A uu B > +-------------+ > |+-+-+-+-+-+-+| > ||1|2|3|4|a|b|| > |+-+-+-+-+-+-+| > +-------------+ > > A sd B > +---------+ > |+-+-+-+-+| > ||1|2|3|4|| > |+-+-+-+-+| > +---------+ > > A cp B > +-----+ > |+-+-+| > ||a|b|| > |+-+-+| > +-----+ > > NB. Below is the set of all subsets of set 0;1 > > set EE;(set <0);(set <1);<set 0;1 > +------------------------+ > |+--+-----+-------+-----+| > ||++|+---+|+-----+|+---+|| > ||||||+-+|||+-+-+|||+-+||| > ||++|||0|||||0|1|||||1|||| > || ||+-+|||+-+-+|||+-+||| > || |+---+|+-----+|+---+|| > |+--+-----+-------+-----+| > +------------------------+ > > Sent from my iPad > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
