Bill Allombert on Wed, 26 Sep 2012 18:51:43 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Chain of conditions |
On Wed, Sep 26, 2012 at 09:18:51AM -0700, zak seidov wrote: > Consider a very simple code: > {for(n=4,1000, > if(bigomega(n)==2&&bigomega(n+1)==2bigomega(n+2)==2, print(n))} > > My (si8lly?) Q is: > Does PARI go to next n > immediately if bigomega(n)<>2 or > proceed with checking all other conditions(s)? Yes, && is 'short-cutting' meaning it does not evaluate the right side if the left side is false. > BTW Any suggestions to do this faster? (No gp2c or how it's called, though. ) Yes, you can save some times by avoiding to recompute bigomega(n) for the same 'n' several time. The simplest way is: s=0;for(n=4,1000,if(bigomega(n)==2,s++;if(s>=3,print(n-2)),s=0)) (but of course, this is an application for the fabled forfactored() function). Cheers, Bill.