When are two J sets the same?  In mathematics two sets are the same if they 
have 
the same elements.  Specifically, sets H and K are the same if no element of H 
is not an element of K and no element of K is not an element of H.  (This 
negative way of putting it is needed when we compare 'abc' and 'bccaaa'.)

To test sameness we can use

    Set =: (/:~)@~.       NB. Fraser, sorted nub

    sortSet =: 3 : 0      NB. Fraser, recursive use of Set
s =. y
for_k. i. >: L. y do.   s =. Set L:k s end.
)
    boxel =: boxopen"_1   NB. box elements, boxopen from z locale and stdlib.ijs

    issameSet =: -:&boxel&sortSet   NB. Do "normal forms" match?

    ]H =: 'abc'
abc
    ]K =: 'bccaaa'
bccaaa
    H issameSet K
1

    ] a =: 2 2 3 $ i. 12
0  1  2
3  4  5

6  7  8
9 10 11

    ]b =: boxel a
+-----+-------+
|0 1 2|6  7  8|
|3 4 5|9 10 11|
+-----+-------+

    ]c =: |. a
6  7  8
9 10 11

0  1  2
3  4  5

    a issameSet b         NB. same elements, see Question 2 below
1
    a issameSet c
1
    b issameSet c
1

Can someone write a recursive use of boxel that boxes elements and elements of 
elements?  I don't _need_ it, I just want to _see_ it, especially when some 
elements are boxed and others are not.  Maybe I _do_ need it in place of boxel
to test sameness.  Haven't figured that out yet.


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.

Remember, for example, the elements of the power set of y are the arrays 
_inside_ the boxes of powSet y .


Kip
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to