MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: data structure for sets

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


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]

SubsetQ[set[a, d, c], set12]

SubsetQ[set[], set12]

SubsetEqualQ[set[e, d, g, f], set1]

SubsetEqualQ[set[d, e, f], set1]

David Park
djmp at

From: Robert B. Nachbar [mailto:nachbar at]
To: mathgroup at

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.



  • Prev by Date: Re: Pattern Matching in Lists
  • Next by Date: Re: Simplified Integration Problem
  • Previous by thread: data structure for sets
  • Next by thread: Mathematica and Gauss