I thought you might enjoy this:

   ps =: [: set [: <"0 ([: |. [: #: [: i. 2 ^ #@>) (([:<#)"1) > 
   ps set 1;2;3
---------------------------------------------------------┐
│---T-----T-------T---------T-------T-----T-------T-----┐│
││-┐│----┐│------┐│--------┐│------┐│----┐│------┐│----┐││
││││││--┐│││--T-┐│││--T-T-┐│││--T-┐│││--┐│││--T-┐│││--┐│││
││L-│││1│││││1│2│││││1│2│3│││││1│3│││││2│││││2│3│││││3││││
││  ││L--│││L-+--│││L-+-+--│││L-+--│││L--│││L-+--│││L--│││
││  │L----│L------│L--------│L------│L----│L------│L----││
│L--+-----+-------+---------+-------+-----+-------+------│
L---------------------------------------------------------
   
   ps2=: [: set"0 ([: #: [: i. 2 ^ [: # >) (([: < #)"1) > 
   ps2 set 1;2;3
---T-----T-----T-------T-----T-------T-------T---------┐
│-┐│----┐│----┐│------┐│----┐│------┐│------┐│--------┐│
│││││--┐│││--┐│││--T-┐│││--┐│││--T-┐│││--T-┐│││--T-T-┐││
│L-│││3│││││2│││││2│3│││││1│││││1│3│││││1│2│││││1│2│3│││
│  ││L--│││L--│││L-+--│││L--│││L-+--│││L-+--│││L-+-+--││
│  │L----│L----│L------│L----│L------│L------│L--------│
L--+-----+-----+-------+-----+-------+-------+----------
   
   ps3 =: [: set"0 ([:|.[: #: [: i. 2 ^ [: # >) (([: < #)"1) > 
   ps3 set 1;2;3
----------T-------T-------T-----T-------T-----T-----T--┐
│--------┐│------┐│------┐│----┐│------┐│----┐│----┐│-┐│
││--T-T-┐│││--T-┐│││--T-┐│││--┐│││--T-┐│││--┐│││--┐│││││
│││1│2│3│││││1│2│││││1│3│││││1│││││2│3│││││2│││││3│││L-│
││L-+-+--│││L-+--│││L-+--│││L--│││L-+--│││L--│││L--││  │
│L--------│L------│L------│L----│L------│L----│L----│  │
L---------+-------+-------+-----+-------+-----+-----+---
   
   ps4 =: [: set"0 ([:|:[:|.[:|:[: #: [: i. 2 ^ [: # >) (([: < #)"1) > 
   ps4 set 1;2;3
---T-----T-----T-------T-----T-------T-------T---------┐
│-┐│----┐│----┐│------┐│----┐│------┐│------┐│--------┐│
│││││--┐│││--┐│││--T-┐│││--┐│││--T-┐│││--T-┐│││--T-T-┐││
│L-│││1│││││2│││││1│2│││││3│││││1│3│││││2│3│││││1│2│3│││
│  ││L--│││L--│││L-+--│││L--│││L-+--│││L-+--│││L-+-+--││
│  │L----│L----│L------│L----│L------│L------│L--------│
L--+-----+-----+-------+-----+-------+-------+----------
   
   ps
[: set [: <"0 ([: |. [: #: [: i. 2 ^ #@>) ([: < #)"1 >
   ps2
[: set"0 ([: #: [: i. 2 ^ [: # >) ([: < #)"1 >
   ps3
[: set"0 ([: |. [: #: [: i. 2 ^ [: # >) ([: < #)"1 >
   ps4
[: set"0 ([: |: [: |. [: |: [: #: [: i. 2 ^ [: # >) ([: < #)"1 >
   
 Did you ever get the pdf file?  I'm still trying to make the empty set be
the same size as the set with a  1  in it. 

Linda  


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of km
Sent: Sunday, November 17, 2013 11:43 PM
To: [email protected]
Subject: Re: [Jprogramming] Sets please help

Henry, thanks for your help.

4 is the expected level of a set whose elements are sets.  Here's how it
works:

   1;2  NB. boxes contain proposed elements 1 and 2
+-+-+
|1|2|
+-+-+
   set 1;2  NB. boxes containing elements are "fenced in"
+-----+
|+-+-+|
||1|2||
|+-+-+|
+-----+
   (set 1;2);<set 3;4  NB. boxes contain proposed elements
+-------+-------+
|+-----+|+-----+|
||+-+-+|||+-+-+||
|||1|2|||||3|4|||
||+-+-+|||+-+-+||
|+-----+|+-----+|
+-------+-------+
   set (set 1;2);<set 3;4  NB. boxes containing elements are "fenced in"
+-----------------+
|+-------+-------+|
||+-----+|+-----+||
|||+-+-+|||+-+-+|||
||||1|2|||||3|4||||
|||+-+-+|||+-+-+|||
||+-----+|+-----+||
|+-------+-------+|
+-----------------+

NB. Similarly
   L. ps set 1;2
4

I will look at the rank issues now.  Thanks for your help.

--Kip Murray

Sent from my iPad

> On Nov 17, 2013, at 8:40 PM, Henry Rich <[email protected]> wrote:
> 
> It looks to me that ps adds an extra level of boxing.  Check the result of
>   ps set ;:'a b'
> to see if I'm wrong.

>> On 11/17/2013 9:19 PM, km wrote:
>> Will you try to "break" the following proposal before I post it on the J
Wike?
>> 
>> Thanks,
>> 
>> -- Kip Murray
>> 
>> 
>> NB. J SETS PROPOSAL
>> 
>> NB. This ia a script you can copy and save, then load or loadd.
>> 
>> 
>> NB. INTRODUCTION
>> 
>> NB. Part of each set is its enclosing box.  Like a Venn diagram set.
>> 
>> NB. A set is a box enclosing a sorted list of boxes.
>> NB. An element is the contents of a box in the sorted list.
>> 
>> NB. A -: B tests whether set A is set B.
>> 
>> 
>> NB. DEFINITIONS
>> 
>> set =: [: < [: /:~ ~.  NB. create set from a box or list of boxes
>> 
>> NB. A set is a: or (scalar and its open is vector, boxed, without
duplicates, and sorted).
>> 
>> isset =: (a: -: ]) +. [: *./ (0 = #@$) , [: ( (1 = #@$),(0 < L.),(-: 
>> ~.),(-: /:~) ) >
>> 
>> 
>> NB. ILLUSTRATIONS
>> 
>> 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
>> 
>> 
>> NB. DEFINITIONS
>> 
>> 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
>> 
>> 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
"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!
>> 
>> 
>> NB. EXAMPLES
>> 
>> (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

Reply via email to