MathGroup Archive 2010

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

Search the Archive

Re: Peculiar output from Union ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108526] Re: Peculiar output from Union ?
  • From: Jack L Goldberg 1 <jackgold at umich.edu>
  • Date: Sun, 21 Mar 2010 02:08:28 -0500 (EST)

Hi Folks,

Thanks to all for pointing out the way to examine the issue I raised.  
I know that many operations that work for lists also work form more  
general heads and therefore one must look closely in cases where the  
operation is applied to objects other than lists. Unfortunately, I was  
led astray (as Murray wisely pointed out) because the answer looked  
like Mathematica was doing a "peculiar union" of sets. One more  
example of life's humbling experiences.

Jack



Quoting Murray Eisenberg <murray at math.umass.edu>:

> 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: Re: Peculiar output from Union ?
  • Next by Date: Re: Passing options to functions / overriding default
  • Previous by thread: Re: Peculiar output from Union ?
  • Next by thread: Re: Peculiar output from Union ?