RE: data structure for sets

*To*: mathgroup at smc.vnet.net*Subject*: [mg35593] RE: [mg35566] data structure for sets*From*: "David Park" <djmp at earthlink.net>*Date*: Sun, 21 Jul 2002 01:01:13 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

Bob, Here is one approach. Attributes[set] = {Orderless}; set[d, e, f, a, b, c] gives set[a, b, c, d, e, f] For some test data... set1 = set[d, e, f, g]; set2 = set[a, b, c, d, e]; set12 = Union[set1, set2] set[a, b, c, d, e, f, g] Here are the SubsetQ and SubsetEqualQ routines. (The real mathematicians will probably have to check if I've captured all the subtleties of sets.) SubsetQ::usage = "SubsetQ[set1, set2] returns True if set1 is a subset of set2."; SubsetQ[set1_set, set2_set] := Intersection[set2, set1] === set1 || set1 === set[]; SubsetEqualQ::usage = "SubsetEqualQ[set1, set2] returns True if set1 is equal to set2."; SubsetEqualQ[set1_set, set2_set] := SubsetQ[set1, set2] && SubsetQ[set2, set1]; SubsetQ[set[a], set1] False SubsetQ[set[a, d, c], set12] True SubsetQ[set[], set12] True SubsetEqualQ[set[e, d, g, f], set1] True SubsetEqualQ[set[d, e, f], set1] False David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Robert B. Nachbar [mailto:nachbar at merck.com] To: mathgroup at smc.vnet.net Has anyone implemented a data structure for sets that has the Attribute Orderless and automatically deletes duplicate elements or else ignores them when using Equal or SameQ? Functions such as SubsetQ and SubsetEqualQ would also be helpful. Thanks, Bob