Re: Union & precision <<take 2>>

• To: mathgroup at smc.vnet.net
• Subject: [mg8706] Re: [mg8627] Union & precision <<take 2>>
• From: Allan Hayes <hay at haystack.demon.co.uk>
• Date: Fri, 19 Sep 1997 02:47:47 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```Gadi Oron <oron at manet.pmmh.espci.fr>
[mg8627] Union & precision <<take 2>>
Wrote as below the line ***********

Here are two possible alternative - though they does not use your test.

lst ={Circle[{0.192450089729875202`,0.277777777777777767`},
0.0555555555555555535`],
Circle[{0.192450089729875202`,0.722222222222222232`},
0.0555555555555555535`],
Circle[{0.192450089729875308`,0.277777777777777901`},
0.0555555555555555802`]};

(1)
Union[lst/.x_Real:>0.00001 Round[10000 x]]

{Circle[{0.19245,0.27778},0.05556],
Circle[{0.19245,0.72222},0.05556]}

(2) This gives the original forms

Last/@Union[{#/.x_Real:>0.00001Round[100000x],#}&/@lst,
SameTest->(#[[1]]===#2[[1]]&)]

{Circle[{0.19245,0.277778},0.0555556],
Circle[{0.19245,0.722222},0.0555556]}

The problem with testing for sameness being between adjacent
entries after sorting (Carl Woll,[mg8669] ) shows up simply in

Union[{1[2],3[2],2[1]}, SameTest ->(#1[[1]]===#2[[1]]&)]

{1[2],2[1],3[2]}

Allan Hayes
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk/training.html
voice:+44 (0)116 2714198
fax: +44 (0)116 2718642
Leicester,  UK

************

Hello again,

This is the second chapter im my adventure of trying to use Union taking
into account the precision.

As suggested by the replies to my last message (thanx) the use of
SameTest-> testfunc should do the thing.

Since my sets contain only one of the two structures
"eline[{x1,y1},{x2,y2}]" and "Circle[{x,y},r]" I wrote the following:

pre=10^(-4);
norm[v_List]:=Sqrt[v.v];

Clear[test];

test[lhs_Circle,rhs_Circle]:=
(norm[lhs[[1]]-rhs[[1]]]<pre && Abs[lhs[[2]]-rhs[[2]]]<pre );

test[lhs_eline , rhs_eline]:=
(norm[lhs[[1]]-rhs[[1]]]<pre && norm[lhs[[2]]-rhs[[2]]]<pre);

test[lhs_,rhs_]:=TrueQ[(lhs==rhs)];

Now, it seems to work all right: Check :

test[Circle[{0.192450089729875202`,0.277777777777777767`},
0.0555555555555555535`],
Circle[{0.192450089729875308`,0.277777777777777901`},
0.0555555555555555802`]]

Gives : True.

Also :

Union[{Circle[{0.192450089729875202`,0.277777777777777767`},
0.0555555555555555535`],
Circle[{0.192450089729875308`,0.277777777777777901`},
0.0555555555555555802`]},SameTest->test]

Gives (right):

{Circle[{0.19245,0.277778},0.0555556]}

But (surprise):

Union[{Circle[{0.192450089729875202`,0.277777777777777767`},
0.0555555555555555535`],
Circle[{0.192450089729875202`,0.722222222222222232`},
0.0555555555555555535`],
Circle[{0.192450089729875308`,0.277777777777777901`},
0.0555555555555555802`]},SameTest->test]

Gives (!!) :

{Circle[{0.19245,0.277778},0.0555556],Circle[{0.19245,0.722222},0.0555556],
Circle[{0.19245,0.277778},0.0555556]}

Notice that the set is not well ordered and that we have 2 of the
element equal by the SameTest.

What is going wrong??

Thank you.

P.S. Sorry for the illisibility, I have put in the full form of the
numbers in order to show the precision.

| EMAIL :  oron at pmmh.espci.fr   ::::     oron at clipper.ens.fr  |
| Homepage : http://pmmh.espci.fr/~oron/personal.html         |
| fido : 2:325/302.8                                          |
| 		  Soyez braves - be brave.                    |
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

```

• Prev by Date: Notebook Styles
• Next by Date: Re: matrix
• Previous by thread: Re: Union & precision <<take 2>>
• Next by thread: Question on Mathematica Signal Processing Packages 2.9.5