Re: Mathematica slows down
- To: mathgroup at smc.vnet.net
- Subject: [mg52964] Re: [mg52956] Mathematica slows down
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sat, 18 Dec 2004 03:59:37 -0500 (EST)
- Reply-to: hanlonr at cox.net
- Sender: owner-wri-mathgroup at wolfram.com
I don't know what changes; however, you can speed it up by avoiding
repeated calls of Prime for the same values
NumP=15000;
Table[pk[n]=Prime[n],{n,NumP}];
For[k=1,k<NumP,k++,
Gap[1]=pk[k+1]-pk[k];
Gap[2]=pk[k+2]-2pk[k+1]+pk[k];
Gap[3]=pk[k+3]-3pk[k+2]+3pk[k+1]-pk[k];
Gap[4]=pk[k+4]-4pk[k+3]+6pk[k+2]-4pk[k+1]+pk[k];
If[Mod[k,1000]==0,Print[k]]]
Bob Hanlon
>
> From: George Szpiro <george at netvision.net.il>
To: mathgroup at smc.vnet.net
> Date: 2004/12/17 Fri AM 05:20:43 EST
> To: mathgroup at smc.vnet.net
> Subject: [mg52964] [mg52956] Mathematica slows down
>
> Hello,
>
> the following program runs ok for the first 6,000 iterations, then slows
> down considerably, and then seems to speed up again after 10,000. Does
> anyone know what is going on?
>
> Thanks,
> George
>
>
> NumP=15000;
>
> For[k=1,k<NumP,k++,
>
> Gap[1]=Prime[k+1]-Prime[k];
> Gap[2]=Prime[k+2]-2Prime[k+1]+Prime[k];
> Gap[3]=Prime[k+3]-3Prime[k+2]+3Prime[k+1]-Prime[k];
> Gap[4]=Prime[k+4]-4Prime[k+3]+6Prime[k+2]-4Prime[k+1]+Prime[k];
>
> If[Mod[k,1000]==0, Print[ k]]
>
>
> ]
>
>
>
- Follow-Ups:
- Re: Re: Mathematica slows down
- From: DrBob <drbob@bigfoot.com>
- Re: Re: Mathematica slows down