Dan Bron wrote:

...I'm not sure you need to provide a format for sets to your users.  You could 
rewrite your functions to apply to any array...

-----------

Dan, your general verbs are appealing, but there is a difficulty with verb 
"is", 
because a set can have elements which are themselves sets, and those elements 
can have elements which are themselves sets ... .  See the example below.

Thus a verb "is" to test two general arrays for set equality would have do a 
complicated recursive sort which knew which elements were sets and were 
therefore themselves eligible for sorting.

It was to circumvent such difficulties that I proposed a definition for "set" 
which included "sorted", and provided verb "set" to create the special arrays 
which are regarded as sets.  If we want an element to be a set, verb "set" 
should be used to create the element!  Here is an example of creating a set 
some 
of whose elements are sets:

]V =: set 1 ; (set (set 3;4);8;<(set 8;9) ) ; 10  NB. Example of Butch Lakeshore

+-+--+------------------++
|1|10|+-+------+------++||
| |  ||8|+-+-++|+-+-++||||
| |  || ||3|4||||8|9||||||
| |  || |+-+-++|+-+-++||||
| |  |+-+------+------++||
+-+--+------------------++

Observe, verb "set" sorted this set as it was being created.  And observe, 
element 2 of this set is a set, call it W, and elements 1 and 2 of set W are 
sets.  The empty box at the end of a list is my set-marker which has the dual 
purpose of (a) making it easy to identify sets and (b) ensuring that every set 
is a non-empty list of boxes (satisfies 0 = #...@$ and 0 < L.).

Another motivation for the definition of "set" as a list of boxes, without 
duplicates, having sorted curtail and tail <i.0 0, is to make it easy to test 
whether a given set is an element of another given set -- a fundamental 
operation of set theory.  If the sets were not recursively sorted at creation 
time (it easier to do then), it would be a real challenge to do it at 
element-testing time.

--You asked about an application.  Fraser Jackson built a model of set theory 
to 
help his daughter with school work.  My personal application is the fun of the 
challenge, showing what J can do, shared perhaps by participants creating 
general verbs for all arrays, including power set verbs.

For reference:

NB. usage set box or set list-of-boxes creates a set

set =: <@empty ,~ [: /:~...@~. ] -. <@empty

NB. empty =: (i.0 0)"_ is standard in the z locale, from stdlib.ijs

An "element" is the array inside a box of the curtail of a "set", and the empty 
set is the list ,<i.0 0 which has empty curtail.  I plan to revise verb set and 
its allies to allow i.0 0 to be an element, having realized after discussion 
from Raul that there is no need to exclude i.0 0 as an element.  That is, it 
will be OK for <i.0 0 be the set-marker tail and also to appear (once) in the 
curtail.


Dan Bron wrote:
> Kip Murray proposed:
>>  Proposal -- A "set" is a list of boxes, without duplicates, 
>>  with tail <i.0 0 and curtail sorted.  You can think of the 
>>  tail as a "set marker" that permits the empty set to be a 
>>  non-empty list.  Sorting the curtail makes it easer to test 
>>  whether a set is an element of another set and whether two 
>>  sets have the same elements and so are regarded as the same set.
> 
> Kip,
> 
> Reading in more detail, I'm not sure you need to provide a format for sets to 
> your users.  You could rewrite your functions to
> apply to any array, by handling some details under the covers.  For example:
> 
>    U       =:  ~.@:,
>    N       =:  [ -. -.
>    is      =:  -:&:(/:~)&:~.
>    less    =:  -.
>    isEmpty =:  -: 0&#
> 
> This might be more convenient for your users, and might enjoy some 
> performance benefits (e.g. when the elements of a set are
> homogenous & wouldn't need to be boxed).
> 
> But you've obviously thought about this more than I have.  Can you describe 
> how you arrived at your representation?  What were
> your motives?  
> 
> It might be easier to design these set functions in the context of an 
> application.  Do you have one in mind?
> 
> -Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to