I have revised my model of set theory so that every array, including i.0 0, can 
be an element, and have adapted Raul's verb powSet to this model.

In this model 2 is not a set, but you can define a set corresponding to the 
natural number 2 of mathematical set theory.

If I can learn to adapt Fraser's verb sortSet to this model, I may be able to 
remove its current restriction that the curtail of a "set" must be sorted and 
have no duplicates.  I am returning to this model because I want a unique empty 
set, and I do not want any sets which are elements of themselves.

    ]E =: , < i.0 0   NB. empty set
++
++
    ]M =: 'a';'b';E   NB. simple sets can be defined this way.
+-+-++
|a|b||
+-+-++
    NB. above, note "set-marker" tail

    NB. following verb pwrSet is adapted from Raul's powSet, see Details below:

    pwrSet M
+--+----+------+----++
|++|+-++|+-+-++|+-++||
|++||a||||a|b||||b||||
|  |+-++|+-+-++|+-++||
+--+----+------+----++

    NB. Imitating mathematical set theory

    ]zero =: E               NB. empty set
++
++
    ]one =: zero;E           NB. set whose only element is zero
+--++
|++||
|++||
+--++
    ]two =: zero;one;E       NB. set whose only elements are zero and one
+--+-----++
|++|+--++||
|++||++||||
|  ||++||||
|  |+--++||
+--+-----++
    ]singletontwo =: two;E   NB. set whose only element is two
+-----------++
|+--+-----++||
||++|+--++||||
||++||++||||||
||  ||++||||||
||  |+--++||||
|+--+-----++||
+-----------++

    countset two
2
    countset singletontwo
1
    two issameset singletontwo
0
    isset two
1
    isset 2
0


Details

NB. A "set" is a list of boxes with tail <i.0 0 and having a sorted curtail
NB. with no duplicates.  An "element" is the open of a box in the curtail.

NB. The tail <i.0 0 is a "set-marker" which permits the list ,<i.0 0
NB. to be the _unique_ empty set.

issequence =: (1 = #...@$) *. (0 < L.)

isset =: issequence *. ( (< i.0 0) -: {: ) *. ( (-: /:~)*.(-: ~.) )@}:

Empty =: , < i.0 0   NB. empty set

E =: Empty

set =: ( /:~...@~.@}: , {: ) : [:

NB. usage set list-of-boxes-ending-with-Empty creates a set;
NB. elements are opens of boxes in the curtail of the argument

issameset =: -:

is =: issameset

iselementof =: <@[ e. }:@]

in =: iselementof

countset =: #...@}:

index =: }:@[ i. <@]             NB. find index of element

indexof =: index

get =: [:`({:: }:)@.(1 > l...@[)   NB. retrieve element

u =: [: set -. , ]    NB. union

less =: Empty ,~ -.   NB. difference

n =: [ less less      NB. intersection

issubsetof =: [ is n

part =: issubsetof

isemptyset =: -: Empty"_

pwrset =: 3 : 0       NB. adapted from Fraser's explicit version
if.
    isemptyset y
do.
    Empty;Empty        NB. set whose only element is Empty

else.
    (Empty ,~ /:~) (#&y) &.> ( <"1 ] 1 ,~"1 (#: i.2^<:#y) )
end.
)

NB. pwrSet below is adapted from Raul's powSet

pwrSet =: (<i.0 0) ,~ ] /:~@:(<@#~) 1 (,~"1) 2 (#"1~ {:)@#:@i...@^ #...@}:


Kip Murray wrote:
> This has to do with Raul's question,
> 
> Raul Miller wrote:
>  > . . . how do you distinguish between an element of a
>  > set and a set containing only that element?
> 
> 
> I will discuss three version of sets.  Bear with me, we will get to "2 is the 
> set whose only element is 2" in the second version.
> 
> 
> In mathematical set theory,
> 
>     2 looks different from {2} -- but how do you know 2 isn't {2}?  The 
> question 
> isn't as fanciful as it looks, for it is common in set theory to say
> 
> 0 is defined to be {}, the empty set
> 1 is defined to be {0}, the set whose only element is 0
> 2 is defined to be {0,1}, the set whose only elements are 0 and 1
> ... and so on: the natural numbers are sets, and how do we know set 2 isn't 
> the 
> set {2}?
> 
> W see 0 is {}, 1 is { {} }, and
> 
>   2  is   { {} , { {} } }, whereas
> {2} is { { {} , { {} } } }, and we are sure 2 is not {2}.  (For one thing, 
> {2} 
> has only one element, and 2 has two elements!)
> 
> 
> But in the current J model of sets we have
> 
>     <"_1 ] 2   NB. <"_1 boxes items
> +-+
> |2|
> +-+
> 
> which means 2 is the only element of set 2 -- we have defined sets to be open 
> or 
> boxed arrays and the elements of open arrays to be their items.
> 
> 
> In my original J model of sets,
> 
>     2         NB. looks different from (set ,<2) the set whose only element 
> is 2
> 2
>     set ,<2   NB. argument is required to be a list of boxes containing 
> elements
> +-++
> |2||
> +-++
> 
>     count set <2   NB. number of elements
> 1
>     2 iselement set <2
> 1
>     2 -: set <2    NB. not only looks different, is different
> 0
> 
> 
> Reference material:
> 
> 
> Current implementor catechism
> 
> Question 1: What is a set?
>     Answer: A set is an array.
> 
> Question 2: What is an element of a set?
>     Answer: If the set is open, an element is an item of the set.  If the set 
> is
>             boxed, an element is the open of an atom of the set.
> 
> 
> Earlier implementor catechism (revised)
> 
> Question 0: What is a sequence?
>     Answer: A "sequence" is a list of boxes.  A "term" of a sequence is the 
> open
>             of one of its boxes.
> 
> Question 1: What is a set?
>     Answer: A "set" is a sequence whose last term is i.0 0 .
> 
> Question 2: What is an element of a set?
>     Answer: An "element" of a set is a term of its curtail.
> 
> ----------------------------------------------------------------------
> 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