MathGroup Archive 2010

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

Search the Archive

Re: Peculiar output from Union ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108524] Re: Peculiar output from Union ?
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Sun, 21 Mar 2010 02:08:05 -0500 (EST)

This is platform-independent and totally predictable!

Ordinarily, Union is used to form the union of two lists.  But the two 
arguments  1<  x<  2  and   3<  x<  5  are not lists. Rather, they are 
abbreviations for the following two expressions each of whose heads is Less:

   Less[1,x,2]   and   Less[3,x,5]

If you look at the Documentation Center page for Union, under the 
section Generalizations & Extensions you'll read that "Union works with 
any head, not just List."  And you'll see the example:

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

Evidently what Union does in such circumstances is form the Union of the 
list of all the arguments supplied to each instance of the function f 
inside.  That would mean, then:


   Union[f[a, b, c], f[u, v, w]]
f[a, b, c, u, v, w]

Next, remember that the result of Union uses the canonical order for the 
elements of a list, so that, e.g.:

   Union[{a, z, b, 2, b, z}]
{2, a, b, z}

Then -- and here we're getting close to the example you asked about -- 
we predict the result:

   Union[f[a, x, c], f[d, x, e]]
f[a, c, d, e, x]

Now take f to be Less:

   Union[Less[a, x, c], Less[d, x, e]]
a < c < d < e < x

That's because:

   FullForm[%]
Less[a,c,d,e,x]

In other words, this example with Less is just a special case of a 
general head f.

I deliberately used literal arguments a, c, e, e in that order, because 
when they are sorted into canonical order, it comes out as a,c,d,e; and 
then when you throw in x, it comes last.

Finally, replace a with 1, b with 2, c with 3, and d with 5.  Then the 
result you should expect from

    Union[Less[1, x, 2], Less[3, x, 5]]

would be Union[1, 2, 3, 5, x], and that immediately evaluates to 5 < x, 
which is what you got.

Perhaps you expected, instead, something like 1<x<2 || 3<x<5. But that 
would be the result not of a Union, but rather of an Or:

   Or[1<x<2,3<x<5]

Were you conflating inequalities with the corresponding sets?

On 3/20/2010 3:46 AM, Jack L Goldberg 1 wrote:
> Hi Folks,
>
> Can anyone explain this:
>
> In[1]:= Union[  1<  x<  2, 3<  x<  5  ]
>
> Out[1]= 5<  x
>
> ??
>
> I am using a MacBook Pro, OS 10.6.2
>
> Thanks,
>
> Jack
>

-- 
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


  • Prev by Date: Mathematica SIG (Washington DC Area)
  • Next by Date: Re: Peculiar output from Union ?
  • Previous by thread: Re: Peculiar output from Union ?
  • Next by thread: Re: Peculiar output from Union ?