Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Mathematica slows down

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52966] Re: [mg52956] Mathematica slows down
  • From: yehuda ben-shimol <benshimo at bgu.ac.il>
  • Date: Sat, 18 Dec 2004 03:59:39 -0500 (EST)
  • References: <200412171020.FAA16192@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi George,
I couldn't notice any speedup for k>10000 but your program is inefficient 
since you are computing the same primes too many times. A faster idea is to 
store them
Timing of your program for k=10000 is
44.4062 Seconds 
and with the following program the timing is 
1.3258 Seconds

l = Table[Prime[i], {i, 5}];
For[k = 1, k < 20001, k++,
  Gap[1] = {0, 0, 0, 2, -1}.l;
  Gap[2] = {0, 0, 1, -2, 1}.l;
  Gap[3] = {0, 1, -3, 6, -4}.l;
  Gap[4] = {1, -4, 6, 4, 1}.l;
  l = RotateRight[l, 1];
  l[[5]] = Prime[k + 5];
  ];
I can make it more efficient but this will be minor change.
good luck
yehuda


On Friday 17 December 2004 12:20, George Szpiro wrote:
> 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]]
>
>
>   ]


  • Prev by Date: An argument pattern problem: ranges and lists
  • Next by Date: Re: NIntegrate a list
  • Previous by thread: Mathematica slows down
  • Next by thread: Re: Mathematica slows down