"Kip Murray" wrote: > 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:
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. 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. ) 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
