       Re: Intersection[...,SameTest] ?

• To: mathgroup at smc.vnet.net
• Subject: [mg33103] Re: Intersection[...,SameTest] ?
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Sun, 3 Mar 2002 06:30:25 -0500 (EST)
• References: <a5htcj\$hsk\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```The problem is how to get the result we expect from
Intersection[lst1, lst2, ...., SameTest->test]
In my earlier posting I replaced test with an explicit reflexive, symmetric,
transitive extension ( that is its equivalence extension).
It would be better if we could find a generalt method that let Mathematica
do most of the work - I have come up against some difficulties in trying to
do this.

To try things out set
a = {1, 6, 0, 0, 8};
b = {3, 8, 0, 0};

Jens-Peer Kuska suggested making the test symmetric

Intersection[a, b, SameTest ->
(If[#2 < #1, #1 === 2*#2, #2 === 2*#1] & )]

{0,0,6}

The 8 does not appear because the test is not reflexive.
This is easily dealt with -- but here is a different form.

tst2 = #1 == #2 || #1 == 2*#2 || 2*#1 == #2 & ;

Intersection[a, b, SameTest -> tst2]

{0,0,6,8}

We still need to remove the repeated 0.

Union[%, SameTest -> tst2]

{0,6,8}

This suggests that a general method might be:
Given test to define the reflexive symmetric extension  rstest by

rstest[x_, y_] := x == y || test[x, y] || test[y, x]

and leave Mathemtica to, in effect, make this transitive

Unfortunately, it turns out that Mathematica still does not cope with this.
Consider

test[x_, y_] := x == 2*y || x == 3*y;

rstest[x_, y_] := x == y || test[x, y] || test[y, x]

Intersection[{3, 2, 6}, {3, 2, 6}, SameTest -> rstest]

{2,3,6}
We would expect only one member.
Try

Union[%, SameTest -> rstest]

{2,3}

Repeat

Union[%,SameTest->rstest]

{2,3}

A generall difficulty illustrated by Union[{2,3},SameTest->rstest] is that
the linking 6 the gives 2 ~6 and 3~6, whence 2~3 is not available.

--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

```

• Prev by Date: something fishy in mathematica random generation?
• Next by Date: Re: A question about summation indicies
• Previous by thread: Re: Intersection[...,SameTest] ?