MathGroup Archive 1997

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

Search the Archive

Re: Re: How to select unique elements in a list?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8084] Re: [mg8058] Re: [mg8041] How to select unique elements in a list?
  • From: Allan Hayes <hay at haystack.demon.co.uk>
  • Date: Tue, 5 Aug 1997 03:22:54 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Begin forwarded message:
"w.meeussen" <meeussen.vdmcc at vandemoortele.be>
in [mg8058] Re: [mg8041] Re: [mg7953] How to select unique elements  
in a list?
writes as below ******

Wouter:
There is almost always some possibility for speed up.
Here is another method  - following Fred Simons' idea - and the timings

(a1 = DeleteCases[List@@Times@@test,_Power]);//Timing (*Fred*)

	{1.40619 Second,Null}

(a2 = DeleteCases[List@@Plus@@test,_Times]);//Timing (*variant*)

	{0.421875 Second,Null}

(a3 =Join@@Cases[Split[Sort[test]],{_}]);//Timing (*several  
postings used Split and Sort*)

	{0.390667 Second,Null}

Check

a1==a2 ==a3

	True
	
There is, of course a problem with the use of Times and Plus - they  
depend on not having conversions like 2 *3 to 6 and 2+3 to 5 for  
the given test.
This could be worked around by using k/@test.

Allan

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

****************
Begin forwarded message:

From: "w.meeussen" <meeussen.vdmcc at vandemoortele.be>
To: mathgroup at smc.vnet.net
Subject: [mg8084] [mg8058] Re: [mg8041] Re: [mg7953] How to select unique  
elements in a list?

at this point it starts to get generally interesting beyond the  
original scope:

how are we (users) to get a feeling for efficiency of operations,  
given that
a Times[sequence_of_args] evaluates sooo much faster than a
List[sequence_of_args]?
By any measure, List feels more 'basic' than Times, not being commutative
and all.

Can we ever be shure that noone will come up with a gimmick that  
increases
the speed even further?

Amazed,
as always,

wouter.


At 22:32 2-08-97 -0400, Fred Simons wrote:
>Carl Woll came with the following solution of his problem:
>
>Distinct[a_]	:= Select[Union[a],Count[a,#]===1&]
>
>Here is another solution, a short and (for me) amusing oneliner:
>
>Distinct2 = List @@ DeleteCases[ Times @@ #, _Power ]&
>
>It is also faster:
>
>test	= Table[i[Random[Integer,1000]],{1000}];
>
>In[9] := Distinct[test]; // Timing
>
>Out[10] = {12.5586 Second,Null}
>
>In[11] := Distinct2[test]; // Timing
>
>Out[11] = {1.43735 Second, Null}
>
>Fred Simons
>Eindhoven University of Technology
>
>
>
>

Dr. Wouter L. J. MEEUSSEN
eu000949 at pophost.eunet.be
w.meeussen.vdmcc at vandemoortele.be




  • Prev by Date: Re: inverse command of Series[]
  • Next by Date: Re: Combining ListPlots
  • Previous by thread: Re: How to select unique elements in a list?
  • Next by thread: Re: How to select unique elements in a list?