MathGroup Archive 2001

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

Search the Archive

Re: Sum


S[n_] := Module[{P = Array[Prime, n], s},
    s[0] = 0;
    s[1] = First@P;
    s[i_] := (s[i] = s[i - 1] + P[[i]]);
    Log@(-Table[s[i], {i, 0, n - 1}] + s[n]).P]

..does the trick ;-)

In[10]:=
Timing[S[5000];]

Out[10]=
{0.99 Second, Null}

Orestis
PS. This is an application of "dynamic programming" in Mathematica.



"marc jeanno" <ts at tsts.com> wrote in message
news:9k2doa$2fn$1 at smc.vnet.net...
> Dear Sirs,
>
> let n be an integer >=1. Let us consider the following sums:
>
> s(1)= P[1]Log[P[1]]
> s(2)= P[2]Log[P[2]]+P[1]log[P[2]+P[1]]
> s(3)= P[3]Log[P[3]]+P[2]Log[P[3]+P[2]]+P[1]Log[P[3]+P[2]+P[1]]
> .
> .
> .
> s(n)= P[n]Log[P[n]]+...+P[1]Log[P[n]+...+P[1]]  .
>
>
> P[k] is the expression Prime[k].
>
> I used a method to evaluate the expression in function of n (n must be
> assigned a priori). But my PC was frozen during the
> operation(zzzzzz...zzzzz...) for large n values.
> How could I evaluate s(n) in a very very fast way?
> Do I have to try with 2 Fold lines?
> I'd like to know Your opinions.
> Thanks.
>
>
>
>
>
>
>




  • Prev by Date: Re: Integrate[Sqrt[Tan[x]], {x, 0, 1}] -- approx ??
  • Next by Date: Re: Filename as Function Argument"
  • Previous by thread: Re: Sum
  • Next by thread: Re: Filename as Function Argument"