       Re: fastest way to add up a billion numbers

```Andrzej Kozlowski <akoz at mimuw.edu.pl> writes:

> Certianly for small vaues explicit addition is performed, as can be
> seen from:
>
> Trace[Sum[i, {i, 1, n}] /. n -> 5]
>
> Out=
> {{HoldForm[Sum[i, {i, 1, n}]],
>     HoldForm[(1/2)*n*(n + 1)]},
>    HoldForm[(1/2)*n*(n + 1) /. n -> 5],
>    HoldForm[(5*(1 + 5))/2], {HoldForm[1 + 5],
>     HoldForm}, HoldForm[(5*6)/2], HoldForm}
>
> In:=
> Trace[Sum[i, {i, 1, 5}]]
>
> Out=
> {HoldForm[Sum[i, {i, 1, 5}]], {HoldForm[i], HoldForm},
>    {HoldForm[i], HoldForm}, {HoldForm[i], HoldForm},
>    {HoldForm[i], HoldForm}, {HoldForm[i], HoldForm},
>    HoldForm[1 + 2 + 3 + 4 + 5], HoldForm}
>
> The second Trace certianly suggests explicit summation.
>
> On the other hand, indeed we have:
>
> In:=
> Trace[Sum[i, {i, 1, 10^9}]]
>
> Out=
> {HoldForm[Sum[i, {i, 1, 10^9}]], {HoldForm[10^9],
>     HoldForm}, HoldForm}
>
>
> If this is right, it sugges that the algorithm switches at some point
> form explicit addition to using a formula. One could obviously find
> out the point at which the algorithm switches form one approach to
> the other, I suspect the number would b eunder 1000.

I have version 5.1 for Linux.  The algorithm switches approaches at
10^6+1.

Scott
--
Scott Hemphill	hemphill at alumni.caltech.edu
"This isn't flying.  This is falling, with style."  -- Buzz Lightyear

```

• Prev by Date: Re: Triangular Distribution in Mathematica
• Next by Date: Re: Integrate (fix a mistake)
• Previous by thread: Re: Re: Re: Re: fastest way to add up a billion numbers
• Next by thread: Re: Re: fastest way to add up a billion numbers