Prev: Docked cells and TagBoxNote / StatusArea
Next: OneStepTopReduction in System` Context in Mathematica 6+?
From: Carl K. Woll on 21 Mar 2010 03:08 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 > > ?? > > The FullForm is: Union[ Less[1, x, 2], Less[3, x, 5] ] which evaluates to: Less[1, 2, 3, 5, x] because that's the way Union works for any head. Usually the head is List, not Less. From the help: The Subscript[list, i] must have the same head, but it need not be List. The above Less expression evaluates to Less[5, x] Carl Woll Wolfram Research > I am using a MacBook Pro, OS 10.6.2 > > Thanks, > > Jack > >
From: Tomas Garza on 21 Mar 2010 03:08 Yes. The argument of Union must be a list (see DocCenterHelp). Check: In[1]:== Union[{1<x<2,3<x<5}] Out[1]== {1<x<2,3<x<5} as it should. Tomas > Date: Sat, 20 Mar 2010 02:46:52 -0500 > From: jackgold(a)umich.edu > Subject: Peculiar output from Union ? > To: mathgroup(a)smc.vnet.net > > 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 >
From: Murray Eisenberg on 21 Mar 2010 03:08 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(a)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
From: Bill Rowe on 21 Mar 2010 03:08 On 3/20/10 at 2:46 AM, jackgold(a)umich.edu (Jack L Goldberg 1) wrote: >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 The result you get using Trace to see what happens, i.e., In[2]:= Union[1 < x < 2, 3 < x < 5] // Trace Out[2]= {HoldForm[Union[1 < x < 2, 3 < x < 5]], HoldForm[1 < 2 < 3 < 5 < x], HoldForm[5 < x]} shows what is going on. Perhaps you want something more like In[3]:= IntervalUnion[Interval[{1, 2}], Interval[{3, 5}]] Out[3]= Interval[{1,2},{3,5}]
From: Jack L Goldberg 1 on 21 Mar 2010 03:08 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(a)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(a)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 > > >
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Docked cells and TagBoxNote / StatusArea Next: OneStepTopReduction in System` Context in Mathematica 6+? |