Re: Re: Summations with Primes

*To*: mathgroup at smc.vnet.net*Subject*: [mg40006] Re: [mg39988] Re: Summations with Primes*From*: Kirk Reinholtz <kirk.reinholtz at jpl.nasa.gov>*Date*: Fri, 14 Mar 2003 04:47:39 -0500 (EST)*References*: <200303130806.DAA12131@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Prime/@Range[1,10] will get the first ten primes. Bill Rowe wrote: > > On 3/12/03 at 2:29 AM, afelder at crsi.org (Anthony Felder) wrote: > > >Can you tell me if, when calculating a summation of f(i) where i goes > >from imin to imax, Mathematica can be forced to only use prime values > >for i? > > Yes, by adding the appropriate code. That is there isn't a built in directive to do what you want. > > I think there are two basic approaches. First would be to generate a list of primes, map f to the elements of that list then sum. For example: > > Tr[f/@Select[Range[imin, imax], PrimeQ]] will do the trick > > This approach might be made more efficient using the NextPrime function in the package NumberTheory`NumberTheoryFunctions` > > The other approach would be to modify f so that it returned zero for non-prime arguments. I think this approach is likely to be slower than the first approach.

**References**:**Re: Summations with Primes***From:*Bill Rowe <listuser@earthlink.net>