how implement sets
- To: mathgroup at smc.vnet.net
- Subject: [mg41511] how implement sets
- From: Murray Eisenberg <murraye at attbi.com>
- Date: Fri, 23 May 2003 03:29:33 -0400 (EDT)
- Organization: Mathematics & Statistics, Univ. of Mass./Amherst
- Reply-to: murray at math.umass.edu
- Sender: owner-wri-mathgroup at wolfram.com
Mathematica has no built-in data type for sets in the mathematical sense
(no implied order of elements). This is to ask your advice in how in
Mathematica to implement sets, for use in teaching math, where the
distinction between an "ordered set" and just a plain "set" is crucial.
Inherently, lists in Mathematica have an order, so List itself certainly
cannot be the correct thing to use. Here are two possibilities:
(1) A set is a list with no repeated parts. Then a function SetQ is
needed to test that. Obvious definition:
SetQ[x_] := ListQ[x] && Length[Union[x]] == Length[x]
(2) Create a new "datatype" by using an appropriately-named head, such
as -- WHAT? Mathematica has already appropriated the word Set for
something else, of course. Perhaps Class or Collection? (And then
overload Union, Intersection, Complement so they do what they should
with such objects.)
Any thoughts on which might be preferable, or on some other way?
--
Murray Eisenberg murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305