Is there a name or theory for this sieve characteristic?

73 Views Asked by At

In enumerating the primes algorithmically, the "completely naive" algorithm loops through every integer, the difference between succeeding candidates being 1. The first improvement is to "pre-identify" 2 as prime, and then only consider odd integers as candidates, the difference between succeeding candidates being 2. But this type of "improvement" can be extended indefinitely. The next step is "pre-identifying" both 2 and 3, and then only considering non-multiples of 2 and 3 as candidates. The differences between candidates forms a period-2 sequence of repeating (2,4), i.e. 5,7,11,13,17,19,23,25,29,31,... with difference sequence 2,4,2,4,2,4,2,4,2,... . The next step is to bring in 5 and additionally eliminate multiples of 5. The "difference sequence" takes on a period of 8, i.e. 4,2,4,2,4,6,2,6, repeated.

Is there a formula for calculating such difference sequences for any initial set of primes? Or even just a formula for calculating what the period of the difference sequence would be?

1

There are 1 best solutions below

7
On BEST ANSWER

It's called a wheel sieve as you found out in the comments. It actually can have a derivation but quite honestly not much point to it. Here's how it would go: $\gcd(a,b)=1\implies\gcd(a-b,b)=1$ that is, if $b$ is a remainder class mod $a$ that can have primes, so is $a-b$ . this is basically using the distributive property and factoring out. If we have to values that aren't relatively prime, then we can factor out a factor greater than 1 (and primes don't have factors greater than 1 that aren't themselves). So it turns out just pick all the relatively prime remainder classes. The number of relative primes to a number is always even, and the sequence will always be symmetric around the halfway point through the repeating part. You really want a formula for Euler's phi function: $$\varphi(n)=n\prod_{d\mid n,d\in \Bbb{P}}(1-{1 \over d})$$ this tells you how long the repeat part possibly goes on for. As to the values of differences, they'll typically be divisible by primes you eliminated.