You now have a /list/ of sets.  To get a /set/ of sets, put a large box around 
your list!  Also rewrite psla so its argument is  the /set/ <1;2;3 (not the 
/list/ 1;2;3).  --Kip

Sent from my iPad

> On Nov 17, 2013, at 5:13 AM, "Linda Alvord" <[email protected]> wrote:
> 
> 
> Click above to see sets!
> 
> 
> ]set=:<1;2;3
> ┌───────┐
> │┌─┬─┬─┐│
> ││1│2│3││
> │└─┴─┴─┘│
> └───────┘
>        
> This match my idea of sets and subsets.  The subsets are “names” for the 
> subsets.
> 
>   psla=: 13 :'<"0<"0 <"1 |:((>:i.#y)*/"0 |:(|:|.|:(#y)#2)#:i.2^#y){A=:'' 
> '',":10#.>>y'
> 
>   psla 1;2;3
> ┌───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┐
> │┌─────┐│┌─────┐│┌─────┐│┌─────┐│┌─────┐│┌─────┐│┌─────┐│┌─────┐│
> ││┌───┐│││┌───┐│││┌───┐│││┌───┐│││┌───┐│││┌───┐│││┌───┐│││┌───┐││
> │││   │││││  3│││││ 2 │││││ 23│││││1  │││││1 3│││││12 │││││123│││
> ││└───┘│││└───┘│││└───┘│││└───┘│││└───┘│││└───┘│││└───┘│││└───┘││
> │└─────┘│└─────┘│└─────┘│└─────┘│└─────┘│└─────┘│└─────┘│└─────┘│
> └───────┴───────┴───────┴───────┴───────┴───────┴───────┴───────┘
>   A
> 123
>   $A
> 4
> 
> I can’t explain how this happens!  Any ideas?
> 
> 
>   psla set
> ┌─────┬─────┐
> │┌───┐│┌───┐│
> ││┌─┐│││┌─┐││
> │││ │││││1│││
> ││└─┘│││└─┘││
> │└───┘│└───┘│
> └─────┴─────┘
>   A
> 123
>   $A
> 4
> 
> Linda   
> 
> 
> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of km
> Sent: Sunday, November 17, 2013 1:03 AM
> To: [email protected]
> Subject: Re: [Jprogramming] Sets
> 
> You are getting closer.  I start with
> 
>   set 1;2;3
> +-------+
> |+-+-+-+|
> ||1|2|3||
> |+-+-+-+|
> +-------+
> 
> and end with
> 
>   ps set 1;2;3
> +--------------------------------------------------------+
> |+--+-----+-------+---------+-------+-----+-------+-----+|
> ||++|+---+|+-----+|+-------+|+-----+|+---+|+-----+|+---+||
> ||||||+-+|||+-+-+|||+-+-+-+|||+-+-+|||+-+|||+-+-+|||+-+|||
> ||++|||1|||||1|2|||||1|2|3|||||1|3|||||2|||||2|3|||||3||||
> ||  ||+-+|||+-+-+|||+-+-+-+|||+-+-+|||+-+|||+-+-+|||+-+|||
> ||  |+---+|+-----+|+-------+|+-----+|+---+|+-----+|+---+||
> |+--+-----+-------+---------+-------+-----+-------+-----+|
> +--------------------------------------------------------+
> 
> The result looks exactly the same if you start with
> 
>   set '1';'2';'3'
> +-------+
> |+-+-+-+|
> ||1|2|3||
> |+-+-+-+|
> +-------+
> 
> "A set is box enclosing a list of boxes.  Each box in the enclosed list 
> contains an element of the set."
> 
> --Kip
> 
> Sent from my iPad
> 
>> On Nov 16, 2013, at 6:46 PM, "Linda Alvord" <[email protected]> wrote:
>> 
>> This looks more like your result:
>> 
>>  f=: 13 :'<"0<"0 <"1 |:((>:i.#y)*/"0 |:(|:|.|:(#y)#2)#:i.2^#y){'' '',y'
>> 
>>  f '123'
>> --------T-------T-------T-------T-------T-------T-------T-------┐
>> │------┐│------┐│------┐│------┐│------┐│------┐│------┐│------┐│
>> ││----┐│││----┐│││----┐│││----┐│││----┐│││----┐│││----┐│││----┐││
>> │││   │││││  3│││││ 2 │││││ 23│││││1  │││││1 3│││││12 │││││123│││
>> ││L----│││L----│││L----│││L----│││L----│││L----│││L----│││L----││
>> │L------│L------│L------│L------│L------│L------│L------│L------│
>> L-------+-------+-------+-------+-------+-------+-------+--------
>> 
>> Linda
>> 
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of km
>> Sent: Saturday, November 16, 2013 2:13 AM
>> 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
> ----------------------------------------------------------------------
> 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