Re: letrec/named let
- To: mathgroup at smc.vnet.net
- Subject: [mg56795] Re: letrec/named let
- From: Peter Pein <petsie at dordos.net>
- Date: Fri, 6 May 2005 03:00:07 -0400 (EDT)
- References: <d5csm5$m22$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Daniel Roy wrote: >> ...... >> >>Neither of these functions do what CompressNumericalSequence does... And >>because I'm no mathematica-guru I don't yet quite understand what they >>do, anyway. Furthermore, they are actually SLOWER than my code (see >>below on a test of 1,000,000 entries). >> >>dan >> >> >> Hello Dan, somehow the test got lost?! So I've run one on my machine (Win2k, 512MB Ram, AMD Athlon 64 3000+ @ 2GHz): In[1]:= $Version Out[1]= "5.1 for Microsoft Windows (October 25, 2004)" your original code: In[2]:=CompressNumericalSequence[S_] := Module[{C = Function[{C, R, i}, If[i < Max[R], If[Length[Position[R, i]] == 0, C[C, (If[#1 > i, #1 - 1, #1] & ) /@ R, i], C[C, R, i + 1]], R]]}, C[C, S, 1]]; my code: In[3]:= CNS[lst_] := Module[{tmp = First /@ Split[Sort[lst]]}, Flatten[(Position[tmp, #1] & ) /@ lst]] 2 things are missing: a supercomputer and patience. The test will run on only 10^5 elements. In[4]:= test = Table[Random[Integer, {1, 5000}], {100000}]; In[5]:= First[Timing[t1 = CompressNumericalSequence[test]; ]] >From In[5]:= $IterationLimit::itlim Iteration limit of 4096 exceeded. More... Out[5]= 25.25*Second We have to do a special setting to run your code In[6]:=Block[{$IterationLimit = Infinity}, First[Timing[t1 = CompressNumericalSequence[test]; ]]] Out[6]= 93.375*Second In[7]:= $IterationLimit (* is 4096 again *) Out[7]= 4096 In[8]:= First[Timing[t2 = CNS[test]; ]] Out[8]= 15.407*Second test the equality of the results: In[9]:= t1 == t2 Out[9]= True Well, I see: it's SLOWER, the result is completely different and I don't have to tweak Mathematica's default settings to run it at all. These are three major disadvantages. Sorry for bothering you, Peter