Your power set is what I call a list of sets, not a set of sets -- because I 
define a set to be a box enclosing a sorted list of boxes.

On the other hand, your power set is a set of sets if you define a set to be a 
list of boxes.  I therefore have a proposal for you indicated by the verbs 
below whose names end in a 'p' .

Why do I include Sort /:~ in my proposal?  Let's discuss that another time.  
The ~. and ,L:1 you will see ensure that even singleton sets are lists (not 
atoms), which makes them sort properly with other lists.


   psb=: a:,[:(],[,,L:1)/ <L:0@>  NB. power set, R.E. Boss
   
   psb set 0;1;2  NB. List of sets or set of sets?
++---+---+-----+---+-----+-----+-------+
||+-+|+-+|+-+-+|+-+|+-+-+|+-+-+|+-+-+-+|
|||2|||1|||1|2|||0|||0|2|||0|1|||0|1|2||
||+-+|+-+|+-+-+|+-+|+-+-+|+-+-+|+-+-+-+|
++---+---+-----+---+-----+-----+-------+
   
   NB. Proposed for R.E. Boss

   setbp =: [: /:~ ~.  NB. Create set from list of boxes
   
   psbp =: [: /:~ [: ,L:1 a: , [: (] , [ , ,L:1)/ <L:0
   
   setbp 2;0;1;2  NB. Here a set is a sorted list of boxes
+-+-+-+
|0|1|2|
+-+-+-+
   
   psbp setbp 0;1;2  NB. power set
++---+-----+-------+-----+---+-----+---+
||+-+|+-+-+|+-+-+-+|+-+-+|+-+|+-+-+|+-+|
|||0|||0|1|||0|1|2|||0|2|||1|||1|2|||2||
||+-+|+-+-+|+-+-+-+|+-+-+|+-+|+-+-+|+-+|
++---+-----+-------+-----+---+-----+---+
   
   $L:1 psbp setbp 0;1;2
+-+-+-+-+-+-+-+-+
|0|1|2|3|2|1|2|1|
+-+-+-+-+-+-+-+-+

--Kip Murray

Sent from my iPad

> On Nov 16, 2013, at 5:04 AM, "R.E. Boss" <[email protected]> wrote:
> 
>   ps=: a:,[:(],[,,L:1)/ <L:0@>
> 
>   ,.L:1 ps B
> 
> +-+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
> 
> | |+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|
> 
> | ||3|||4|||4|||a|||a|||a|||a|||b|||b|||b|||b|||b|||b|||b|||b||
> 
> | |+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|+-+|
> 
> | |   |   ||3||   ||3|||4|||4||   ||3|||4|||4|||a|||a|||a|||a||
> 
> | |   |   |+-+|   |+-+|+-+|+-+|   |+-+|+-+|+-+|+-+|+-+|+-+|+-+|
> 
> | |   |   |   |   |   |   ||3||   |   |   ||3||   ||3|||4|||4||
> 
> | |   |   |   |   |   |   |+-+|   |   |   |+-+|   |+-+|+-+|+-+|
> 
> | |   |   |   |   |   |   |   |   |   |   |   |   |   |   ||3||
> 
> | |   |   |   |   |   |   |   |   |   |   |   |   |   |   |+-+|
> 
> +-+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
> 
> 
> 
> R.E. Boss
> 
> 
> 
> (Add your info to http://www.jsoftware.com/jwiki/Community/Demographics )
> 
> 
> 
>> -----Original Message-----
> 
>> From: [email protected] [mailto:programming-
> 
>> [email protected]] On Behalf Of km
> 
>> Sent: zaterdag 16 november 2013 8:13
> 
>> To: [email protected]
> 
>> Subject: [Jprogramming] Sets
> 
> 
>> The following script for doing sets in J is a big improvement over what I
> 
>> proposed several years ago.  You can save it and then do a loadd.  I would
> like
> 
>> to make it a J Wiki page, but it will take a while to relearn how to do
> that.
> 
>> Near the end is my verb ps for creating power sets and another cp for
> 
>> creating the Cartesian product of two sets.  --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 sorted list.
> 
>> NB. A -: B tests whether set A is set B.
> 
> 
>> set =: [: < [: /:~ ~.  NB. create set from a box or list of boxes
> 
> 
>> isset =: -: [: set >  NB. test whether y is a set
> 
> 
> 
>> set 'a';i.2 2  NB. elements are 'a' and i. 2 2
> 
> 
>> set <'a'  NB. sole element is 'a'
> 
> 
>> ]Empty =: set ''  NB. the empty set, same as Ace a:
> 
> 
>> isset Empty
> 
> 
> 
>> sf =: [: > ({ >)  NB. From { for sets: retrieve xth element of y, a set
> 
> 
>> sn =: ([: # >) : ([: < (# >))  NB. Number # for sets
> 
> 
>> eo =: <@[ e. >@]  NB. test whether x is an element of y
> 
> 
>> un =: [: set ,&>  NB. union of x and y
> 
> 
>> mn =: [: < -.&> NB. "minus" -- create set with the elements of x that are
> not
> 
>> in y
> 
> 
>> sd =: mn un mn~  NB. symmetric difference
> 
> 
>> nt =: un mn sd  NB. intersection
> 
> 
>> so =: un -: ]  NB. test whether x is a subset of y
> 
> 
>> cp =: [: set [: , ({@(,&<))&>  NB. Cartesian product, adapted from CP in
> 
>> Vocabulary's "Catalog {"
> 
> 
>> ps =: [: set [: <"0 ([: #: [: i. 2 ^ #@>) <@#"1 >  NB. ps y is the power
> set of y
> 
> 
>> NB. ps y is the set whose elements are all the subsets of y .  There are
> 2^#>y
> 
>> of them.
> 
> 
>> dv =: [: < [: ,. >  NB. dv y displays the set y vertically, useful for
> power sets!
> 
> 
> 
>> (set 1;2;3;3) -: set 3;1;2  NB. On each side the elements are 1 and 2 and
> 3 .
> 
> 
>> ]A =: set 2;'b';1;'a'
> 
> 
>> ]B =: set 'b';'a';4;3;'a'
> 
> 
>> A un B
> 
> 
>> A sd B
> 
> 
>> A nt B
> 
> 
>> (set 1;2) cp set 'a';'b';'c'
> 
> 
>> ps set 0;1;2
> 
> 
> 
>> 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

Reply via email to