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

MathGroup Archive 1998

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

Search the Archive

logical inconsistency in Union

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13069] logical inconsistency in Union
  • From: Veit Elser <ve10 at cornell.edu>
  • Date: Sat, 4 Jul 1998 16:45:09 -0400
  • Organization: Cornell University
  • Sender: owner-wri-mathgroup at wolfram.com

The Union function gives logically inconsistent results when used with
certain SameTest rules. The problem is that the argument of Union is
first sorted into Mathematica's canonical order, which may be
inconsistent with the supplied SameTest. Here's an innocent example of
the problem:
 

In[1]:= (* 3 points in the plane *)
a={1,1};
b={1.2,1};
c={1.1,2};

In[2]:= (* rule which says two points are the same if each coordinate
differs by at most 0.5 *)
approxSame[x_,y_]:=Round[x-y]=={0,0}

In[3]:=
approxSame[a,b]

Out[3]=
True

In[4]:=
approxSame[a,c]

Out[4]=
False

In[5]:=
Union[{a,b,c},SameTest->approxSame]

Out[5]=
{{1,1},{1.1,2},{1.2,1}}     (* incorrect result ! *)

In[7]:=
Union[{a,b},SameTest->approxSame]

Out[7]=
{{1,1}}    (* correct result *)
 

To fix this problem we have to be allowed to modify the ordering
function used by Union in order to be consistent with SameTest. An even
better solution would be to be able to overide Mathematica's Order
function (which returns -1,0,1). This would accomplish both: a
consistent rule for sorting and a criterion to decide if two elements
are the same.

This problem affects other set theoretic functions as well (e.g.
Complement).
 
 

-Veit



  • Prev by Date: Re: Importing external grid file to do contour plot
  • Next by Date: Int.
  • Previous by thread: Re: Importing external grid file to do contour plot
  • Next by thread: Re: logical inconsistency in Union