Fraser, I will chew on this.  I can see my elaborate theory going to the place 
where elaborate theories go.

Everyone please note the lists of Dan and Fraser's verbs near the end, taking 
special note of "Set", "isin", and "isequalset".

I hope the discussion will continue a little longer.  I am uncertain about verb 
isequalset, believing it should be something like issubset *. issubset~ .  Kip


Dan:

>> ...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...


Kip:

>> Dan, your general verbs are appealing, but there is a difficulty with verb 
>> "is"
...


Fraser:

> I agree strongly with Dan here.  Every J noun is a set of items.  Primitives
> provide a means of dealing with a huge range of set problems where the
> elements are discrete entities.  You do not need any boxing.  The simple
> functions  U and N introduced by Dan provide all that is needed for
> discussing and solving a large number of problems.  Creating a subset may 
> involve comparisons of individual elements, and not require any boxing.
> 
> As noted boxed objects are needed when the elements of a set are themselves
> sets of different numbers of elements or are not homogenous.  So sets of
> sets need boxed objects.  You can achieve any level extension required by
> repeatedly creating a set of all subsets of subsets of a set by an
> additional level of boxing.   With this form there is no need for addition of
> an empty element to the list to denote a set of elements.   An
> empty element will only occur in the list of all subsets of the set.  J 
> handles
> the empty subset automatically with standard procedures except for the
> standard proposition that the empty set is a member of every set.
> 
> You devised a standard form using the sorted nub to list the elements of
> sets, and that can be helpful but is not essential.  Some applications may
> consist of 13 cards from four suites, the set consisting of multiples of
> some identical items.  The nub of a set is an important concept and in much 
> set theory the distinct items are all that is considered.  What we
> want are functions which will perform the essential operations and tests
> when the set of interest is any J noun even with repetitions of its items.
> In additon to the functions in Dan's post you might want something like the 
> following, probably with some tweaking.


Fraser's verbs:

> Set =: (/:~)@~.   NB. sorted nub
> isin =: *./ @ e.
> isequalset =: isin~ *. isin
> ispropersubset =: < & (#...@~.)
> isemptyset =: 3 : 'if. isboxed y do. y=a: else. isempty y end.'
> isdisjoint =: (-...@in) *. (-.@ (in~))
> 
> allsubsets =: 3 : 0    NB.  An explicit alternative to Raul's neat form.
> if. isemptyset y do. a:
>  else.
>  (#&y) &.> ( <"1 (#: i.2^#y))
> end.
> )


Fraser's conclusion:

> The big advantage of doing this is that constructing subsets subject to some 
> condition merely requires a function applied to each item in the list of 
> elements of the set.  Everything is just standard J.
> 
> Fraser


Dan's verbs:

    U       =:  ~.@:,
    N       =:  [ -. -.
    is      =:  -:&:(/:~)&:~.
    less    =:  -.
    isEmpty =:  -: 0&#

"This might be more convenient for your users, and might enjoy some performance 
benefits when the elements of a set are homogeneous & wouldn't need to be 
boxed."


Footnote:

The empty is a subset (not an element) of every set.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to