MathGroup Archive 1997

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

Search the Archive

RE: Q: Union and precision.

Oron wrote:
|How can I force Union to consider numbers equal in the current
|precision as equal? Explanation:
|In:=     a=SetPrecision[1.234567,2]
|Out:=    1.2
|In:=     b=SetPrecision[1.234561,2]  (* Notice difference *)
|Out:=    1.2
|In:=     a==b
|Out:=    True
|In:=     Union[{a,b}]
|Out:=    {1.2,1.2} (* !!! *)
|How does Union evaluates equalities? How can I force it to do it the right
Union uses the setting for the SameTest Option to determine if two elements
are "equal".   By default it uses SameTest->Automatic.
However, I don't know exactly what this does.

You will get the results you want if you use the following:

In:=  Union[ {a,b}, SameTest->Equal ]
Out= {1.2}

Even better. you can add a line in your init.m file,
and Union will always have the default (SameTest->Equal).
Well first you have to restart Mathematica using the new init.m.

Here is what you add to init.m.
SetOptions[ Union, SameTest->Equal ]

Ted Ersek

  • Prev by Date: Re: importing images
  • Next by Date: Re: Q: Union and precision.
  • Previous by thread: Q: Union and precision.
  • Next by thread: Re: Q: Union and precision.