Re: Re: programming problem about elements taken
- To: mathgroup at smc.vnet.net
- Subject: [mg72510] Re: [mg72497] Re: programming problem about elements taken
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Wed, 3 Jan 2007 05:16:32 -0500 (EST)
- References: <200612301039.FAA21673@smc.vnet.net><en82hd$6or$1@smc.vnet.net> <200701030603.BAA29747@smc.vnet.net>
On 3 Jan 2007, at 06:03, Ray Koopman wrote: > Andrzej Kozlowski wrote: >> Consider this list of 5 numbers: >> >> ls = Sort[Table[Random[], {5}]] >> {0.165874, 0.256035, 0.556211, 0.811305, 0.865799} >> Suppose we take epsilon = 0.3 and identify the numbers distant by >> less than that from one another. Then >> >> Union[ls, SameTest -> (Abs[#1 - #2] < 0.3 &)] >> {0.165874, 0.556211, 0.865799} >> gives us just three numbers. >> [...] >> Note that when two numbers are identified it is the smaller one that >> is kept. >> [...] > > Is this just an observation, or official-but-not-publicly-documented? > The arguments to SameTest seem always to be reverse-ordered (i.e., > #2 >= #1), even when the input list is unsorted, and the sequence of > argument pairs seems to be the same regardless of whether the input > list is sorted or unsorted. Can we conclude that Union sorts the input > list before using SameTest, and that when SameTest returns True it is > the second argument that is kept? > Yes, it is all true and actually I have known it fro a very long time, so it is probably documented (but I can't check that right now). Therefore there was no need to sort the list before running the code and SameTest could be simply (#2-#1<0.3&). I suppose I faield to think of that because I so used to working with spaces more general the just the real line. The code will work, I think, with a sequence of complex numbers (and Abs can even be replaced by Norm) where we identify them if they are less than espilon apart in the complex plane. I have never tested how fast it is; probably not very fast, since Union works much faster with the default value of SameTest (the same is true for Sort which is much slower with a user defined ordering function). Andrzej Kozlowski
- Follow-Ups:
- Re: Re: Re: programming problem about elements
- From: Daniel Lichtblau <danl@wolfram.com>
- Re: Re: Re: programming problem about elements
- References:
- Re: programming problem about elements taken
- From: "Ray Koopman" <koopman@sfu.ca>
- Re: programming problem about elements taken