Jacques Gélinas on Fri, 23 Mar 2018 21:45:04 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Datatypes for sieve algorithms |
A prime sieve algorithm is proposed in http://vixra.org/pdf/1803.0493v1.pdf >From the list of even integers, [2,4,6,8,10,12,14,16,18,20,22,...] eliminate 4+2r + n(2+4r) where r,n=1,2,3,... [12,18,24,30,...], [18,28,38,...], ... then subtract 3 from those remaining to get [_,1,3,5, 7, _,11,13, _,17,19,_,...] The list of primes below 4(r^2+r+1) is said to be complete as this number is eliminated. In order to use PARI/GP to test this (unproven++) algorithm, what kind of datatypes/structures are available and efficient ? Vectors of GP integers seem to me to be wasteful here !! What is needed is an index for primes that could be used in vecextract([1..n]). NP = 2^10; /* number of primes */ GP = primes(NP); N = (GP[NP]+3)/2; /* largest index needed in P */ P = vector(N-2,n,2*n+1); for(k=1,N/3-1, for(j=1,(N-2-k)/(1+2*k), P[k+j*(1+2*k)] = 0 )); MP = N - 1 - vecsum(apply(n->!n,P)); Q = vector(MP); Q[1]=2; /* drop zeros from P */ m=1; for(n=1,N-2,if(P[n],Q[m++]=P[n])); Q == GP /* the test */ Thanks, Jacques Gélinas, Ottawa ++ The Golbach conjecture is deduced from it however (vixra is arxiv backwards).