       Re: logical inconsistency in Union

• To: mathgroup at smc.vnet.net
• Subject: [mg13126] Re: [mg13069] logical inconsistency in Union
• From: Daniel Lichtblau <danl>
• Date: Tue, 7 Jul 1998 03:44:30 -0400
• References: <199807042045.QAA02915@smc.vnet.net.>
• Sender: owner-wri-mathgroup at wolfram.com

```Veit Elser wrote:
>
> 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:= (* 3 points in the plane *)
> a={1,1};
> b={1.2,1};
> c={1.1,2};
>
> In:= (* 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:=
> approxSame[a,b]
>
> Out=
> True
>
> In:=
> approxSame[a,c]
>
> Out=
> False
>
> In:=
> Union[{a,b,c},SameTest->approxSame]
>
> Out=
> {{1,1},{1.1,2},{1.2,1}}     (* incorrect result ! *)
>
> In:=
> Union[{a,b},SameTest->approxSame]
>
> Out=
> {{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

I do not think overriding the ordering would help in cases where the
user-provided SameTest does not give a canonical ordering. About all
that can be done for Union et al is a brute-force comparison of every
candidate element with all elements already in the set under
construction.

This problem was noted by several people at the recent Worldwide
Mathematica Conference. I fixed it in our development version.

In:= Union[{a,b,c},SameTest->approxSame] Out= {{1, 1}, {1.1, 2}}

Daniel Lichtblau
Wolfram Research

```

• Prev by Date: Re: How to declare Integers?
• Next by Date: Re: Restrict domain of Plot3D[]?
• Previous by thread: logical inconsistency in Union
• Next by thread: Re: logical inconsistency in Union