Fraser, sortSet is beautiful.
isSet =: -:&sortSet
(powSet 'abcd') isSet powSet 'bdca'
1
'abcd' isSet 'bdcaa'
1
Revision:
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.
About creating new data objects, I plead guilty, especially if you are
referring
to my response to Raul's puzzle.
Kip
Fraser Jackson wrote:
> Kip,
>
> You seem to keep wanting to create new data objects when I do not believe
> they are necessary.
>
> In J it is perfectly possible to have a sequence and a set having exactly
> the same representation. A lot of set theory is concerned with sequences.
> They may be sequences of atoms, or sequences of sets. Having set verbs and
> sequence verbs operating on these objects is the direction I would go. That
> means of course that the order of items in the list of elements may matter.
>
> At an earlier stage in this discussion you suggested that it would be
> difficult to sort elements and test identity in sets of sets if the elements
> were not in a standard order.
>
> I think the following function will achieve that by sorting into a J sort
> order. That provides a standard form to simplify testing. Raul might
> provide a tacit form.
>
> sortSet =: 3 : 0
> s =. y
> for_k. i. >: L. y do. s =. Set L:k s end.
> )
>
> The following gives an example of what it does - you need to copy and
> execute it to see its results - my mailer seems to really mishandle boxing.
>
> s1 =: 'bdca'
> s2 =: powSet s1
> s2a =: 0 13 3 6 {s2
> s2b =: 1 13 5 2 {s2
> s3a =: 2 5 9 13 { powSet s2a
> s3b =: 2 5 9 13 { powSet s2b
>
> sc =: |. s1;s2a;<s3a
> sd =: |. s1;s2b;<s3b
>
> sc
> sortSet sc
> sd
> sortSet sd
>
> You can get other results by converting sortSet to a dyadic verb and
> specifying the levels at which sorting will be done.
>
> Fraser
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm