Re: unexpected behaviour of Sum
- To: mathgroup at smc.vnet.net
- Subject: [mg126500] Re: unexpected behaviour of Sum
- From: Dana DeLouis <ng201005 at me.com>
- Date: Tue, 15 May 2012 04:53:57 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
> Sum[sod[k],{k,1+10^6}] which gives 500001500001 (nonsense). Hi. I don't have an answer, but the nonsense number looks to me like it skipped the function, and just added the Ks 1/2 n (1+n) /.n -> 1+10^6 500001500001 Don't have an answer, but bypassing the function seems to work. Sum[Plus@@IntegerDigits[j],{j,1+10^6}] 27000003 Just interesting: digits 0 thru 9 sum to 45. 1/2 n (1+n) /. n->9 45 Sum of digits 1 thru 999,999 might be: {100000,100000,100000,100000,100000,100000}.{45,45,45,45,45,45} 27000000 Reducing to: 100000*(6*45) 27000000 Sum[Plus@@IntegerDigits[j],{j,10^6,1+10^6}] 3 %% + % 27000003 This gave an interesting alternative for a closed form... z=Table[Power[10,j-1]*(j*45),{j,1,8}] {45,900,13500,180000,2250000,27000000,315000000,3600000000} FindSequenceFunction[z,n] 9 2^(-1+n) 5^n n Which matched here: WolframAlpha[ToString[z]] << . . . >> Also of interest: http://oeis.org/A034967 = = = = = = = = = = HTH :>) Dana DeLouis Mac & Math 8 = = = = = = = = = = On May 13, 10:34 pm, perplexed <yudu... at gmail.com> wrote: > I do not want to say that this is a bug, however I did > not find, in the Sum documentation, an explanation of this > behaviour (v8.0.4) > > I defined an innocent function like > sod[n_]:=Plus@@IntegerDigits[n] > that compute the sum of the digits of a number. > (I tried with other functions, so the culprit is not IntegerDigits) > > Then I compute two sums: > Sum[sod[k],{k,10^6}] which gives 27000001 (ok) > then > Sum[sod[k],{k,1+10^6}] which gives 500001500001 (nonsense). > then > Sum[sod[k],{k,2,1+10^6}] which gives 27000002 (ok) > > so, it seems to me that Sum has a problem when the iterator > works in a range greater than 10^6. > > Indeed, I made an experiment: > I set L={}; and defined > sod[n_]:=(AppendTo[L,n];Plus@@IntegerDigits[n]) > Then Sum[sod[k],{k,1+10^6}] still gives 500001500001 > and at the end L is equal to {k}, so it seems that > Sum tried to do something symbolic (??). > > Is this a bug or a feature whose documentation I was not > able to find? Say, is there an option to fix things ? > > Btw, using ParallelSum instead of Sum works fine (and faster). > thanks