I see what you mean by this, and the usefulness--I presented to math club a set with elements earth, air, water, and fire--but in general it is necessary to distinguish sets from regular arrays that happen to be boxed. This is really a call based on the individual application, and my choice of the adjective "proper" is a bit like the same word used on fractions...
Marshall -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Kip Murray Sent: Sunday, October 10, 2010 6:15 PM To: Programming forum Subject: Re: [Jprogramming] Sets In my model the verb isset tells which arrays are allowed to be sets. Every array is permitted to be an element, for example set 'abc';(i. 2 4);17 ┌──┬───────┬───┬┐ │17│0 1 2 3│abc││ │ │4 5 6 7│ ││ └──┴───────┴───┴┘ One of my teachers said, you can have a set whose elements are an elephant, a bumblebee, and the color blue: anything can be an element. Here, any array can be an element, all elements must be boxed, and no set is "improper"! On 10/10/2010 3:22 PM, Marshall Lochbaum wrote: > To avoid confusion, every element that has rank greater than 0 should > probably be boxed. Then any element that is a list must be a set. Of course > you might want to modify this depending on what you are actually doing. > > Then we have > isproperset=: isset *. [: *./ 1:`is...@.(#...@$) :: 0: @> > > Marshall > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Henry Rich > Sent: Sunday, October 10, 2010 3:14 PM > To: Programming forum > Subject: Re: [Jprogramming] Sets > > How about > > less =: a: ,~ -. > > isset should, I suppose, test whether a set is well-formed. In that case > wouldn't it need to look inside elements to see that they are well-formed? > > Can an element of a set be a non-set box? Is the idea that contents that are > not lists, or not boxed, or perhaps either, represent contents that are not > sets? > > Henry Rich > > On 10/10/2010 12:01 AM, Kip Murray wrote: >> Here is my latest attempt to model set theory in J. All sets have >> distinct elements and are ordered by /:~ so that match -: determines >> whether two sets are the same. Sets must be created by the verb set >> or by provided operations. The intention is theoretical not >> practical! --Kip Murray >> >> ]A =: set 0;'b';2 NB. elements 0 'b' 2 are put in boxes >> preceding the last ┌─┬─┬─┬┐ │0│2│b││ └─┴─┴─┴┘ >> ]B =: set 2;'b';'b';0 NB. same elements so same set ┌─┬─┬─┬┐ >> │0│2│b││ └─┴─┴─┴┘ >> >> A -: B >> 1 >> >> ]C =: set 2;'b';'c';'d' >> ┌─┬─┬─┬─┬┐ >> │2│b│c│d││ >> └─┴─┴─┴─┴┘ >> >> B sand C NB. intersection, "set and" >> ┌─┬─┬┐ >> │2│b││ >> └─┴─┴┘ >> B sor C NB. union >> ┌─┬─┬─┬─┬─┬┐ >> │0│2│b│c│d││ >> └─┴─┴─┴─┴─┴┘ >> >> (A sand B sor C) -: (A sand B) sor (A sand C) NB. distributive >> law >> 1 >> >> pwrset A NB. A has 3 elements, power set has 2^3, including the >> empty set ┌──────┬────────┬────┬──────┬────┬──────┬──┬────┬┐ >> │┌─┬─┬┐│┌─┬─┬─┬┐│┌─┬┐│┌─┬─┬┐│┌─┬┐│┌─┬─┬┐│┌┐│┌─┬┐││ >> ││0│2││││0│2│b││││0││││0│b││││2││││2│b│││││││b││││ >> │└─┴─┴┘│└─┴─┴─┴┘│└─┴┘│└─┴─┴┘│└─┴┘│└─┴─┴┘│└┘│└─┴┘││ >> └──────┴────────┴────┴──────┴────┴──────┴──┴────┴┘ >> NB. Elements are contained in boxes preceding the last which is always >> NB. the Boxed Empty a: (Ace). The use of a: permits a unique and >> visible >> NB. empty set, viz >> >> (,a:) -: E =: A less A NB. see verb less below >> 1 >> E >> ┌┐ >> ││ >> └┘ >> a: >> ┌┐ >> ││ >> └┘ >> E -: a: >> 0 >> >> NB. Definitions >> >> E =: ,a: NB. empty set >> set =: a: ,~ [: /:~ ~. NB. create set from boxed list y >> NB. each box of y encloses an element >> get =: { }: NB. get boxed elements (from curtail because >> NB. elements are inside boxes of curtail) >> isin =: e. }: NB. Do boxes in list x contain elements of y? >> less =: a: ,~ -.&}: NB. remove elements of y from x >> sand =: [ less less NB. intersection, "set and" >> sor =: a: ,~ [: /:~ [: ~. ,&}: NB. union, "set or" >> diff =: less sor less~ NB. symmetric difference >> card =: [: # }: NB. count elements: cardinality >> issubs =: [ -: sand NB. Is x a subset of y? >> pwrset =: a: ,~ [: /:~ ] (<@#~) 1 (,~"1) 2 (#"1~ {:)@#:@i...@^ #...@}: >> NB. pwrset by Raul Miller, adapted >> islist =: 1 = #...@$ NB. islist through isunique from validate.ijs >> isboxed =: 0< L. >> issorted =: -: /:~ >> isunique =: -: ~. >> isset =: islist *. isboxed *. (a: -: {:) *. issorted@:}: *. isunique@:}: >> NB. isset y asks, is array y a set? >> iselement =:<@[ isin ] NB. Is array x an element of set y? >> >> NB. End >> >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
