MathGroup Archive 1997

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

Search the Archive

Re: Q : Lists as sets.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg7854] Re: [mg7810] Q : Lists as sets.
  • From: "C. Woll" <carlw at u.washington.edu>
  • Date: Thu, 17 Jul 1997 02:01:36 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

On Sat, 12 Jul 1997, Gadi Oron wrote:

> Hi there,
> 
> I want to use a list as a mathematical set. How can I do that? (Nothing in
> the MMA book).
> 
> I found one (not elegant) way to do it : Allways do set=Union[list] but
> that is really ugly.
> 
> Any ideas?
> 

Hi Gadi,

Here is one technique, with f being the head of the set.

b:a_f:=Sort[Unevaluated[b]]/;!OrderedQ[Unevaluated[b]]
b:a_f:=Union[Unevaluated[b]]/;(Signature[Unevaluated[b]]==0)

You need the Unevaluated wrapper to prevent infinite recursion. Note that
this definition is much faster than the following somewhat more intuitive
one.

SetAttributes[f,{Orderless,Flat,OneIdentity}]
f[a_,a_]:=f[a]

Carl Woll




  • Prev by Date: Re: Print symbol value on plot
  • Next by Date: Re: Question on Positive[x]=True
  • Previous by thread: Q : Lists as sets.
  • Next by thread: Re: Q : Lists as sets.