Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1997
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1997

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

Search the Archive

RE: Q: Union and precision.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8548] RE: [mg8529] Q: Union and precision.
  • From: Ersek_Ted%PAX1A at mr.nawcad.navy.mil
  • Date: Sat, 6 Sep 1997 23:16:15 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

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
|way??
|
|
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.