Re: Uniform design

*To*: mathgroup at smc.vnet.net*Subject*: [mg48289] Re: Uniform design*From*: Bill Rowe <readnewsciv at earthlink.net>*Date*: Fri, 21 May 2004 03:54:36 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

On 5/20/04 at 4:03 AM, ab_def at prontomail.com (Maxim) wrote: >Besides, there's a matter of 'optimizations' that Mathematica uses >for Sum (an issue which was discussed in this newsgroup a while >ago): >In[1]:= Module[{cnt = 0}, Sum[cnt += 1, {i, 10^6}] ] >Module[{cnt =0}, Sum[cnt += 1, {i, 10^6 + 1}] ] >Out[1]= 500000500000 >Out[2]= 1000001 Clearly, this is a bug. But consider In[1]:= Timing[Module[{cnt = 0}, Sum[cnt += 1, {n, 10^6}]]] Out[1]= {8.69*Second, 500000500000} In[2]:= Timing[Sum[n, {n, 10^6}]] Out[2]= {2.549999999999999*Second, 500000500000} In[3]:= Timing[Sum[n, {n, k}] /. k -> 10^6] Out[3]= {0.019999999999999574*Second, 500000500000} It seems to me far more natural to due either Sum[n, {n, 10^6}] or Sum[n, {n,k}]/.k->10^6 then what you've shown. Not only are these more natural, they are faster and avoid the bug. -- To reply via email subtract one hundred and four