MathGroup Archive 2011

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

Search the Archive

Re: reliably sort?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123740] Re: reliably sort?
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Sat, 17 Dec 2011 02:42:43 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jca06e$a35$1@smc.vnet.net> <201112150956.EAA23025@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

> Result of a Union is a set. Hence one can not talk about
> a set being sorted.  The result is not a set then, but a
> sequence, but the result of a Union should be a set.

a) But Union results ARE sorted. Don't pretend they're not:

Union[RandomInteger[{1, 10}, 20]]

{1, 2, 3, 5, 6, 7, 8, 9}

b) Here are two examples you might not have considered:

Union[f[a, b, a]]

f[a, b]

Union[f[a, b, a], f[c, a]]

f[a, b, c]

No sets there... and not even lists.

c) At school, when he talked about sets, the MATH teacher was not talking  
about computer languages.

d) Generally, we have lists and the functions that act on them. If lists  
have no duplicates, call them sets if you WANT to, but they don't act like  
sets unless you use functions that treat them like sets. For instance,  
does Joining sets give sets???

Join[{a, b, c}, {a}]

{a, b, c, a}

Oops, no.

e) Union, Intersection, and Complement may be the only built-in functions  
that eliminate duplicates in creating outputs... and they don't have to  
have "sets" (lists without duplicates) as their arguments.

Union[List[a, b, a], List[c, a]]

{a, b, c}

f) Union, Intersection, and Complement are not implemented to take  
advantage of the special properties of sets. Union, for instance, Joins  
lists and THEN deletes duplicates. Set theoretic packages exist that do it  
differently, so that duplicates are not created in the first place.

g) Hence, I'll repeat that Mathematica has no "sets". (As distributed.)

Bobby

On Fri, 16 Dec 2011 04:49:18 -0600, Nasser M. Abbasi <nma at 12000.org> wrote:

> On 12/15/2011 2:44 PM, DrMajorBob wrote:
>> Michael,
>>
>> Sorry, but no. Union always sorts.
>>
>> Bobby
>>
>
> You mean Mathematica's Union[] always sorts, right? Because
> at school the teacher kept telling us that a set has no
> implied order between its elements. It is just a collection
> of elements. But a sequence has an order.
>
> Result of a Union is a set. Hence one can not talk about
> a set being sorted.  The result is not a set then, but a
> sequence, but the result of a Union should be a set.
>
> --Nasser
>
>
>


-- 
DrMajorBob at yahoo.com



  • Prev by Date: Re: Elementary Document Formatting Questions
  • Next by Date: Re: Mathematica LogPlot Bug
  • Previous by thread: Re: reliably sort?
  • Next by thread: Re: reliably sort?