Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Uniform design

  • To: mathgroup at
  • Subject: [mg48289] Re: Uniform design
  • From: Bill Rowe <readnewsciv at>
  • Date: Fri, 21 May 2004 03:54:36 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

On 5/20/04 at 4:03 AM, ab_def at (Maxim) wrote:

>Besides, there's a matter of 'optimizations' that Mathematica uses
>for Sum (an issue which was discussed in this newsgroup a while

>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

Timing[Module[{cnt = 0}, Sum[cnt += 1, {n, 10^6}]]]

{8.69*Second, 500000500000}

Timing[Sum[n, {n, 10^6}]]

{2.549999999999999*Second, 500000500000}

Timing[Sum[n, {n, k}] /. k -> 10^6]

{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

  • Prev by Date: Home Page of Marek Rychlik--> Mathematica creations
  • Next by Date: RE: proof of formula for log(-t) found in Mathematica?
  • Previous by thread: Re: Uniform design
  • Next by thread: Re: Uniform design