Re: how implement sets
- To: mathgroup at smc.vnet.net
- Subject: [mg41558] Re: how implement sets
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Mon, 26 May 2003 05:46:35 -0400 (EDT)
- Organization: Universitaet Leipzig
- References: <bakj7u$l8h$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
create a new expression type and you can benefit from
the Oderless arrtibute, and Mathematica will sort the
arguments by default.
Remove[MathematicalSet]
SetAttributes[MathematicalSet, Orderless]
MathematicalSet[a__] /; Length[Split[{a}]] =!= Length[{a}] :=
MathematicalSet @@ (First /@ Split[{a}])
Regards
Jens
Murray Eisenberg wrote:
>
> 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