Well, I'm going to give up the enclosing box for my sets. The displays are too
complicated.
Please try to "break" the revised proposal below. You can save it and do a
loadd.
Thanks. --Kip Murray
NB. SETS PROPOSAL
NB. INTRODUCTION
NB. A set is '' or a sorted list of boxes, with no duplicates.
NB. An element is the contents of a box in the list.
NB. A -: B tests whether set A is set B
NB. DEFINITION AND EXAMPLES
set =: [: /:~ ~. NB. create a set from a box or list of boxes
NB. Test whether y is a set:
isset =: ('' -: ]) +. [: *./ (-: /:~),(1 = #@$),(0<L.),(-: ~.)
NB. That is, a set is /''/ or a /sorted/ /list/ /of boxes/,
NB. /with no duplicates/.
]A =: set 'a';0;'a' NB. no duplicates; digits precede letters
]B =: set 'b';0;1
$ Empty =: set '' NB. empty set is an empty list
'' -: Empty NB. empty set is ''
isset <'a'
isset ,<'a'
isset Empty
NB. DEFINITIONS
un =: [: set , NB. union
mn =: -. NB. minus, remove elements of y from x
sd =: mn un mn~ NB. symmetric difference
nt =: un mn sd NB. Intersection
so =: ] -: un NB. tests whether x is a subset of y
cp =: [: set [: , {@(,&<)
NB. Cartesian product, adapted from CP in "Catalog {"
ps =: ( [: set ([: #: [: i. 2 ^ #) (<@#)"1 ] )`([: set <)@.('' -: ])
NB. power set of y
NB. EXAMPLES
]A
]B
A un B
A sd B
A nt B
A cp B NB. Some elements of the Cartesian product are sets, and some
B cp A NB. are not, because some are out of order and some have duplicates.
NB. The power set of a set is the set of all its subsets, one of which is '' .
NB. There are 2^#A subsets of A.
ps A NB. 4 subsets
ps set <'a' NB. 2 subsets
ps Empty NB. 1 subset
Sent from my iPad
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm