1

I am not deeply familiar with mathematics, but I've run into an interesting question while programming that I would appreciate some help with. I'll provide context on the programming side of things to help clarify my question in case my description is lacking, but I want to emphasize that I'm interested in the mathematics part of this, and do not need help with the programming problem.

I've been working on an implementation of https://swtch.com/~rsc/thread/, where in short I implement the sieve of Eratosthenes in an interesting way using the following pseudocode:

p = get a number from left neighbor process

print p

loop: n = get a number from left neighbor process

if (p does not divide n)
    send n to right neighbor process

Essentially, each process consumes a prime number $p$ and then culls all input numbers that are not coprime to $p$. Since each process to the left will only produce coprimes, each successive process is getting a stream of numbers that are coprime to all of the primes less than the process's prime $p$.

Here is a link to an image demonstrating the flow of numbers. (I would have embedded this if I had enough reputation.)

I've discussed this with a friend, and we figured that instead of using division, it would likely be faster to use addition - that is, instead of dividing by $p$ every time, you could keep track of a current multiple $m$ of $p$, and have something like the following:

p = get a number from left neighbor process
mp = p

print p

loop: n = get a number from left neighbor process

if (mp < n)
    mp += p

if mp == n
    continue

send n to right neighbor process

I've tested this with a small number of primes and this works. My question is: is this valid for all primes? That is, for the $i^{th}$ prime $p_i$, will the sequence of coprimes to the set $S_i = \{p_1, p_2, ..., p_{i-1}\}$ ever produce a gap that is larger than $2p_i$?

Or does the function need to handle the possibility that $n$ could be greater than or equal to $mp+2p$ with a loop, like:

p = get a number from left neighbor process
mp = p

print p

loop: n = get a number from left neighbor process

for (; mp < n; mp += p);

if mp == n
    continue

send n to right neighbor process

I've done some searching here and elsewhere, but I'm having a hard time phrasing the question in the first place due to my inexperience with mathematics. Intuitively I feel like it is true, but I also am not equipped to prove it.

I believe that "Range of numbers not divisible by 2 or 3 or 5", "The number of numbers not divisible by 2,3,5,7 or 11 between multiples of 2310", and "Is that true that all the prime numbers are of the form 6m±1?" are likely related, but it's not clear to me how to apply that to my particular question.

  • I don't understand the question. What is $p_i$? Is it specifically the $i^{th}$ prime? In the post you just refer to it as "a given prime" but then what is $p_{i-1}$? Has it got some specified relation to $p_i$? Perhaps it would help to work an explicit example for some non-trivial prime. – lulu Jan 22 '24 at 14:54
  • I note that, in the header you refer to $p_k$ and $p_k-1$ but in the body you have $p_i$ and $p_{i-1}$ so maybe one of those is a typo? – lulu Jan 22 '24 at 15:01
  • This question reminds me of the Scheme implementation of the sieve of Eratosthenes. See 21.5 at https://homes.cs.aau.dk/~normark/prog3-03/html/notes/eval-order_themes-delay-stream-section.html – Ethan Bolker Jan 22 '24 at 15:08
  • Apologies for my poor notation - I'm attempting to refer to the set of all primes less than some prime. Due to the structure of the program, a process will operate on one prime at a time, and will see a stream of numbers that are coprime to all of the primes less than it. I can try to edit the question to use consistent indices once I'm back at a keyboard. – user1281418 Jan 22 '24 at 15:10
  • So, then, $p_i$ denotes the $i^{th}$ prime and your set is $S_i={p_1, p_2, \cdots, p_{i-1}}$? But then the natural primes prime to $S_i$ are precisely those that can be written as products (with multiplicity) of the primes $T_i={p_i, p_{i+1}, \cdots}$, right? If that is all correct, then what is the question about $T_i$? – lulu Jan 22 '24 at 15:13
  • Let's say $i=3$, so $S_3={2,3,5}$. Then $T_3={1, 7, 11, 13, \cdots}$, the first composite element of $T_3$ is $7^2=49$ and the first one that isn't a prime power is $7\times 11=77$. Is that the sort of picture you have in mind? – lulu Jan 22 '24 at 15:15
  • What is $k_j$? You never mention it before of "a number at position $j$ such that $k_j>k_{j−1}+2 p_i$" – Marco Jan 22 '24 at 15:20
  • It's close, the question (I think) I'm asking is: will the gap between successive elements of $T_3$ ever be greater than $2p_4$? and more generally, for any $i^{th}$ prime, will $T_{i-1}$ produce a gap larger than $2p_i$? – user1281418 Jan 22 '24 at 15:22
  • If I have everything right (not at all clear), then your question is a duplicate of this one. – lulu Jan 22 '24 at 15:22
  • Should remark: The answers to what I'm seeing as a duplicate do not fully resolve the question. At best (I believe) they argue that, if you can check it up to some certain level, then it is true for all primes $p$. "That level" being surprisingly small, under $1.5$ million. But I have not studied the answers carefully and I am not sure it's truly a duplicate anyway. – lulu Jan 22 '24 at 15:26
  • @Marco, $k_j$ was meant to be the $j^{th}$ number in the sequence of coprimes to all primes less than the $i^{th}$ prime ($2...p_{i-1}$). – user1281418 Jan 22 '24 at 15:38
  • 1
    I've edited the title and body somewhat, hopefully that helps. – user1281418 Jan 22 '24 at 15:46
  • To aid in searching for results, note that, for a given prime $p$, your "coprime" set is typically referred to as the set of $p-$rough numbers, see this for instance. If I have understand your question, it is a strengthening of Bertrand's postulate, so I expect you'll find associated references. – lulu Jan 22 '24 at 15:48
  • I think I understand, and if so, I think another way to phrase my question would be: is the gap between $p$-rough numbers ever larger than $2p$? Does that sound right? The linked question is about bounding the size of the $p$-rough numbers, but I'm interested in a bound on the gap. – user1281418 Jan 22 '24 at 16:10

1 Answers1

0

I was able to find a proof by counterexample for $p = 13$, since:

  • 9113 and 9127 are adjacent coprimes to the set $\{2, 3, 5, 7, 11\}$.
  • 9113 is a multiple of 13 ($13 × 701 = 9113$).
  • $9113 + 13 = 9126$, and $9126 < 9127$.

So in the code above, a single increment of $mp$ by $p$ when $p = 13$ would not suffice for the sequence of $9113, 9127$.

I think this could have been proven without running the program by looking at the Jacobsthal function applied to the product of the first n primes, A048670, since:

  • any process for the $i^{th}$ prime $p_i$ would only see numbers coprime to the product of ${2 × 3 × ... × p_{i-1}}$
  • $A048670(i-1)$ gives the maximal gap between coprimes to the product of ${2 × 3 × ... × p_{i-1}}$

and when $i = 6$,

  • $p_6 = 13$
  • $A048670(6-1) = 14$

So the process for 13 would, on some basis, see a gap of 14 in the coprimes it read from the processes to its left, and eventually that gap would happen directly after a multiple of 13, leaving it unable to cross the gap with a single increment of 13. This appears to first happen between 9113 and 9127.